VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/rest/RTCRestOutputBase.cpp@ 84379

Last change on this file since 84379 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1/* $Id: RTCRestOutputBase.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * IPRT - C++ REST, RTCRestOutputBase implementation.
4 */
5
6/*
7 * Copyright (C) 2018-2020 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/errcore.h>
35#include <iprt/string.h>
36
37
38RTCRestOutputBase::RTCRestOutputBase() RT_NOEXCEPT
39 : m_uState(0)
40{
41}
42
43
44RTCRestOutputBase::~RTCRestOutputBase()
45{
46}
47
48
49size_t RTCRestOutputBase::vprintf(const char *pszFormat, va_list va) RT_NOEXCEPT
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) RT_NOEXCEPT
56{
57 return ((RTCRestOutputBase *)pvArg)->output(pachChars, cbChars);
58}
59
60
61uint32_t RTCRestOutputBase::beginArray() RT_NOEXCEPT
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
70void RTCRestOutputBase::endArray(uint32_t a_uOldState) RT_NOEXCEPT
71{
72 m_uState = a_uOldState;
73 output(RT_STR_TUPLE("]"));
74}
75
76
77uint32_t RTCRestOutputBase::beginObject() RT_NOEXCEPT
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
86void RTCRestOutputBase::endObject(uint32_t a_uOldState) RT_NOEXCEPT
87{
88 m_uState = a_uOldState;
89 output(RT_STR_TUPLE("}"));
90}
91
92
93void RTCRestOutputBase::valueSeparator() RT_NOEXCEPT
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
102void RTCRestOutputBase::valueSeparatorAndName(const char *a_pszName, size_t a_cchName) RT_NOEXCEPT
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
115void RTCRestOutputBase::nullValue() RT_NOEXCEPT
116{
117 output(RT_STR_TUPLE("null"));
118}
119
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette