Changeset 74414 in vbox for trunk/include/iprt/cpp
- Timestamp:
- Sep 21, 2018 6:23:01 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 125249
- Location:
- trunk/include/iprt/cpp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/cpp/restbase.h
r74410 r74414 40 40 */ 41 41 42 43 44 /**45 * Abstract base class for serializing data objects.46 */47 class RT_DECL_CLASS RTCRestOutputBase48 {49 public:50 RTCRestOutputBase()51 : m_uIndent(0)52 { }53 virtual ~RTCRestOutputBase()54 { }55 56 /**57 * RTStrPrintf like function (see @ref pg_rt_str_format).58 *59 * @returns Number of bytes outputted.60 * @param pszFormat The format string.61 * @param ... Argument specfied in @a pszFormat.62 */63 size_t printf(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(2, 3)64 {65 va_list va;66 va_start(va, pszFormat);67 size_t cchWritten = this->vprintf(pszFormat, va);68 va_end(va);69 return cchWritten;70 }71 72 /**73 * RTStrPrintfV like function (see @ref pg_rt_str_format).74 *75 * @returns Number of bytes outputted.76 * @param pszFormat The format string.77 * @param va Argument specfied in @a pszFormat.78 */79 virtual size_t vprintf(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0) = 0;80 81 /**82 * Sets the indentation level for use when pretty priting things.83 *84 * @returns Previous indentation level.85 * @param uIndent The indentation level.86 */87 inline unsigned setIndent(unsigned uIndent)88 {89 unsigned const uRet = m_uIndent;90 m_uIndent = uIndent;91 return uRet;92 }93 94 /**95 * Increases the indentation level.96 *97 * @returns Previous indentation level.98 */99 inline unsigned incrementIndent()100 {101 unsigned const uRet = m_uIndent;102 m_uIndent = uRet + 1;103 return uRet;104 }105 106 protected:107 /** The current indentation level. */108 unsigned m_uIndent;109 };110 111 112 /**113 * Serialize to a string object.114 */115 class RT_DECL_CLASS RTCRestOutputToString : public RTCRestOutputBase116 {117 public:118 /**119 * Creates an instance that appends to @a a_pDst.120 * @param a_pDst Pointer to the destination string object.121 * NULL is not accepted and will assert.122 * @param a_fAppend Whether to append to the current string value, or123 * nuke the string content before starting the output.124 */125 RTCRestOutputToString(RTCString *a_pDst, bool a_fAppend = false);126 virtual ~RTCRestOutputToString();127 128 virtual size_t vprintf(const char *pszFormat, va_list va) RT_OVERRIDE;129 130 /**131 * Finalizes the output and releases the string object to the caller.132 *133 * @returns The released string object. NULL if we ran out of memory or if134 * called already.135 *136 * @remark This sets m_pDst to NULL and the object cannot be use for any137 * more output afterwards.138 */139 virtual RTCString *finalize();140 141 142 protected:143 /** Pointer to the destination string. NULL after finalize(). */144 RTCString *m_pDst;145 /** Set if we ran out of memory and should ignore subsequent calls. */146 bool m_fOutOfMemory;147 148 /** @callback_method_impl{FNRTSTROUTPUT} */149 static DECLCALLBACK(size_t) strOutput(void *pvArg, const char *pachChars, size_t cbChars);150 151 /* Make non-copyable (RTCNonCopyable causes warnings): */152 RTCRestOutputToString(RTCRestOutputToString const &);153 RTCRestOutputToString *operator=(RTCRestOutputToString const &);154 };155 156 157 42 /* forward decl: */ 43 class RTCRestOutputBase; 158 44 class RTCRestJsonPrimaryCursor; 159 45 … … 1134 1020 1135 1021 /** 1136 * Serialize the members as JSON.1137 * 1138 * @returns Leading separator prefix (empty string or comma string).1022 * Serialize the object members as JSON. 1023 * 1024 * @returns a_rDst 1139 1025 * @param a_rDst The destination for the serialization. 1140 * @param a_pszSep Leading separator prefix (empty or comma). 1141 */ 1142 virtual const char *serializeMembersAsJson(RTCRestOutputBase &a_rDst, const char *a_pszSep) const; 1026 */ 1027 virtual RTCRestOutputBase &serializeMembersAsJson(RTCRestOutputBase &a_rDst) const; 1143 1028 1144 1029 /** -
trunk/include/iprt/cpp/restclient.h
r74396 r74414 712 712 713 713 /* Make non-copyable (RTCNonCopyable causes warnings): */ 714 RTCRestClientApiBase(RTCRest OutputToStringconst &);715 RTCRestClientApiBase *operator=(RTCRest OutputToStringconst &);714 RTCRestClientApiBase(RTCRestClientApiBase const &); 715 RTCRestClientApiBase *operator=(RTCRestClientApiBase const &); 716 716 717 717 /**
Note:
See TracChangeset
for help on using the changeset viewer.