VirtualBox

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


Ignore:
Timestamp:
Aug 31, 2018 7:08:02 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
124754
Message:

IPRT/rest: Deal (more) properly with 'null'. bugref:9167

File:
1 edited

Legend:

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

    r73978 r74008  
    256256/**
    257257 * Abstract base class for REST data objects.
     258 *
     259 * The only information this keeps is the null indicator.
    258260 */
    259261class RT_DECL_CLASS RTCRestObjectBase
     
    261263public:
    262264    RTCRestObjectBase();
     265    RTCRestObjectBase(RTCRestObjectBase const &a_rThat);
    263266    virtual ~RTCRestObjectBase();
    264267
    265     /** @todo Add some kind of state? */
     268    /**
     269     * Tests if the object is @a null.
     270     * @returns true if null, false if not.
     271     */
     272    bool isNull(void) const { return m_fNullIndicator; };
     273
     274    /**
     275     * Sets the object to @a null and fills it with defaults.
     276     * @returns IPRT status code (from resetToDefault).
     277     */
     278    virtual int setNull(void);
     279
     280    /**
     281     * Sets the object to not-null state (i.e. undoes setNull()).
     282     * @remarks Only really important for strings.
     283     */
     284    virtual void setNotNull(void);
    266285
    267286    /**
     
    353372    /** Pointer to factory method. */
    354373    typedef FNCREATEINSTANCE *PFNCREATEINSTANCE;
     374
     375
     376protected:
     377    /** Null indicator.
     378     * @remarks The null values could be mapped onto C/C++ NULL pointer values,
     379     *          with the consequence that all data members in objects and such would
     380     *          have had to been allocated individually, even simple @a bool members.
     381     *          Given that we're overly paranoid about heap allocations (std::bad_alloc),
     382     *          it's more fitting to use a null indicator for us.
     383     */
     384    bool    m_fNullIndicator;
    355385};
    356386
     
    559589    RTCRestString(const char *a_pszSrc);
    560590    /** Safe copy assignment method. */
     591    int assignCopy(RTCRestString const &a_rThat);
     592    /** Safe copy assignment method. */
    561593    int assignCopy(RTCString const &a_rThat);
    562594    /** Safe copy assignment method. */
     
    564596
    565597    /* Overridden methods: */
     598    virtual int setNull(void) RT_OVERRIDE; /* (ambigious, so overrider it to make sure.) */
    566599    virtual int resetToDefault() RT_OVERRIDE;
    567600    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
     
    12971330
    12981331    /* Overridden methods: */
     1332    virtual int setNull(void) RT_OVERRIDE;
    12991333    virtual int resetToDefault() RT_OVERRIDE;
    13001334    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_OVERRIDE;
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