VirtualBox

source: vbox/trunk/src/VBox/Runtime/common/rest/RTCRestOutputPrettyBase.cpp@ 76452

Last change on this file since 76452 was 76452, checked in by vboxsync, 6 years ago

IPRT: Ran scm --fix-err-h. bugref:9344

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1/* $Id: RTCRestOutputPrettyBase.cpp 76452 2018-12-25 01:41:25Z vboxsync $ */
2/** @file
3 * IPRT - C++ REST, RTCRestOutputPrettyBase 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/errcore.h>
35#include <iprt/string.h>
36
37
38RTCRestOutputPrettyBase::RTCRestOutputPrettyBase() RT_NOEXCEPT
39 : RTCRestOutputBase()
40{
41}
42
43
44RTCRestOutputPrettyBase::~RTCRestOutputPrettyBase()
45{
46}
47
48
49uint32_t RTCRestOutputPrettyBase::beginArray() RT_NOEXCEPT
50{
51 output(RT_STR_TUPLE("["));
52 uint32_t const uOldState = m_uState;
53 m_uState = (uOldState & 0xffff) + 1;
54 return uOldState;
55}
56
57
58void RTCRestOutputPrettyBase::endArray(uint32_t a_uOldState) RT_NOEXCEPT
59{
60 m_uState = a_uOldState;
61 output(RT_STR_TUPLE("\n"));
62 outputIndentation();
63 output(RT_STR_TUPLE("]"));
64}
65
66
67uint32_t RTCRestOutputPrettyBase::beginObject() RT_NOEXCEPT
68{
69 output(RT_STR_TUPLE("{"));
70 uint32_t const uOldState = m_uState;
71 m_uState = (uOldState & 0xffff) + 1;
72 return uOldState;
73}
74
75
76void RTCRestOutputPrettyBase::endObject(uint32_t a_uOldState) RT_NOEXCEPT
77{
78 m_uState = a_uOldState;
79 output(RT_STR_TUPLE("\n"));
80 outputIndentation();
81 output(RT_STR_TUPLE("}"));
82}
83
84
85void RTCRestOutputPrettyBase::valueSeparator() RT_NOEXCEPT
86{
87 if (m_uState & RT_BIT_32(31))
88 output(RT_STR_TUPLE(",\n"));
89 else
90 {
91 m_uState |= RT_BIT_32(31);
92 output(RT_STR_TUPLE("\n"));
93 }
94 outputIndentation();
95}
96
97
98void RTCRestOutputPrettyBase::valueSeparatorAndName(const char *a_pszName, size_t a_cchName) RT_NOEXCEPT
99{
100 RT_NOREF(a_cchName);
101 if (m_uState & RT_BIT_32(31))
102 output(RT_STR_TUPLE(",\n"));
103 else
104 {
105 m_uState |= RT_BIT_32(31);
106 output(RT_STR_TUPLE("\n"));
107 }
108 outputIndentation();
109 printf("%RMjs: ", a_pszName);
110}
111
112
113void RTCRestOutputPrettyBase::outputIndentation() RT_NOEXCEPT
114{
115 static char const s_szSpaces[] = " ";
116 size_t cchIndent = (m_uState & 0xffff) << 1;
117 while (cchIndent > 0)
118 {
119 size_t cbToWrite = RT_MIN(cchIndent, sizeof(s_szSpaces) - 1);
120 output(s_szSpaces, cbToWrite);
121 cchIndent -= cbToWrite;
122 }
123}
124
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