[74414] | 1 | /* $Id: RTCRestOutputPrettyBase.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
| 3 | * IPRT - C++ REST, RTCRestOutputPrettyBase implementation.
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2018-2023 Oracle and/or its affiliates.
|
---|
[74414] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
[74414] | 11 | *
|
---|
[96407] | 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
[74414] | 25 | * The contents of this file may alternatively be used under the terms
|
---|
| 26 | * of the Common Development and Distribution License Version 1.0
|
---|
[96407] | 27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
| 28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
[74414] | 29 | * CDDL are applicable instead of those of the GPL.
|
---|
| 30 | *
|
---|
| 31 | * You may elect to license modified versions of this file under the
|
---|
| 32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
[96407] | 33 | *
|
---|
| 34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
[74414] | 35 | */
|
---|
| 36 |
|
---|
| 37 |
|
---|
| 38 | /*********************************************************************************************************************************
|
---|
| 39 | * Header Files *
|
---|
| 40 | *********************************************************************************************************************************/
|
---|
| 41 | #define LOG_GROUP RTLOGGROUP_REST
|
---|
| 42 | #include <iprt/cpp/restoutput.h>
|
---|
| 43 |
|
---|
[76452] | 44 | #include <iprt/errcore.h>
|
---|
[74414] | 45 | #include <iprt/string.h>
|
---|
| 46 |
|
---|
| 47 |
|
---|
[74425] | 48 | RTCRestOutputPrettyBase::RTCRestOutputPrettyBase() RT_NOEXCEPT
|
---|
[74414] | 49 | : RTCRestOutputBase()
|
---|
| 50 | {
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 | RTCRestOutputPrettyBase::~RTCRestOutputPrettyBase()
|
---|
| 55 | {
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 |
|
---|
[74425] | 59 | uint32_t RTCRestOutputPrettyBase::beginArray() RT_NOEXCEPT
|
---|
[74414] | 60 | {
|
---|
| 61 | output(RT_STR_TUPLE("["));
|
---|
| 62 | uint32_t const uOldState = m_uState;
|
---|
| 63 | m_uState = (uOldState & 0xffff) + 1;
|
---|
| 64 | return uOldState;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 |
|
---|
[74425] | 68 | void RTCRestOutputPrettyBase::endArray(uint32_t a_uOldState) RT_NOEXCEPT
|
---|
[74414] | 69 | {
|
---|
| 70 | m_uState = a_uOldState;
|
---|
| 71 | output(RT_STR_TUPLE("\n"));
|
---|
| 72 | outputIndentation();
|
---|
| 73 | output(RT_STR_TUPLE("]"));
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 |
|
---|
[74425] | 77 | uint32_t RTCRestOutputPrettyBase::beginObject() RT_NOEXCEPT
|
---|
[74414] | 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 |
|
---|
[74425] | 86 | void RTCRestOutputPrettyBase::endObject(uint32_t a_uOldState) RT_NOEXCEPT
|
---|
[74414] | 87 | {
|
---|
| 88 | m_uState = a_uOldState;
|
---|
| 89 | output(RT_STR_TUPLE("\n"));
|
---|
| 90 | outputIndentation();
|
---|
| 91 | output(RT_STR_TUPLE("}"));
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 |
|
---|
[74425] | 95 | void RTCRestOutputPrettyBase::valueSeparator() RT_NOEXCEPT
|
---|
[74414] | 96 | {
|
---|
| 97 | if (m_uState & RT_BIT_32(31))
|
---|
| 98 | output(RT_STR_TUPLE(",\n"));
|
---|
| 99 | else
|
---|
| 100 | {
|
---|
| 101 | m_uState |= RT_BIT_32(31);
|
---|
| 102 | output(RT_STR_TUPLE("\n"));
|
---|
| 103 | }
|
---|
| 104 | outputIndentation();
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 |
|
---|
[74425] | 108 | void RTCRestOutputPrettyBase::valueSeparatorAndName(const char *a_pszName, size_t a_cchName) RT_NOEXCEPT
|
---|
[74414] | 109 | {
|
---|
| 110 | RT_NOREF(a_cchName);
|
---|
| 111 | if (m_uState & RT_BIT_32(31))
|
---|
| 112 | output(RT_STR_TUPLE(",\n"));
|
---|
| 113 | else
|
---|
| 114 | {
|
---|
| 115 | m_uState |= RT_BIT_32(31);
|
---|
| 116 | output(RT_STR_TUPLE("\n"));
|
---|
| 117 | }
|
---|
| 118 | outputIndentation();
|
---|
| 119 | printf("%RMjs: ", a_pszName);
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 |
|
---|
[74425] | 123 | void RTCRestOutputPrettyBase::outputIndentation() RT_NOEXCEPT
|
---|
[74414] | 124 | {
|
---|
| 125 | static char const s_szSpaces[] = " ";
|
---|
| 126 | size_t cchIndent = (m_uState & 0xffff) << 1;
|
---|
| 127 | while (cchIndent > 0)
|
---|
| 128 | {
|
---|
| 129 | size_t cbToWrite = RT_MIN(cchIndent, sizeof(s_szSpaces) - 1);
|
---|
| 130 | output(s_szSpaces, cbToWrite);
|
---|
| 131 | cchIndent -= cbToWrite;
|
---|
| 132 | }
|
---|
| 133 | }
|
---|
| 134 |
|
---|