Changeset 74414 in vbox for trunk/src/VBox/Runtime/common/rest
- Timestamp:
- Sep 21, 2018 6:23:01 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 125249
- Location:
- trunk/src/VBox/Runtime/common/rest
- Files:
-
- 2 added
- 6 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/rest/RTCRestAnyObject.cpp
r74402 r74414 34 34 #include <iprt/assert.h> 35 35 #include <iprt/err.h> 36 #include <iprt/cpp/restoutput.h> 36 37 37 38 … … 419 420 if (m_pData) 420 421 return m_pData->serializeAsJson(a_rDst); 421 a_rDst. printf("null");422 a_rDst.nullValue(); 422 423 return a_rDst; 423 424 } -
trunk/src/VBox/Runtime/common/rest/RTCRestArrayBase.cpp
r74402 r74414 34 34 #include <iprt/err.h> 35 35 #include <iprt/string.h> 36 #include <iprt/cpp/restoutput.h> 36 37 37 38 … … 117 118 if (!m_fNullIndicator) 118 119 { 119 a_rDst.printf("[\n"); 120 unsigned const uOldIndent = a_rDst.incrementIndent(); 121 120 uint32_t const uOldState = a_rDst.beginArray(); 122 121 for (size_t i = 0; i < m_cElements; i++) 123 122 { 123 a_rDst.valueSeparator(); 124 124 m_papElements[i]->serializeAsJson(a_rDst); 125 if (i < m_cElements - 1) 126 a_rDst.printf(",\n"); 127 else 128 a_rDst.printf("\n"); 129 } 130 131 a_rDst.setIndent(uOldIndent); 132 a_rDst.printf("]"); 125 } 126 a_rDst.endArray(uOldState); 133 127 } 134 128 else 135 a_rDst. printf("null");129 a_rDst.nullValue(); 136 130 return a_rDst; 137 131 } -
trunk/src/VBox/Runtime/common/rest/RTCRestOutputPrettyToString.cpp
r74403 r74414 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - C++ REST, RTCRestOutput ToString implementation.3 * IPRT - C++ REST, RTCRestOutputPrettyToString implementation. 4 4 */ 5 5 … … 30 30 *********************************************************************************************************************************/ 31 31 #define LOG_GROUP RTLOGGROUP_REST 32 #include <iprt/cpp/rest base.h>32 #include <iprt/cpp/restoutput.h> 33 33 34 34 #include <iprt/err.h> … … 36 36 37 37 38 RTCRestOutputToString::RTCRestOutputToString(RTCString *a_pDst, bool a_fAppend /*= false*/) 39 : m_pDst(a_pDst) 38 RTCRestOutputPrettyToString::RTCRestOutputPrettyToString(RTCString *a_pDst, bool a_fAppend /*= false*/) 39 : RTCRestOutputPrettyBase() 40 , m_pDst(a_pDst) 40 41 , m_fOutOfMemory(false) 41 42 { … … 45 46 46 47 47 RTCRestOutput ToString::~RTCRestOutputToString()48 RTCRestOutputPrettyToString::~RTCRestOutputPrettyToString() 48 49 { 49 50 /* We don't own the string, so we don't delete it! */ … … 52 53 53 54 54 /** 55 * @callback_method_impl{FNRTSTROUTPUT} 56 */ 57 /*static*/ DECLCALLBACK(size_t) 58 RTCRestOutputToString::strOutput(void *pvArg, const char *pachChars, size_t cbChars) 55 size_t RTCRestOutputPrettyToString::output(const char *a_pchString, size_t a_cchToWrite) 59 56 { 60 RTCRestOutputToString *pThis = (RTCRestOutputToString *)pvArg; 61 if (cbChars) 57 if (a_cchToWrite) 62 58 { 63 RTCString *pDst = pThis->m_pDst;64 if (pDst && ! pThis->m_fOutOfMemory)59 RTCString *pDst = m_pDst; 60 if (pDst && !m_fOutOfMemory) 65 61 { 66 62 /* … … 69 65 size_t cchCurrent = pDst->length(); 70 66 size_t cbCapacity = pDst->capacity(); 71 size_t cbNeeded = cchCurrent + cbChars+ 1;67 size_t cbNeeded = cchCurrent + a_cchToWrite + 1; 72 68 if (cbNeeded <= cbCapacity) 73 69 { /* likely */ } … … 96 92 if (RT_FAILURE(rc)) 97 93 { 98 pThis->m_fOutOfMemory = true;99 return cbChars;94 m_fOutOfMemory = true; 95 return a_cchToWrite; 100 96 } 101 97 } … … 105 101 * Do the appending. 106 102 */ 107 pDst->append( pachChars, cbChars);103 pDst->append(a_pchString, a_cchToWrite); 108 104 } 109 105 } 110 return cbChars;106 return a_cchToWrite; 111 107 } 112 108 113 109 114 size_t RTCRestOutputToString::vprintf(const char *pszFormat, va_list va) 115 { 116 return RTStrFormatV(strOutput, this, NULL, NULL, pszFormat, va); 117 } 118 119 120 RTCString *RTCRestOutputToString::finalize() 110 RTCString *RTCRestOutputPrettyToString::finalize() 121 111 { 122 112 RTCString *pRet; -
trunk/src/VBox/Runtime/common/rest/RTCRestOutputToString.cpp
r73977 r74414 30 30 *********************************************************************************************************************************/ 31 31 #define LOG_GROUP RTLOGGROUP_REST 32 #include <iprt/cpp/rest base.h>32 #include <iprt/cpp/restoutput.h> 33 33 34 34 #include <iprt/err.h> … … 37 37 38 38 RTCRestOutputToString::RTCRestOutputToString(RTCString *a_pDst, bool a_fAppend /*= false*/) 39 : m_pDst(a_pDst) 39 : RTCRestOutputBase() 40 , m_pDst(a_pDst) 40 41 , m_fOutOfMemory(false) 41 42 { … … 52 53 53 54 54 /** 55 * @callback_method_impl{FNRTSTROUTPUT} 56 */ 57 /*static*/ DECLCALLBACK(size_t) 58 RTCRestOutputToString::strOutput(void *pvArg, const char *pachChars, size_t cbChars) 55 size_t RTCRestOutputToString::output(const char *a_pchString, size_t a_cchToWrite) 59 56 { 60 RTCRestOutputToString *pThis = (RTCRestOutputToString *)pvArg; 61 if (cbChars) 57 if (a_cchToWrite) 62 58 { 63 RTCString *pDst = pThis->m_pDst;64 if (pDst && ! pThis->m_fOutOfMemory)59 RTCString *pDst = m_pDst; 60 if (pDst && !m_fOutOfMemory) 65 61 { 66 62 /* … … 69 65 size_t cchCurrent = pDst->length(); 70 66 size_t cbCapacity = pDst->capacity(); 71 size_t cbNeeded = cchCurrent + cbChars+ 1;67 size_t cbNeeded = cchCurrent + a_cchToWrite + 1; 72 68 if (cbNeeded <= cbCapacity) 73 69 { /* likely */ } … … 96 92 if (RT_FAILURE(rc)) 97 93 { 98 pThis->m_fOutOfMemory = true;99 return cbChars;94 m_fOutOfMemory = true; 95 return a_cchToWrite; 100 96 } 101 97 } … … 105 101 * Do the appending. 106 102 */ 107 pDst->append( pachChars, cbChars);103 pDst->append(a_pchString, a_cchToWrite); 108 104 } 109 105 } 110 return cbChars; 111 } 112 113 114 size_t RTCRestOutputToString::vprintf(const char *pszFormat, va_list va) 115 { 116 return RTStrFormatV(strOutput, this, NULL, NULL, pszFormat, va); 106 return a_cchToWrite; 117 107 } 118 108 -
trunk/src/VBox/Runtime/common/rest/RTCRestStringMapBase.cpp
r74402 r74414 34 34 #include <iprt/err.h> 35 35 #include <iprt/string.h> 36 #include <iprt/cpp/restoutput.h> 36 37 37 38 … … 101 102 if (!m_fNullIndicator) 102 103 { 103 a_rDst.printf("{\n"); 104 unsigned const uOldIndent = a_rDst.incrementIndent(); 105 106 MapEntry const * const pLast = RTListGetLastCpp(&m_ListHead, MapEntry, ListEntry); 107 MapEntry const * pCur; 104 uint32_t const uOldState = a_rDst.beginObject(); 105 MapEntry const *pCur; 108 106 RTListForEachCpp(&m_ListHead, pCur, MapEntry, ListEntry) 109 107 { 110 a_rDst. printf("%RJs: ", pCur->strKey.c_str());108 a_rDst.valueSeparatorAndName(pCur->strKey.c_str(), pCur->strKey.length()); 111 109 pCur->pValue->serializeAsJson(a_rDst); 112 113 if (pCur != pLast)114 a_rDst.printf(",\n");115 else116 a_rDst.printf("\n");117 110 } 118 119 a_rDst.setIndent(uOldIndent); 120 a_rDst.printf("}"); 111 a_rDst.endArray(uOldState); 121 112 } 122 113 else 123 a_rDst. printf("null");114 a_rDst.nullValue(); 124 115 return a_rDst; 125 116 } -
trunk/src/VBox/Runtime/common/rest/rest-binary.cpp
r74402 r74414 35 35 #include <iprt/assert.h> 36 36 #include <iprt/err.h> 37 #include <iprt/cpp/restoutput.h> 37 38 38 39 … … 209 210 { 210 211 AssertMsgFailed(("We should never get here!\n")); 211 a_rDst. printf("null");212 a_rDst.nullValue(); 212 213 return a_rDst; 213 214 } -
trunk/src/VBox/Runtime/common/rest/rest-primary-object-types.cpp
r74402 r74414 35 35 #include <iprt/err.h> 36 36 #include <iprt/string.h> 37 #include <iprt/cpp/restoutput.h> 37 38 38 39 #include <stdio.h> … … 409 410 a_rDst.printf("%RI64", m_iValue); 410 411 else 411 a_rDst. printf("null");412 a_rDst.nullValue(); 412 413 return a_rDst; 413 414 } … … 593 594 a_rDst.printf("%RI32", m_iValue); 594 595 else 595 a_rDst. printf("null");596 a_rDst.nullValue(); 596 597 return a_rDst; 597 598 } … … 783 784 a_rDst.printf("%RI16", m_iValue); 784 785 else 785 a_rDst. printf("null");786 a_rDst.nullValue(); 786 787 return a_rDst; 787 788 } … … 989 990 } 990 991 else 991 a_rDst. printf("null");992 a_rDst.nullValue(); 992 993 return a_rDst; 993 994 } … … 1238 1239 a_rDst.printf("%RMjs", m_psz ? m_psz : ""); 1239 1240 else 1240 a_rDst. printf("null");1241 a_rDst.nullValue(); 1241 1242 return a_rDst; 1242 1243 } … … 1546 1547 { 1547 1548 if (m_fNullIndicator) 1548 a_rDst. printf("null");1549 a_rDst.nullValue(); 1549 1550 else 1550 1551 a_rDst.printf("%RMjs", m_strFormatted.c_str()); … … 1958 1959 a_rDst.printf("%RMjs", getString()); 1959 1960 else 1960 a_rDst. printf("null");1961 a_rDst.nullValue(); 1961 1962 return a_rDst; 1962 1963 } … … 2228 2229 2229 2230 2230 const char *RTCRestDataObject::serializeMembersAsJson(RTCRestOutputBase &a_rDst, const char *a_pszSep) const2231 RTCRestOutputBase &RTCRestDataObject::serializeMembersAsJson(RTCRestOutputBase &a_rDst) const 2231 2232 { 2232 2233 RT_NOREF(a_rDst); 2233 return a_ pszSep;2234 return a_rDst; 2234 2235 } 2235 2236 … … 2239 2240 if (!m_fNullIndicator) 2240 2241 { 2241 a_rDst.printf("{"); 2242 unsigned const uOldIndent = a_rDst.incrementIndent(); 2243 2244 const char *pszSep = serializeMembersAsJson(a_rDst, ""); 2245 2246 a_rDst.setIndent(uOldIndent); 2247 a_rDst.printf("%s}", *pszSep != '\0' ? "\n" : ""); 2242 uint32_t const uOldState = a_rDst.beginObject(); 2243 serializeMembersAsJson(a_rDst); 2244 a_rDst.endObject(uOldState); 2248 2245 } 2249 2246 else 2250 a_rDst. printf("null");2247 a_rDst.nullValue(); 2251 2248 return a_rDst; 2252 2249 }
Note:
See TracChangeset
for help on using the changeset viewer.