VirtualBox

Changeset 74387 in vbox


Ignore:
Timestamp:
Sep 20, 2018 3:51:35 PM (6 years ago)
Author:
vboxsync
Message:

IPRT/rest: Early support for polymorphic data objects in the data model. bugref:9167

Location:
trunk
Files:
7 edited

Legend:

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

    r74106 r74387  
    9696    int assignValue(const char *a_pszValue);
    9797
     98    /** Make a clone of this object. */
     99    inline RTCRestAnyObject *clone() const { return (RTCRestAnyObject *)baseClone(); }
     100
    98101    /* Overridden methods: */
     102    virtual RTCRestObjectBase *baseClone() const RT_OVERRIDE;
    99103    virtual int setNull(void) RT_OVERRIDE;
    100104    virtual int resetToDefault() RT_OVERRIDE;
  • trunk/include/iprt/cpp/restarray.h

    r74181 r74387  
    4747
    4848    /* Overridden methods: */
     49    virtual RTCRestObjectBase *baseClone() const RT_OVERRIDE;
    4950    virtual int resetToDefault() RT_OVERRIDE;
    5051    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
     
    132133
    133134    /**
     135     * Helper for creating a clone.
     136     *
     137     * @returns Pointer to new array on success, NULL if out of memory.
     138     */
     139    virtual RTCRestArrayBase *createClone(void) const = 0;
     140
     141    /**
    134142     * Wrapper around the value constructor.
    135143     *
     
    137145     */
    138146    virtual RTCRestObjectBase *createValue(void) = 0;
    139 
    140     /**
    141      * Wrapper around the value copy constructor.
    142      *
    143      * @returns Pointer to copy on success, NULL if out of memory.
    144      * @param   a_pSrc      The value to copy.
    145      */
    146     virtual RTCRestObjectBase *createValueCopy(RTCRestObjectBase const *a_pSrc) = 0;
    147147
    148148    /**
     
    214214
    215215    /** Copy assignment operator. */
    216     RTCRestArray &operator=(RTCRestArray const &a_rThat)
     216    inline RTCRestArray &operator=(RTCRestArray const &a_rThat)
    217217    {
    218218        copyArrayWorker(a_rThat, true /*fThrow*/);
     
    221221
    222222    /** Safe copy assignment method. */
    223     int assignCopy(RTCRestArray const &a_rThat)
     223    inline int assignCopy(RTCRestArray const &a_rThat)
    224224    {
    225225        return copyArrayWorker(a_rThat, false /*fThrow*/);
     226    }
     227
     228    /** Make a clone of this object. */
     229    inline RTCRestArray *clone() const
     230    {
     231        return (RTCRestArray *)baseClone();
    226232    }
    227233
     
    403409
    404410protected:
     411    virtual RTCRestArrayBase *createClone(void) const RT_OVERRIDE
     412    {
     413        return new (std::nothrow) RTCRestArray();
     414    }
     415
    405416    virtual RTCRestObjectBase *createValue(void) RT_OVERRIDE
    406417    {
    407418        return new (std::nothrow) ElementType();
    408419    }
    409 
    410     virtual RTCRestObjectBase *createValueCopy(RTCRestObjectBase const *a_pSrc) RT_OVERRIDE
    411     {
    412         ElementType *pCopy = new (std::nothrow) ElementType();
    413         if (pCopy)
    414         {
    415             int rc = pCopy->assignCopy(*(ElementType const *)a_pSrc);
    416             if (RT_SUCCESS(rc))
    417                 return pCopy;
    418             delete pCopy;
    419         }
    420         return NULL;
    421     }
    422420};
    423421
  • trunk/include/iprt/cpp/restbase.h

    r74347 r74387  
    265265
    266266    /**
     267     * Create a copy of this object.
     268     *
     269     * @returns Pointer to copy.
     270     */
     271    virtual RTCRestObjectBase *baseClone() const = 0;
     272
     273    /**
    267274     * Tests if the object is @a null.
    268275     * @returns true if null, false if not.
     
    421428    /** Assign value and clear null indicator. */
    422429    void assignValue(bool a_fValue);
     430    /** Make a clone of this object. */
     431    inline RTCRestBool *clone() const { return (RTCRestBool *)baseClone(); }
    423432
    424433    /* Overridden methods: */
     434    virtual RTCRestObjectBase *baseClone() const RT_OVERRIDE;
    425435    virtual int resetToDefault() RT_OVERRIDE;
    426436    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
     
    461471    /** Assign value and clear null indicator. */
    462472    void assignValue(int64_t a_iValue);
     473    /** Make a clone of this object. */
     474    inline RTCRestInt64 *clone() const { return (RTCRestInt64 *)baseClone(); }
    463475
    464476    /* Overridden methods: */
     477    virtual RTCRestObjectBase *baseClone() const RT_OVERRIDE;
    465478    virtual int resetToDefault() RT_OVERRIDE;
    466479    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
     
    501514    /** Assign value and clear null indicator. */
    502515    void assignValue(int32_t a_iValue);
     516    /** Make a clone of this object. */
     517    inline RTCRestInt32 *clone() const { return (RTCRestInt32 *)baseClone(); }
    503518
    504519    /* Overridden methods: */
     520    virtual RTCRestObjectBase *baseClone() const RT_OVERRIDE;
    505521    virtual int resetToDefault() RT_OVERRIDE;
    506522    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
     
    541557    /** Assign value and clear null indicator. */
    542558    void assignValue(int16_t a_iValue);
     559    /** Make a clone of this object. */
     560    inline RTCRestInt16 *clone() const { return (RTCRestInt16 *)baseClone(); }
    543561
    544562    /* Overridden methods: */
     563    virtual RTCRestObjectBase *baseClone() const RT_OVERRIDE;
    545564    virtual int resetToDefault() RT_OVERRIDE;
    546565    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
     
    581600    /** Assign value and clear null indicator. */
    582601    void assignValue(double a_rdValue);
     602    /** Make a clone of this object. */
     603    inline RTCRestDouble *clone() const { return (RTCRestDouble *)baseClone(); }
    583604
    584605    /* Overridden methods: */
     606    virtual RTCRestObjectBase *baseClone() const RT_OVERRIDE;
    585607    virtual int resetToDefault() RT_OVERRIDE;
    586608    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
     
    604626 * Class wrapping 'RTCString'.
    605627 */
    606 class RT_DECL_CLASS RTCRestString : public RTCString, public RTCRestObjectBase
     628class RT_DECL_CLASS RTCRestString : public RTCRestObjectBase, public RTCString
    607629{
    608630public:
     
    624646    /** Safe copy assignment method. */
    625647    int assignCopy(const char *a_pszThat);
     648    /** Make a clone of this object. */
     649    inline RTCRestString *clone() const { return (RTCRestString *)baseClone(); }
    626650
    627651    /* Overridden methods: */
     652    virtual RTCRestObjectBase *baseClone() const RT_OVERRIDE;
    628653    virtual int setNull(void) RT_OVERRIDE; /* (ambigious, so overrider it to make sure.) */
    629654    virtual int resetToDefault() RT_OVERRIDE;
     
    688713    /** Safe copy assignment method. */
    689714    int assignCopy(RTCRestDate const &a_rThat);
     715    /** Make a clone of this object. */
     716    inline RTCRestDate *clone() const { return (RTCRestDate *)baseClone(); }
    690717
    691718    /* Overridden methods: */
     719    virtual RTCRestObjectBase *baseClone() const RT_OVERRIDE;
    692720    virtual int resetToDefault() RT_OVERRIDE;
    693721    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
     
    908936    bool                setWorker(int a_iEnumValue);
    909937
     938    /** Helper for implementing RTCRestObjectBase::clone(). */
     939    RTCRestObjectBase  *cloneWorker(RTCRestStringEnumBase *a_pDst) const;
     940
    910941    /**
    911942     * Gets the mapping table.
     
    949980    inline size_t          getSize() const { return m_cbData; }
    950981
     982    /** Make a clone of this object. */
     983    inline RTCRestBinary  *clone() const { return (RTCRestBinary *)baseClone(); }
     984
    951985    /* Overridden methods: */
     986    virtual RTCRestObjectBase *baseClone() const RT_OVERRIDE;
    952987    virtual int setNull(void) RT_OVERRIDE;
    953988    virtual int resetToDefault(void) RT_OVERRIDE;
     
    9831018
    9841019/**
    985  * Abstract base class for REST data model objects.
     1020 * Abstract base class for REST data model classes.
    9861021 */
    9871022class RT_DECL_CLASS RTCRestDataObject : public RTCRestObjectBase
     
    9981033    virtual kTypeClass typeClass(void) const RT_OVERRIDE;
    9991034
    1000     /** Safe copy assignment method. */
    1001     virtual int assignCopy(RTCRestDataObject const &a_rThat);
    1002 
    10031035    /**
    10041036     * Serialize the members as JSON.
     
    10281060    /** Copy assignment operator. */
    10291061    RTCRestDataObject &operator=(RTCRestDataObject const &a_rThat);
     1062
     1063    /** Safe copy assignment method. */
     1064    virtual int assignCopy(RTCRestDataObject const &a_rThat);
     1065};
     1066
     1067
     1068/**
     1069 * Abstract base class for polymorphic REST data model classes.
     1070 */
     1071class RT_DECL_CLASS RTCRestPolyDataObject : public RTCRestDataObject
     1072{
     1073public:
     1074    RTCRestPolyDataObject();
     1075    RTCRestPolyDataObject(RTCRestPolyDataObject const &a_rThat);
     1076    virtual ~RTCRestPolyDataObject();
     1077
     1078    /* Overridden methods:*/
     1079    virtual int resetToDefault() RT_OVERRIDE;
     1080
     1081    /** Checks if the instance is of a child class (@c true) or of the parent (@c false). */
     1082    virtual bool isChild() const;
     1083
     1084protected:
     1085
     1086    /** Copy assignment operator. */
     1087    RTCRestPolyDataObject &operator=(RTCRestPolyDataObject const &a_rThat);
    10301088};
    10311089
  • trunk/include/iprt/cpp/restclient.h

    r74351 r74387  
    6666    virtual int assignWriteable(void *a_pvBuf, size_t a_cbBuf) RT_OVERRIDE;
    6767
     68    /** Make a clone of this object. */
     69    inline RTCRestBinaryParameter *clone() const { return (RTCRestBinaryParameter *)baseClone(); }
     70
    6871    /* Overridden methods: */
     72    virtual RTCRestObjectBase *baseClone() const RT_OVERRIDE;
    6973    virtual int resetToDefault() RT_OVERRIDE;
    7074    virtual const char *typeName(void) const RT_OVERRIDE;
     
    200204    virtual int assignWriteable(void *a_pvBuf, size_t a_cbBuf) RT_OVERRIDE;
    201205
     206    /** Make a clone of this object. */
     207    inline RTCRestBinaryResponse *clone() const { return (RTCRestBinaryResponse *)baseClone(); }
     208
    202209    /* Overridden methods: */
     210    virtual RTCRestObjectBase *baseClone() const RT_OVERRIDE;
    203211    virtual int resetToDefault() RT_OVERRIDE;
    204212    virtual const char *typeName(void) const RT_OVERRIDE;
  • trunk/include/iprt/cpp/reststringmap.h

    r74197 r74387  
    5353
    5454    /* Overridden methods: */
     55    virtual RTCRestObjectBase *baseClone() const RT_OVERRIDE;
    5556    virtual int resetToDefault() RT_OVERRIDE;
    5657    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
     
    216217protected:
    217218    /**
     219     * Helper for creating a clone.
     220     *
     221     * @returns Pointer to new map object on success, NULL if out of memory.
     222     */
     223    virtual RTCRestStringMapBase *createClone(void) const = 0;
     224
     225    /**
    218226     * Wrapper around the value constructor.
    219227     *
     
    221229     */
    222230    virtual RTCRestObjectBase *createValue(void) = 0;
    223 
    224     /**
    225      * Wrapper around the value copy constructor.
    226      *
    227      * @returns Pointer to copy on success, NULL if out of memory.
    228      * @param   a_pSrc      The value to copy.
    229      */
    230     virtual RTCRestObjectBase *createValueCopy(RTCRestObjectBase const *a_pSrc) = 0;
    231231
    232232    /**
     
    324324    }
    325325
     326    /** Make a clone of this object. */
     327    inline RTCRestStringMap *clone() const
     328    {
     329        return (RTCRestStringMap *)baseClone();
     330    }
     331
    326332    /** Factory method. */
    327333    static DECLCALLBACK(RTCRestObjectBase *) createInstance(void)
     
    439445
    440446protected:
     447    virtual RTCRestStringMapBase *createClone(void) const RT_OVERRIDE
     448    {
     449        return new (std::nothrow) RTCRestStringMap();
     450    }
     451
    441452    virtual RTCRestObjectBase *createValue(void) RT_OVERRIDE
    442453    {
    443454        return new (std::nothrow) ValueType();
    444455    }
    445 
    446     virtual RTCRestObjectBase *createValueCopy(RTCRestObjectBase const *a_pSrc) RT_OVERRIDE
    447     {
    448         ValueType *pCopy = new (std::nothrow) ValueType();
    449         if (pCopy)
    450         {
    451             int rc = pCopy->assignCopy(*(ValueType const *)a_pSrc);
    452             if (RT_SUCCESS(rc))
    453                 return pCopy;
    454             delete pCopy;
    455         }
    456         return NULL;
    457     }
    458456};
    459457
  • trunk/src/VBox/Runtime/VBox/VBoxRTImp-vcc32.def

    r74351 r74387  
    220220    ?assignCopy@RTCRestBinaryResponse@@UAEHPBXI@Z                               ; (public: virtual int __thiscall RTCRestBinaryResponse::assignCopy(void const *,unsigned int))
    221221    ?assignCopy@RTCRestBool@@QAEHABV1@@Z                                        ; (public: int __thiscall RTCRestBool::assignCopy(class RTCRestBool const &))
    222     ?assignCopy@RTCRestDataObject@@UAEHABV1@@Z                                  ; (public: virtual int __thiscall RTCRestDataObject::assignCopy(class RTCRestDataObject const &))
     222    ?assignCopy@RTCRestDataObject@@MAEHABV1@@Z                                  ; (protected: virtual int __thiscall RTCRestDataObject::assignCopy(class RTCRestDataObject const &))
    223223    ?assignCopy@RTCRestDate@@QAEHABV1@@Z                                        ; (public: int __thiscall RTCRestDate::assignCopy(class RTCRestDate const &))
    224224    ?assignCopy@RTCRestDouble@@QAEHABV1@@Z                                      ; (public: int __thiscall RTCRestDouble::assignCopy(class RTCRestDouble const &))
  • trunk/src/VBox/Runtime/VBox/VBoxRTImp-vcc64.def

    r74351 r74387  
    220220    ?assignCopy@RTCRestBinaryResponse@@UEAAHPEBX_K@Z                            ; (public: virtual int __cdecl RTCRestBinaryResponse::assignCopy(void const *,unsigned __int64))
    221221    ?assignCopy@RTCRestBool@@QEAAHAEBV1@@Z                                      ; (public: int __cdecl RTCRestBool::assignCopy(class RTCRestBool const &))
    222     ?assignCopy@RTCRestDataObject@@UEAAHAEBV1@@Z                                ; (public: virtual int __cdecl RTCRestDataObject::assignCopy(class RTCRestDataObject const &))
     222    ?assignCopy@RTCRestDataObject@@MEAAHAEBV1@@Z                                ; (protected: virtual int __cdecl RTCRestDataObject::assignCopy(class RTCRestDataObject const &))
    223223    ?assignCopy@RTCRestDate@@QEAAHAEBV1@@Z                                      ; (public: int __cdecl RTCRestDate::assignCopy(class RTCRestDate const &))
    224224    ?assignCopy@RTCRestDouble@@QEAAHAEBV1@@Z                                    ; (public: int __cdecl RTCRestDouble::assignCopy(class RTCRestDouble const &))
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