Changeset 73803 in vbox
- Timestamp:
- Aug 21, 2018 3:00:15 PM (6 years ago)
- File:
-
- 1 edited
-
trunk/include/iprt/cpp/restbase.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/restbase.h
r73802 r73803 28 28 29 29 #include <iprt/types.h> 30 #include <iprt/assert.h> 30 31 #include <iprt/err.h> 31 32 #include <iprt/http.h> 33 #include <iprt/json.h> 34 #include <iprt/stdarg.h> 35 #include <iprt/cpp/ministring.h> 32 36 #include <iprt/cpp/utils.h> 33 37 … … 40 44 41 45 /** 42 * Base class for REST data objects. 46 * Abstract base class for serializing data objects. 47 */ 48 class RTCRestOutputBase 49 { 50 public: 51 RTCRestOutputBase(); 52 virtual ~RTCRestOutputBase(); 53 54 /** 55 * RTStrPrintf like function (see @rel pg_rt_str_format). 56 * 57 * @returns Number of bytes outputted. 58 * @param uDepth The indentation level. 59 * @param pszFormat The format string. 60 * @param ... Argument specfied in @a pszFormat. 61 */ 62 size_t printf(unsigned uIndent, const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3) 63 { 64 va_list va; 65 va_start(va, pszFormat); 66 size_t cchWritten = this->vprintf(uIndent, pszFormat, va); 67 va_end(va); 68 return cchWritten; 69 } 70 71 /** 72 * RTStrPrintfV like function (see @rel pg_rt_str_format). 73 * 74 * @returns Number of bytes outputted. 75 * @param uDepth The indentation level. 76 * @param pszFormat The format string. 77 * @param va Argument specfied in @a pszFormat. 78 */ 79 virtual size_t vprintf(unsigned uIndent, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0) = 0; 80 }; 81 82 83 /** 84 * Serialize to a string object. 85 */ 86 class RTCRestOutputToString : public RTCRestOutputBase, public RTCNonCopyable 87 { 88 public: 89 /** 90 * Creates an instance that appends to @a a_pDst. 91 * @param a_pDst Pointer to the destination string object. 92 * NULL is not accepted and will assert. 93 */ 94 RTCRestOutputToString(RTCString *a_pDst); 95 virtual ~RTCRestOutputToString(); 96 97 size_t vprintf(unsigned uIndent, const char *pszFormat, va_list va); 98 99 /** 100 * Finalizes the output and releases the string object to the caller. 101 * 102 * @returns The released string object. NULL if we ran out of memory or if 103 * called already. 104 * 105 * @remark This sets m_pDst to NULL and the object cannot be use for any 106 * more output afterwards. 107 */ 108 virtual RTCString *finalize(void); 109 110 111 protected: 112 /** Pointer to the destination string. NULL after finalize(). */ 113 RTCString *m_pDst; 114 /** Set if we ran out of memory and should ignore subsequent calls. */ 115 bool m_fOutOfMemory; 116 }; 117 118 119 /** 120 * Abstract base class for REST data objects. 43 121 */ 44 122 class RTCSRestObjectBase … … 47 125 RTCSRestObjectBase() {} 48 126 virtual ~RTCSRestObjectBase() {} 127 49 128 /** @todo Add some kind of state? */ 129 130 /** 131 * Serialize the object as JSON. 132 * 133 * @returns a_rDst 134 * @param a_rDst The destination for the serialization. 135 * @param uIndent The indentation level. Increment by 1 for child 136 * objects. 137 */ 138 virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst, unsigned uIndent) = 0; 139 140 /** 141 * Deserialize object from the given JSON iterator. 142 * 143 * @returns IPRT status code. 144 * @param hJsonIt The JSON iterator for this object. 145 * @param pErrInfo Where to return additional error information. 146 * Optional. 147 * 148 * @todo Take a RTJSONVAL? 149 */ 150 virtual int deserializeFromJson(RTJSONIT hJsonIt, PRTERRINFO pErrInfo) = 0; 50 151 }; 51 152
Note:
See TracChangeset
for help on using the changeset viewer.

