1 | /* $Id: RTCRestOutputBase.cpp 74417 2018-09-21 18:47:21Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - C++ REST, RTCRestOutputBase implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2018 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*********************************************************************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *********************************************************************************************************************************/
|
---|
31 | #define LOG_GROUP RTLOGGROUP_REST
|
---|
32 | #include <iprt/cpp/restoutput.h>
|
---|
33 |
|
---|
34 | #include <iprt/err.h>
|
---|
35 | #include <iprt/string.h>
|
---|
36 |
|
---|
37 |
|
---|
38 | RTCRestOutputBase::RTCRestOutputBase()
|
---|
39 | : m_uState(0)
|
---|
40 | {
|
---|
41 | }
|
---|
42 |
|
---|
43 |
|
---|
44 | RTCRestOutputBase::~RTCRestOutputBase()
|
---|
45 | {
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 | size_t RTCRestOutputBase::vprintf(const char *pszFormat, va_list va)
|
---|
50 | {
|
---|
51 | return RTStrFormatV(printfOutputCallback, this, NULL, NULL, pszFormat, va);
|
---|
52 | }
|
---|
53 |
|
---|
54 |
|
---|
55 | /*static*/ DECLCALLBACK(size_t) RTCRestOutputBase::printfOutputCallback(void *pvArg, const char *pachChars, size_t cbChars)
|
---|
56 | {
|
---|
57 | return ((RTCRestOutputBase *)pvArg)->output(pachChars, cbChars);
|
---|
58 | }
|
---|
59 |
|
---|
60 |
|
---|
61 | uint32_t RTCRestOutputBase::beginArray()
|
---|
62 | {
|
---|
63 | output(RT_STR_TUPLE("["));
|
---|
64 | uint32_t const uOldState = m_uState;
|
---|
65 | m_uState = (uOldState & 0xffff) + 1;
|
---|
66 | return uOldState;
|
---|
67 | }
|
---|
68 |
|
---|
69 |
|
---|
70 | void RTCRestOutputBase::endArray(uint32_t a_uOldState)
|
---|
71 | {
|
---|
72 | m_uState = a_uOldState;
|
---|
73 | output(RT_STR_TUPLE("]"));
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|
77 | uint32_t RTCRestOutputBase::beginObject()
|
---|
78 | {
|
---|
79 | output(RT_STR_TUPLE("{"));
|
---|
80 | uint32_t const uOldState = m_uState;
|
---|
81 | m_uState = (uOldState & 0xffff) + 1;
|
---|
82 | return uOldState;
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | void RTCRestOutputBase::endObject(uint32_t a_uOldState)
|
---|
87 | {
|
---|
88 | m_uState = a_uOldState;
|
---|
89 | output(RT_STR_TUPLE("}"));
|
---|
90 | }
|
---|
91 |
|
---|
92 |
|
---|
93 | void RTCRestOutputBase::valueSeparator()
|
---|
94 | {
|
---|
95 | if (m_uState & RT_BIT_32(31))
|
---|
96 | output(RT_STR_TUPLE(","));
|
---|
97 | else
|
---|
98 | m_uState |= RT_BIT_32(31);
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 | void RTCRestOutputBase::valueSeparatorAndName(const char *a_pszName, size_t a_cchName)
|
---|
103 | {
|
---|
104 | RT_NOREF(a_cchName);
|
---|
105 | if (m_uState & RT_BIT_32(31))
|
---|
106 | printf(",%RMjs:", a_pszName);
|
---|
107 | else
|
---|
108 | {
|
---|
109 | m_uState |= RT_BIT_32(31);
|
---|
110 | printf("%RMjs:", a_pszName);
|
---|
111 | }
|
---|
112 | }
|
---|
113 |
|
---|
114 |
|
---|
115 | void RTCRestOutputBase::nullValue()
|
---|
116 | {
|
---|
117 | output(RT_STR_TUPLE("null"));
|
---|
118 | }
|
---|
119 |
|
---|