VirtualBox

Changeset 74181 in vbox for trunk/include/iprt


Ignore:
Timestamp:
Sep 10, 2018 12:43:30 PM (6 years ago)
Author:
vboxsync
Message:

IPRT/rest: Wrote unit tests for RTCRestDate. Addressed some issues found. Marked methods implemented in headers with 'inline'. bugref:9167

Location:
trunk/include/iprt/cpp
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/cpp/restarray.h

    r74025 r74181  
    6666     * @return   True if there is more than zero items, false otherwise.
    6767     */
    68     bool isEmpty() const
     68    inline bool isEmpty() const
    6969    {
    7070        return m_cElements == 0;
     
    7474     * Gets the number of entries in the map.
    7575     */
    76     size_t size() const
     76    inline size_t size() const
    7777    {
    7878        return m_cElements;
     
    8585     * @param   a_idx           The array index.
    8686     */
    87     RTCRestObjectBase *atBase(size_t a_idx)
     87    inline RTCRestObjectBase *atBase(size_t a_idx)
    8888    {
    8989        if (a_idx < m_cElements)
     
    9898     * @param   a_idx           The array index.
    9999     */
    100     RTCRestObjectBase const *atBase(size_t a_idx) const
     100    inline RTCRestObjectBase const *atBase(size_t a_idx) const
    101101    {
    102102        if (a_idx < m_cElements)
     
    247247     * @param   a_pThat         The object to insert.  The array takes ownership of the object on success.
    248248     */
    249     int insert(size_t a_idx, ElementType *a_pThat)
     249    inline int insert(size_t a_idx, ElementType *a_pThat)
    250250    {
    251251        return insertWorker(a_idx, a_pThat, false /*a_fReplace*/);
     
    260260     * @param   a_rThat         The object to insert a copy of.
    261261     */
    262     int insertCopy(size_t a_idx, ElementType const &a_rThat)
     262    inline int insertCopy(size_t a_idx, ElementType const &a_rThat)
    263263    {
    264264        return insertCopyWorker(a_idx, a_rThat, false /*a_fReplace*/);
     
    272272     * @param   a_pThat         The object to insert.  The array takes ownership of the object on success.
    273273     */
    274     int append(ElementType *a_pThat)
     274    inline int append(ElementType *a_pThat)
    275275    {
    276276        return insertWorker(~(size_t)0, a_pThat, false /*a_fReplace*/);
     
    284284     * @param   a_rThat         The object to insert a copy of.
    285285     */
    286     int appendCopy(ElementType const &a_rThat)
     286    inline int appendCopy(ElementType const &a_rThat)
    287287    {
    288288        return insertCopyWorker(~(size_t)0, a_rThat, false /*a_fReplace*/);
     
    296296     * @param   a_pThat         The object to insert.  The array takes ownership of the object on success.
    297297     */
    298     int prepend(ElementType *a_pThat)
     298    inline int prepend(ElementType *a_pThat)
    299299    {
    300300        return insertWorker(0, a_pThat, false /*a_fReplace*/);
     
    308308     * @param   a_rThat         The object to insert a copy of.
    309309     */
    310     int prependCopy(ElementType const &a_rThat)
     310    inline int prependCopy(ElementType const &a_rThat)
    311311    {
    312312        return insertCopyWorker(0, a_rThat, false /*a_fReplace*/);
     
    321321     * @param   a_pThat         The replacement object.  The array takes ownership of the object on success.
    322322     */
    323     int replace(size_t a_idx, ElementType *a_pThat)
     323    inline int replace(size_t a_idx, ElementType *a_pThat)
    324324    {
    325325        return insertWorker(a_idx, a_pThat, true /*a_fReplace*/);
     
    334334     * @param   a_rThat         The object to insert a copy of.
    335335     */
    336     int replaceCopy(size_t a_idx, ElementType const &a_rThat)
     336    inline int replaceCopy(size_t a_idx, ElementType const &a_rThat)
    337337    {
    338338        return insertCopyWorker(a_idx, a_rThat, true /*a_fReplace*/);
     
    345345     * @param   a_idx           The array index.
    346346     */
    347     ElementType *at(size_t a_idx)
     347    inline ElementType *at(size_t a_idx)
    348348    {
    349349        if (a_idx < m_cElements)
     
    358358     * @param   a_idx           The array index.
    359359     */
    360     ElementType const *at(size_t a_idx) const
     360    inline ElementType const *at(size_t a_idx) const
    361361    {
    362362        if (a_idx < m_cElements)
     
    369369     * @returns The first object, NULL if empty.
    370370     */
    371     ElementType *first()
     371    inline ElementType *first()
    372372    {
    373373        return at(0);
     
    378378     * @returns The first object, NULL if empty.
    379379     */
    380     ElementType const *first() const
     380    inline ElementType const *first() const
    381381    {
    382382        return at(0);
     
    387387     * @returns The last object, NULL if empty.
    388388     */
    389     ElementType *last()
     389    inline ElementType *last()
    390390    {
    391391        return at(m_cElements - 1);
     
    396396     * @returns The last object, NULL if empty.
    397397     */
    398     ElementType const *last() const
     398    inline ElementType const *last() const
    399399    {
    400400        return at(m_cElements - 1);
  • trunk/include/iprt/cpp/restbase.h

    r74176 r74181  
    8585     * @param   uIndent     The indentation level.
    8686     */
    87     unsigned setIndent(unsigned uIndent)
     87    inline unsigned setIndent(unsigned uIndent)
    8888    {
    8989        unsigned const uRet = m_uIndent;
     
    9797     * @returns Previous indentation level.
    9898     */
    99     unsigned incrementIndent()
     99    inline unsigned incrementIndent()
    100100    {
    101101        unsigned const uRet = m_uIndent;
     
    267267     * @returns true if null, false if not.
    268268     */
    269     bool isNull(void) const { return m_fNullIndicator; };
     269    inline bool isNull(void) const { return m_fNullIndicator; };
    270270
    271271    /**
     
    730730     */
    731731    int assignValue(PCRTTIMESPEC a_pTimeSpec, kFormat a_enmFormat);
    732     int assignValueRfc2822(PCRTTIMESPEC a_pTimeSpec); /**< Convenience method. */
    733     int assignValueRfc7131(PCRTTIMESPEC a_pTimeSpec); /**< Convenience method. */
    734     int assignValueRfc3339(PCRTTIMESPEC a_pTimeSpec); /**< Convenience method. */
     732    int assignValueRfc2822(PCRTTIMESPEC a_pTimeSpec); /**< Convenience method for email/whatnot. */
     733    int assignValueRfc7131(PCRTTIMESPEC a_pTimeSpec); /**< Convenience method for HTTP date. */
     734    int assignValueRfc3339(PCRTTIMESPEC a_pTimeSpec); /**< Convenience method for ISO-8601 timstamp. */
    735735
    736736    /**
     
    742742     */
    743743    int assignNow(kFormat a_enmFormat);
    744     int assignNowRfc2822(); /**< Convenience method. */
    745     int assignNowRfc7131(); /**< Convenience method. */
    746     int assignNowRfc3339(); /**< Convenience method. */
     744    int assignNowRfc2822(); /**< Convenience method for email/whatnot. */
     745    int assignNowRfc7131(); /**< Convenience method for HTTP date. */
     746    int assignNowRfc3339(); /**< Convenience method for ISO-8601 timstamp. */
    747747
    748748    /**
     
    756756
    757757    /** Check if the value is okay (m_TimeSpec & m_Exploded). */
    758     bool              isOkay() const        { return m_fTimeSpecOkay; }
     758    inline bool              isOkay() const             { return m_fTimeSpecOkay; }
    759759    /** Get the timespec value. */
    760     RTTIMESPEC const &getTimeSpec() const   { return m_TimeSpec; }
     760    inline RTTIMESPEC const &getTimeSpec() const        { return m_TimeSpec; }
    761761    /** Get the exploded time. */
    762     RTTIME const     &getExploded() const   { return m_Exploded; }
     762    inline RTTIME const     &getExploded() const        { return m_Exploded; }
     763    /** Gets the format. */
     764    inline kFormat           getFormat() const          { return m_enmFormat; }
    763765    /** Get the formatted/raw string value. */
    764     RTCString const  &getString() const     { return m_strFormatted; }
     766    inline RTCString const  &getString() const          { return m_strFormatted; }
     767
     768    /** Get nanoseconds since unix epoch. */
     769    inline int64_t           getEpochNano() const       { return RTTimeSpecGetNano(&m_TimeSpec); }
     770    /** Get seconds since unix epoch. */
     771    inline int64_t           getEpochSeconds() const    { return RTTimeSpecGetSeconds(&m_TimeSpec); }
     772    /** Checks if UTC time. */
     773    inline bool              isUtc() const              { return (m_Exploded.fFlags & RTTIME_FLAGS_TYPE_MASK) != RTTIME_FLAGS_TYPE_LOCAL; }
     774    /** Checks if local time. */
     775    inline bool              isLocal() const            { return (m_Exploded.fFlags & RTTIME_FLAGS_TYPE_MASK) == RTTIME_FLAGS_TYPE_LOCAL; }
    765776
    766777protected:
     
    841852    int assignCopy(RTCRestStringEnumBase const &a_rThat);
    842853    /** Safe copy assignment method. */
    843     int assignCopy(RTCString const &a_rThat)    { return setByString(a_rThat); }
    844     /** Safe copy assignment method. */
    845     int assignCopy(const char *a_pszThat)       { return setByString(a_pszThat); }
     854    inline int assignCopy(RTCString const &a_rThat)    { return setByString(a_rThat); }
     855    /** Safe copy assignment method. */
     856    inline int assignCopy(const char *a_pszThat)       { return setByString(a_pszThat); }
    846857
    847858    /* Overridden methods: */
     
    940951
    941952    /** Returns a pointer to the data blob. */
    942     const uint8_t  *getPtr()  const { return m_pbData; }
     953    inline const uint8_t  *getPtr()  const { return m_pbData; }
    943954    /** Gets the size of the data. */
    944     size_t          getSize() const { return m_cbData; }
     955    inline size_t          getSize() const { return m_cbData; }
    945956
    946957    /* Overridden methods: */
  • trunk/include/iprt/cpp/restclient.h

    r74142 r74181  
    7575     * Retrieves the callback data.
    7676     */
    77     void *getCallbackData() const  { return m_pvCallbackData; }
     77    inline void *getCallbackData() const  { return m_pvCallbackData; }
    7878
    7979    /**
     
    8989     * Gets the content type that was set.
    9090     */
    91     RTCString const &getContentType() const { return m_strContentType; }
     91    inline RTCString const &getContentType() const { return m_strContentType; }
    9292
    9393    /**
     
    199199     * Retrieves the callback data.
    200200     */
    201     void *getCallbackData() const  { return m_pvCallbackData; }
     201    inline void *getCallbackData() const  { return m_pvCallbackData; }
    202202
    203203    /**
     
    216216     * Gets the content-length value (UINT64_MAX if not available).
    217217     */
    218     uint64_t getContentLength() const { return m_cbContentLength; }
     218    inline uint64_t getContentLength() const { return m_cbContentLength; }
    219219
    220220    /**
     
    340340     * Checks if there are were any assignment errors.
    341341     */
    342     bool hasAssignmentErrors() const { return m_fErrorSet != 0; }
     342    inline bool hasAssignmentErrors() const { return m_fErrorSet != 0; }
    343343
    344344protected:
     
    498498     * @returns Negative numbers are IPRT errors, positive are HTTP status codes.
    499499     */
    500     int getStatus() { return m_rcStatus; }
     500    inline int getStatus() { return m_rcStatus; }
    501501
    502502    /**
     
    504504     * @returns HTTP status code or VERR_NOT_AVAILABLE.
    505505     */
    506     int getHttpStatus() { return m_rcHttp; }
     506    inline int getHttpStatus() { return m_rcHttp; }
    507507
    508508    /**
    509509     * Getter for m_pErrInfo.
    510510     */
    511     PCRTERRINFO getErrInfo(void) const { return m_pErrInfo; }
     511    inline PCRTERRINFO getErrInfo(void) const { return m_pErrInfo; }
    512512
    513513    /**
    514514     * Getter for m_strContentType.
    515515     */
    516     RTCString const &getContentType(void) const { return m_strContentType; }
     516    inline RTCString const &getContentType(void) const { return m_strContentType; }
    517517
    518518
     
    632632     * @returns Base URL string.  If empty, we'll be using the default one.
    633633     */
    634     RTCString const &getBasePath(void) const
     634    inline RTCString const &getBasePath(void) const
    635635    {
    636636        return m_strBasePath;
     
    661661     * @note    Defers to the C-string variant.
    662662     */
    663     void setBasePath(RTCString const &a_strPath) { setBasePath(a_strPath.c_str()); }
     663    inline void setBasePath(RTCString const &a_strPath) { setBasePath(a_strPath.c_str()); }
    664664
    665665    /**
  • trunk/include/iprt/cpp/reststringmap.h

    r74029 r74181  
    160160
    161161        /** Gets the key string. */
    162         RTCString const         &getKey()   { return m_pCur->strKey; }
     162        inline RTCString const         &getKey()   { return m_pCur->strKey; }
    163163        /** Gets poitner to the value object. */
    164         RTCRestObjectBase const *getValue() { return m_pCur->pValue; }
     164        inline RTCRestObjectBase const *getValue() { return m_pCur->pValue; }
    165165
    166166        /** Advance to the next map entry. */
    167         ConstIterator &operator++()
     167        inline ConstIterator &operator++()
    168168        {
    169169            m_pCur = RTListNodeGetNextCpp(&m_pCur->ListEntry, MapEntry, ListEntry);
     
    172172
    173173        /** Advance to the previous map entry. */
    174         ConstIterator &operator--()
     174        inline ConstIterator &operator--()
    175175        {
    176176            m_pCur = RTListNodeGetPrevCpp(&m_pCur->ListEntry, MapEntry, ListEntry);
     
    179179
    180180        /** Compare equal. */
    181         bool operator==(ConstIterator const &a_rThat) { return m_pCur == a_rThat.m_pCur; }
     181        inline bool operator==(ConstIterator const &a_rThat) { return m_pCur == a_rThat.m_pCur; }
    182182        /** Compare not equal. */
    183         bool operator!=(ConstIterator const &a_rThat) { return m_pCur != a_rThat.m_pCur; }
     183        inline bool operator!=(ConstIterator const &a_rThat) { return m_pCur != a_rThat.m_pCur; }
    184184
    185185        /* Map class must be friend so it can use the MapEntry constructor. */
     
    188188
    189189    /** Returns iterator for the first map entry (unless it's empty and it's also the end). */
    190     ConstIterator begin() const { return ConstIterator(RTListGetFirstCpp(&m_ListHead, MapEntry, ListEntry)); }
     190    inline ConstIterator begin() const { return ConstIterator(RTListGetFirstCpp(&m_ListHead, MapEntry, ListEntry)); }
    191191    /** Returns iterator for the last map entry (unless it's empty and it's also the end). */
    192     ConstIterator last() const  { return ConstIterator(RTListGetLastCpp(&m_ListHead, MapEntry, ListEntry)); }
     192    inline ConstIterator last() const  { return ConstIterator(RTListGetLastCpp(&m_ListHead, MapEntry, ListEntry)); }
    193193    /** Returns the end iterator.  This does not ever refer to an actual map entry. */
    194     ConstIterator end() const   { return ConstIterator(RT_FROM_CPP_MEMBER(&m_ListHead, MapEntry, ListEntry)); }
     194    inline ConstIterator end() const   { return ConstIterator(RT_FROM_CPP_MEMBER(&m_ListHead, MapEntry, ListEntry)); }
    195195    /** @} */
    196196
     
    327327     * @param   a_fReplace      Whether to replace existing key-value pair with matching key.
    328328     */
    329     int put(const char *a_pszKey, ValueType *a_pValue, bool a_fReplace = false)
     329    inline int put(const char *a_pszKey, ValueType *a_pValue, bool a_fReplace = false)
    330330    {
    331331        return putWorker(a_pszKey, a_pValue, a_fReplace);
     
    341341     * @param   a_fReplace      Whether to replace existing key-value pair with matching key.
    342342     */
    343     int put(RTCString const &a_rStrKey, ValueType *a_pValue, bool a_fReplace = false)
     343    inline int put(RTCString const &a_rStrKey, ValueType *a_pValue, bool a_fReplace = false)
    344344    {
    345345        return putWorker(a_rStrKey.c_str(), a_pValue, a_fReplace, a_rStrKey.length());
     
    355355     * @param   a_fReplace      Whether to replace existing key-value pair with matching key.
    356356     */
    357     int putCopy(const char *a_pszKey, const ValueType &a_rValue, bool a_fReplace = false)
     357    inline int putCopy(const char *a_pszKey, const ValueType &a_rValue, bool a_fReplace = false)
    358358    {
    359359        return putCopyWorker(a_pszKey, a_rValue, a_fReplace);
     
    369369     * @param   a_fReplace      Whether to replace existing key-value pair with matching key.
    370370     */
    371     int putCopy(RTCString const &a_rStrKey, const ValueType &a_rValue, bool a_fReplace = false)
     371    inline int putCopy(RTCString const &a_rStrKey, const ValueType &a_rValue, bool a_fReplace = false)
    372372    {
    373373        return putCopyWorker(a_rStrKey.c_str(), a_rValue, a_fReplace, a_rStrKey.length());
     
    380380     * @param   a_pszKey        The key which value to look up.
    381381     */
    382     ValueType *get(const char *a_pszKey)
     382    inline ValueType *get(const char *a_pszKey)
    383383    {
    384384        return (ValueType *)getWorker(a_pszKey);
     
    391391     * @param   a_rStrKey       The key which value to look up.
    392392     */
    393     ValueType *get(RTCString const &a_rStrKey)
     393    inline ValueType *get(RTCString const &a_rStrKey)
    394394    {
    395395        return (ValueType *)getWorker(a_rStrKey.c_str());
     
    402402     * @param   a_pszKey        The key which value to look up.
    403403     */
    404     ValueType const *get(const char *a_pszKey) const
     404    inline ValueType const *get(const char *a_pszKey) const
    405405    {
    406406        return (ValueType const *)getWorker(a_pszKey);
     
    413413     * @param   a_rStrKey       The key which value to look up.
    414414     */
    415     ValueType const *get(RTCString const &a_rStrKey) const
     415    inline ValueType const *get(RTCString const &a_rStrKey) const
    416416    {
    417417        return (ValueType const *)getWorker(a_rStrKey.c_str());
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette