VirtualBox

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


Ignore:
Timestamp:
Aug 26, 2018 3:47:58 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
124612
Message:

IPRT/rest: Wrap primitive types to unify serializing, deserializing, formatting, array, maps, and whatnot. bugref:9167

File:
1 edited

Legend:

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

    r73889 r73895  
    126126    virtual ~RTCRestOutputToString();
    127127
    128     size_t vprintf(const char *pszFormat, va_list va);
     128    virtual size_t vprintf(const char *pszFormat, va_list va) RT_OVERRIDE;
    129129
    130130    /**
     
    257257{
    258258public:
    259     RTCRestObjectBase() {}
    260     virtual ~RTCRestObjectBase() {}
     259    RTCRestObjectBase();
     260    virtual ~RTCRestObjectBase();
    261261
    262262    /** @todo Add some kind of state? */
     
    265265     * Resets the object to all default values.
    266266     */
    267     virtual void resetToDefaults() = 0;
     267    virtual void resetToDefault() = 0;
    268268
    269269    /**
     
    283283    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) = 0;
    284284
    285     /** @name Helpers for deserializing primitive types and strings.
    286      * @{ */
    287     static int deserialize_RTCString_FromJson(RTCRestJsonCursor const &a_rCursor, RTCString *a_pDst);
    288     static int deserialize_int64_t_FromJson(RTCRestJsonCursor const &a_rCursor, int64_t *a_piDst);
    289     static int deserialize_int32_t_FromJson(RTCRestJsonCursor const &a_rCursor, int32_t *a_piDst);
    290     static int deserialize_int16_t_FromJson(RTCRestJsonCursor const &a_rCursor, int16_t *a_piDst);
    291     static int deserialize_bool_FromJson(RTCRestJsonCursor const &a_rCursor, bool *a_pfDst);
    292     static int deserialize_double_FromJson(RTCRestJsonCursor const &a_rCursor, double *a_prdDst);
    293     /** @} */
    294 
    295     /** @name Helpers for serializing floating point types.
    296      * @{ */
    297     static RTCRestOutputBase &serialize_double_AsJson(RTCRestOutputBase &a_rDst, double const *a_prdValue);
    298     /** @} */
     285    /**
     286     * String conversion.
     287     *
     288     * The default implementation of is a wrapper around serializeAsJson().
     289     *
     290     * @returns IPRT status code.
     291     * @param   a_pDst      Pointer to the destionation string.
     292     * @param   a_fFlags    For future tricks, MBZ.
     293     */
     294    virtual int toString(RTCString *a_pDst, uint32_t fFlags = 0);
     295
     296    /**
     297     * String convertsion, naive variant.
     298     *
     299     * @returns String represenation.
     300     */
     301    RTCString toString();
     302
     303    /**
     304     * Returns the object type name.
     305     */
     306    virtual const char *getType(void) = 0;
     307};
     308
     309
     310/**
     311 * Class wrapping 'bool'.
     312 */
     313class RTCRestBool : public RTCRestObjectBase
     314{
     315public:
     316    /** Default destructor. */
     317    RTCRestBool();
     318    /** Copy constructor. */
     319    RTCRestBool(RTCRestBool const &a_rThat);
     320    /** From value constructor. */
     321    RTCRestBool(bool fValue);
     322    /** Destructor. */
     323    virtual ~RTCRestBool();
     324    /** Copy assignment operator. */
     325    RTCRestBool &operator=(RTCRestBool const &a_rThat);
     326
     327    /* Overridden methods: */
     328    virtual void resetToDefault() RT_OVERRIDE;
     329    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) RT_OVERRIDE;
     330    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
     331    virtual int toString(RTCString *a_pDst, uint32_t fFlags = 0) RT_OVERRIDE;
     332    virtual const char *getType(void) RT_OVERRIDE;
     333
     334public:
     335    /** The value. */
     336    bool    m_fValue;
     337};
     338
     339
     340/**
     341 * Class wrapping 'int64_t'.
     342 */
     343class RTCRestInt64 : public RTCRestObjectBase
     344{
     345public:
     346    /** Default destructor. */
     347    RTCRestInt64();
     348    /** Copy constructor. */
     349    RTCRestInt64(RTCRestInt64 const &a_rThat);
     350    /** From value constructor. */
     351    RTCRestInt64(int64_t iValue);
     352    /** Destructor. */
     353    virtual ~RTCRestInt64();
     354    /** Copy assignment operator. */
     355    RTCRestInt64 &operator=(RTCRestInt64 const &a_rThat);
     356
     357        /* Overridden methods: */
     358    virtual void resetToDefault() RT_OVERRIDE;
     359    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) RT_OVERRIDE;
     360    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
     361    virtual int toString(RTCString *a_pDst, uint32_t fFlags = 0) RT_OVERRIDE;
     362    virtual const char *getType(void) RT_OVERRIDE;
     363
     364public:
     365    /** The value. */
     366    int64_t m_iValue;
     367};
     368
     369
     370/**
     371 * Class wrapping 'int32_t'.
     372 */
     373class RTCRestInt32 : public RTCRestObjectBase
     374{
     375public:
     376    /** Default destructor. */
     377    RTCRestInt32();
     378    /** Copy constructor. */
     379    RTCRestInt32(RTCRestInt32 const &a_rThat);
     380    /** From value constructor. */
     381    RTCRestInt32(int32_t iValue);
     382    /** Destructor. */
     383    virtual ~RTCRestInt32();
     384    /** Copy assignment operator. */
     385    RTCRestInt32 &operator=(RTCRestInt32 const &a_rThat);
     386
     387    /* Overridden methods: */
     388    virtual void resetToDefault() RT_OVERRIDE;
     389    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) RT_OVERRIDE;
     390    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
     391    virtual int toString(RTCString *a_pDst, uint32_t fFlags = 0) RT_OVERRIDE;
     392    virtual const char *getType(void) RT_OVERRIDE;
     393
     394public:
     395    /** The value. */
     396    int32_t m_iValue;
     397};
     398
     399
     400/**
     401 * Class wrapping 'int16_t'.
     402 */
     403class RTCRestInt16 : public RTCRestObjectBase
     404{
     405public:
     406    /** Default destructor. */
     407    RTCRestInt16();
     408    /** Copy constructor. */
     409    RTCRestInt16(RTCRestInt16 const &a_rThat);
     410    /** From value constructor. */
     411    RTCRestInt16(int16_t iValue);
     412    /** Destructor. */
     413    virtual ~RTCRestInt16();
     414    /** Copy assignment operator. */
     415    RTCRestInt16 &operator=(RTCRestInt16 const &a_rThat);
     416
     417    /* Overridden methods: */
     418    virtual void resetToDefault() RT_OVERRIDE;
     419    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) RT_OVERRIDE;
     420    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
     421    virtual int toString(RTCString *a_pDst, uint32_t fFlags = 0) RT_OVERRIDE;
     422    virtual const char *getType(void) RT_OVERRIDE;
     423
     424public:
     425    /** The value. */
     426    int16_t m_iValue;
     427};
     428
     429
     430/**
     431 * Class wrapping 'double'.
     432 */
     433class RTCRestDouble : public RTCRestObjectBase
     434{
     435public:
     436    /** Default destructor. */
     437    RTCRestDouble();
     438    /** Copy constructor. */
     439    RTCRestDouble(RTCRestDouble const &a_rThat);
     440    /** From value constructor. */
     441    RTCRestDouble(double rdValue);
     442    /** Destructor. */
     443    virtual ~RTCRestDouble();
     444    /** Copy assignment operator. */
     445    RTCRestDouble &operator=(RTCRestDouble const &a_rThat);
     446
     447    /* Overridden methods: */
     448    virtual void resetToDefault() RT_OVERRIDE;
     449    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) RT_OVERRIDE;
     450    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
     451    virtual int toString(RTCString *a_pDst, uint32_t fFlags = 0) RT_OVERRIDE;
     452    virtual const char *getType(void) RT_OVERRIDE;
     453
     454public:
     455    /** The value. */
     456    double m_rdValue;
     457};
     458
     459
     460/**
     461 * Class wrapping 'RTCString'.
     462 */
     463class RTCRestString : public RTCString, public RTCRestObjectBase
     464{
     465public:
     466    /** Default destructor. */
     467    RTCRestString();
     468    /** Copy constructor. */
     469    RTCRestString(RTCRestString const &a_rThat);
     470    /** From value constructor. */
     471    RTCRestString(RTCString const &a_rThat);
     472    /** From value constructor. */
     473    RTCRestString(const char *a_pszSrc);
     474    /** Destructor. */
     475    virtual ~RTCRestString();
     476
     477    /* Overridden methods: */
     478    virtual void resetToDefault() RT_OVERRIDE;
     479    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) RT_OVERRIDE;
     480    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE;
     481    virtual int toString(RTCString *a_pDst, uint32_t fFlags = 0) RT_OVERRIDE;
     482    virtual const char *getType(void) RT_OVERRIDE;
    299483};
    300484
     
    310494/** @todo more later. */
    311495
    312     virtual void resetToDefaults();
    313     virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst);
    314     virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor)
     496    virtual void resetToDefault() RT_OVERRIDE;
     497    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) RT_OVERRIDE;
     498    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE
    315499    {
    316500        RT_NOREF(a_rCursor);
    317501        return VERR_NOT_IMPLEMENTED;
    318502    }
     503    virtual const char *getType(void) RT_OVERRIDE;
    319504};
    320505
     
    330515/** @todo more later. */
    331516
    332     virtual void resetToDefaults();
    333     virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst);
    334     virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor)
     517    virtual void resetToDefault() RT_OVERRIDE;
     518    virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) RT_OVERRIDE;
     519    virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_OVERRIDE
    335520    {
    336521        RT_NOREF(a_rCursor);
    337522        return VERR_NOT_IMPLEMENTED;
    338523    }
     524    virtual const char *getType(void) RT_OVERRIDE;
    339525};
    340526
     
    352538     * Reset all members to default values.
    353539     */
    354     virtual void resetToDefaults() = 0;
     540    virtual void resetToDefault() = 0;
    355541
    356542    /**
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