VirtualBox

Ignore:
Timestamp:
Sep 20, 2018 3:51:35 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
125208
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
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