VirtualBox

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


Ignore:
Timestamp:
Sep 21, 2018 9:25:55 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
125227
Message:

IPRT/rest: Implemented array and string-map support for deserializating polymorphic objects. bugref:9167

Location:
trunk/include/iprt/cpp
Files:
4 edited

Legend:

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

    r74387 r74402  
    113113    /** Factory method. */
    114114    static DECLCALLBACK(RTCRestObjectBase *) createInstance(void);
     115    /** Deserialization w/ instantiation. */
     116    static FNDESERIALIZEINSTANCEFROMJSON deserializeInstanceFromJson;
    115117
    116118protected:
  • trunk/include/iprt/cpp/restarray.h

    r74387 r74402  
    147147
    148148    /**
     149     * For accessing the static deserializeInstanceFromJson() method of the value.
     150     */
     151    virtual int deserializeValueInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) = 0;
     152
     153    /**
    149154     * Worker for the copy constructor and the assignment operator.
    150155     *
     
    244249    }
    245250
     251    /** @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON */
     252    static DECLCALLBACK(int) deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance)
     253    {
     254        *a_ppInstance = new (std::nothrow) RTCRestArray<ElementType>();
     255        if (*a_ppInstance)
     256            return (*a_ppInstance)->deserializeFromJson(a_rCursor);
     257        return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_NO_MEMORY, "Out of memory");
     258    }
     259
    246260
    247261    /**
     
    418432        return new (std::nothrow) ElementType();
    419433    }
     434
     435    virtual int deserializeValueInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) RT_OVERRIDE
     436    {
     437        return ElementType::deserializeInstanceFromJson(a_rCursor, a_ppInstance);
     438    }
    420439};
    421440
  • trunk/include/iprt/cpp/restbase.h

    r74390 r74402  
    312312
    313313    /**
     314     * Polymorphic JSON deserialization helper that instantiate the matching class using
     315     * the discriminator field.
     316     *
     317     * @returns IPRT status code.
     318     * @param   a_rCursor    The JSON cursor.
     319     * @param   a_ppInstance Where to return the deserialized instance.
     320     *                       May return an object on failure.
     321     */
     322    typedef DECLCALLBACK(int) FNDESERIALIZEINSTANCEFROMJSON(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance);
     323    /** Pointer to a FNDESERIALIZEINSTANCEFROMJSON function. */
     324    typedef FNDESERIALIZEINSTANCEFROMJSON *PFNDESERIALIZEINSTANCEFROMJSON;
     325
     326    /**
    314327     * Flags for toString().
    315328     *
     
    444457    /** Factory method. */
    445458    static DECLCALLBACK(RTCRestObjectBase *) createInstance(void);
     459    /** Deserialization w/ instantiation. */
     460    static FNDESERIALIZEINSTANCEFROMJSON deserializeInstanceFromJson;
    446461
    447462public:
     
    487502    /** Factory method. */
    488503    static DECLCALLBACK(RTCRestObjectBase *) createInstance(void);
     504    /** Deserialization w/ instantiation. */
     505    static FNDESERIALIZEINSTANCEFROMJSON deserializeInstanceFromJson;
    489506
    490507public:
     
    530547    /** Factory method. */
    531548    static DECLCALLBACK(RTCRestObjectBase *) createInstance(void);
     549    /** Deserialization w/ instantiation. */
     550    static FNDESERIALIZEINSTANCEFROMJSON deserializeInstanceFromJson;
    532551
    533552public:
     
    573592    /** Factory method. */
    574593    static DECLCALLBACK(RTCRestObjectBase *) createInstance(void);
     594    /** Deserialization w/ instantiation. */
     595    static FNDESERIALIZEINSTANCEFROMJSON deserializeInstanceFromJson;
    575596
    576597public:
     
    616637    /** Factory method. */
    617638    static DECLCALLBACK(RTCRestObjectBase *) createInstance(void);
     639    /** Deserialization w/ instantiation. */
     640    static FNDESERIALIZEINSTANCEFROMJSON deserializeInstanceFromJson;
    618641
    619642public:
     
    663686    /** Factory method. */
    664687    static DECLCALLBACK(RTCRestObjectBase *) createInstance(void);
     688    /** Deserialization w/ instantiation. */
     689    static FNDESERIALIZEINSTANCEFROMJSON deserializeInstanceFromJson;
    665690
    666691    /** @name RTCString assignment methods we need to replace to manage the null indicator
     
    729754    /** Factory method. */
    730755    static DECLCALLBACK(RTCRestObjectBase *) createInstance(void);
     756    /** Deserialization w/ instantiation. */
     757    static FNDESERIALIZEINSTANCEFROMJSON deserializeInstanceFromJson;
    731758
    732759    /** Date formats. */
     
    9921019
    9931020    /** Factory method. */
    994     static DECLCALLBACK(RTCRestObjectBase *) createInstance(void) { return new (std::nothrow) RTCRestStringEnum(); }
     1021    static DECLCALLBACK(RTCRestObjectBase *) createInstance(void)
     1022    {
     1023        return new (std::nothrow) RTCRestStringEnum();
     1024    }
     1025
     1026    /** @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON */
     1027    static DECLCALLBACK(int) deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance)
     1028    {
     1029        *a_ppInstance = new (std::nothrow) RTCRestStringEnum();
     1030        if (*a_ppInstance)
     1031            return (*a_ppInstance)->deserializeFromJson(a_rCursor);
     1032        return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_NO_MEMORY, "Out of memory");
     1033    }
    9951034
    9961035protected:
     
    10561095    /** Factory method. */
    10571096    static DECLCALLBACK(RTCRestObjectBase *) createInstance(void);
     1097    /** Deserialization w/ instantiation. */
     1098    static FNDESERIALIZEINSTANCEFROMJSON deserializeInstanceFromJson;
    10581099
    10591100protected:
  • trunk/include/iprt/cpp/reststringmap.h

    r74387 r74402  
    231231
    232232    /**
     233     * For accessing the static deserializeInstanceFromJson() method of the value.
     234     */
     235    virtual int deserializeValueInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) = 0;
     236
     237    /**
    233238     * Worker for the copy constructor and the assignment operator.
    234239     *
     
    342347    }
    343348
     349    /** @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON */
     350    static DECLCALLBACK(int) deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance)
     351    {
     352        *a_ppInstance = new (std::nothrow) RTCRestStringMap<ValueType>();
     353        if (*a_ppInstance)
     354            return (*a_ppInstance)->deserializeFromJson(a_rCursor);
     355        return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_NO_MEMORY, "Out of memory");
     356    }
     357
    344358    /**
    345359     * Inserts the given object into the map.
     
    454468        return new (std::nothrow) ValueType();
    455469    }
     470
     471    virtual int deserializeValueInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) RT_OVERRIDE
     472    {
     473        return ValueType::deserializeInstanceFromJson(a_rCursor, a_ppInstance);
     474    }
    456475};
    457476
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