VirtualBox

Changeset 73977 in vbox for trunk/include/iprt/cpp


Ignore:
Timestamp:
Aug 30, 2018 12:13:02 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
124713
Message:

IPRT/rest: More request array and map setter methods. Fixed string defaults. Safer copying and resetToDefaults. bugref:9167

File:
1 edited

Legend:

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

    r73968 r73977  
    267267    /**
    268268     * Resets the object to all default values.
    269      */
    270     virtual void resetToDefault() = 0;
     269     * @returns IPRT status code.
     270     */
     271    virtual int resetToDefault() = 0;
    271272
    272273    /**
     
    370371    /** Copy assignment operator. */
    371372    RTCRestBool &operator=(RTCRestBool const &a_rThat);
     373    /** Safe copy assignment method. */
     374    int assignCopy(RTCRestBool const &a_rThat);
    372375
    373376    /* Overridden methods: */
    374     virtual void resetToDefault() RT_OVERRIDE;
     377    virtual int resetToDefault() RT_OVERRIDE;
    375378    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
    376379    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
     
    405408    /** Copy assignment operator. */
    406409    RTCRestInt64 &operator=(RTCRestInt64 const &a_rThat);
     410    /** Safe copy assignment method. */
     411    int assignCopy(RTCRestInt64 const &a_rThat);
    407412
    408413    /* Overridden methods: */
    409     virtual void resetToDefault() RT_OVERRIDE;
     414    virtual int resetToDefault() RT_OVERRIDE;
    410415    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
    411416    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
     
    440445    /** Copy assignment operator. */
    441446    RTCRestInt32 &operator=(RTCRestInt32 const &a_rThat);
     447    /** Safe copy assignment method. */
     448    int assignCopy(RTCRestInt32 const &a_rThat);
    442449
    443450    /* Overridden methods: */
    444     virtual void resetToDefault() RT_OVERRIDE;
     451    virtual int resetToDefault() RT_OVERRIDE;
    445452    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
    446453    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
     
    475482    /** Copy assignment operator. */
    476483    RTCRestInt16 &operator=(RTCRestInt16 const &a_rThat);
     484    /** Safe copy assignment method. */
     485    int assignCopy(RTCRestInt16 const &a_rThat);
    477486
    478487    /* Overridden methods: */
    479     virtual void resetToDefault() RT_OVERRIDE;
     488    virtual int resetToDefault() RT_OVERRIDE;
    480489    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
    481490    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
     
    510519    /** Copy assignment operator. */
    511520    RTCRestDouble &operator=(RTCRestDouble const &a_rThat);
     521    /** Safe copy assignment method. */
     522    int assignCopy(RTCRestDouble const &a_rThat);
    512523
    513524    /* Overridden methods: */
    514     virtual void resetToDefault() RT_OVERRIDE;
     525    virtual int resetToDefault() RT_OVERRIDE;
    515526    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
    516527    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
     
    537548    /** Default destructor. */
    538549    RTCRestString();
     550    /** Destructor. */
     551    virtual ~RTCRestString();
     552
    539553    /** Copy constructor. */
    540554    RTCRestString(RTCRestString const &a_rThat);
     
    543557    /** From value constructor. */
    544558    RTCRestString(const char *a_pszSrc);
    545     /** Destructor. */
    546     virtual ~RTCRestString();
     559    /** Safe copy assignment method. */
     560    int assignCopy(RTCString const &a_rThat);
     561    /** Safe copy assignment method. */
     562    int assignCopy(const char *a_pszThat);
    547563
    548564    /* Overridden methods: */
    549     virtual void resetToDefault() RT_OVERRIDE;
     565    virtual int resetToDefault() RT_OVERRIDE;
    550566    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
    551567    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
     
    572588
    573589    /* Overridden methods: */
    574     virtual void resetToDefault() RT_OVERRIDE;
     590    virtual int resetToDefault() RT_OVERRIDE;
    575591    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
    576592    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
     
    718734    }
    719735
     736    /** Safe copy assignment method. */
     737    int assignCopy(RTCRestArray const &a_rThat)
     738    {
     739        return copyArrayWorker(a_rThat, false /*fThrow*/);
     740    }
     741
    720742    virtual const char *getType(void) RT_OVERRIDE
    721743    {
     
    759781    int insertCopy(size_t a_idx, ElementType const &a_rThat)
    760782    {
    761         return insertCopyWorker(a_idx, &a_rThat, false /*a_fReplace*/);
     783        return insertCopyWorker(a_idx, a_rThat, false /*a_fReplace*/);
    762784    }
    763785
     
    783805    int appendCopy(ElementType const &a_rThat)
    784806    {
    785         return insertCopyWorker(~(size_t)0, &a_rThat, false /*a_fReplace*/);
     807        return insertCopyWorker(~(size_t)0, a_rThat, false /*a_fReplace*/);
    786808    }
    787809
     
    807829    int prependCopy(ElementType const &a_rThat)
    808830    {
    809         return insertCopyWorker(0, &a_rThat, false /*a_fReplace*/);
     831        return insertCopyWorker(0, a_rThat, false /*a_fReplace*/);
    810832    }
    811833
     
    833855    int replaceCopy(size_t a_idx, ElementType const &a_rThat)
    834856    {
    835         return insertCopyWorker(a_idx, &a_rThat, true /*a_fReplace*/);
     857        return insertCopyWorker(a_idx, a_rThat, true /*a_fReplace*/);
    836858    }
    837859
     
    907929    virtual RTCRestObjectBase *createValueCopy(RTCRestObjectBase const *a_pSrc) RT_OVERRIDE
    908930    {
    909         return new (std::nothrow) ElementType(*(ElementType const *)a_pSrc);
     931        ElementType *pCopy = new (std::nothrow) ElementType();
     932        if (pCopy)
     933        {
     934            int rc = pCopy->assignCopy(*(ElementType const *)a_pSrc);
     935            if (RT_SUCCESS(rc))
     936                return pCopy;
     937            delete pCopy;
     938        }
     939        return NULL;
    910940    }
    911941};
     
    928958
    929959    /* Overridden methods: */
    930     virtual void resetToDefault() RT_OVERRIDE;
     960    virtual int resetToDefault() RT_OVERRIDE;
    931961    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
    932962    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
     
    10981128    }
    10991129
     1130    /** Safe copy assignment method. */
     1131    int assignCopy(RTCRestStringMap const &a_rThat)
     1132    {
     1133        return copyMapWorker(a_rThat, false /*a_fThrow*/);
     1134    }
     1135
    11001136    virtual const char *getType(void) RT_OVERRIDE
    11011137    {
     
    12251261    virtual RTCRestObjectBase *createValueCopy(RTCRestObjectBase const *a_pSrc) RT_OVERRIDE
    12261262    {
    1227         return new (std::nothrow) ValueType(*(ValueType const *)a_pSrc);
     1263        ValueType *pCopy = new (std::nothrow) ValueType();
     1264        if (pCopy)
     1265        {
     1266            int rc = pCopy->assignCopy(*(ValueType const *)a_pSrc);
     1267            if (RT_SUCCESS(rc))
     1268                return pCopy;
     1269            delete pCopy;
     1270        }
     1271        return NULL;
    12281272    }
    12291273};
     
    12411285    /** Default destructor. */
    12421286    RTCRestObject();
    1243     /** Copy constructor. */
    1244     RTCRestObject(RTCRestBool const &a_rThat);
    12451287    /** Destructor. */
    12461288    virtual ~RTCRestObject();
     1289
     1290    /** Copy constructor. */
     1291    RTCRestObject(RTCRestObject const &a_rThat);
    12471292    /** Copy assignment operator. */
    1248     RTCRestBool &operator=(RTCRestObject const &a_rThat);
     1293    RTCRestObject &operator=(RTCRestObject const &a_rThat);
     1294    /** Safe Safe copy assignment method. */
     1295    int assignCopy(RTCRestObject const &a_rThat);
    12491296
    12501297    /* Overridden methods: */
    1251     virtual void resetToDefault() RT_OVERRIDE;
     1298    virtual int resetToDefault() RT_OVERRIDE;
    12521299    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
    12531300    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
     
    12731320    RTCRestClientRequestBase();
    12741321    virtual ~RTCRestClientRequestBase();
     1322    RTCRestClientRequestBase(RTCRestClientRequestBase const &a_rThat);
     1323    RTCRestClientRequestBase &operator=(RTCRestClientRequestBase const &a_rThat);
    12751324
    12761325    /**
    12771326     * Reset all members to default values.
    1278      */
    1279     virtual void resetToDefault() = 0;
     1327     * @returns IPRT status code.
     1328     */
     1329    virtual int resetToDefault() = 0;
    12801330
    12811331    /**
     
    12981348    virtual void xmitComplete(int a_rcStatus, RTHTTP a_hHttp) const = 0;
    12991349
     1350    /**
     1351     * Checks if there are were any assignment errors.
     1352     */
     1353    bool hasAssignmentErrors() const { return m_fErrorSet != 0; }
     1354
    13001355protected:
     1356    /** Set of fields that have been explicitly assigned a value. */
     1357    uint64_t m_fIsSet;
     1358    /** Set of fields where value assigning failed. */
     1359    uint64_t m_fErrorSet;
     1360
    13011361    /** Path replacement entry. */
    13021362    typedef struct
     
    15911651     * @param   a_enmHttpMethod The HTTP request method.
    15921652     * @param   a_pResponse     Pointer to the response object.
     1653     * @param   a_pszMethod     The method name, for logging purposes.
    15931654     */
    15941655    virtual void doCall(RTCRestClientRequestBase const &a_rRequest, RTHTTPMETHOD a_enmHttpMethod,
    1595                         RTCRestClientResponseBase *a_pResponse);
     1656                        RTCRestClientResponseBase *a_pResponse, const char *a_pszMethod);
    15961657
    15971658};
Note: See TracChangeset for help on using the changeset viewer.

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