VirtualBox

source: vbox/trunk/include/iprt/cpp/restanyobject.h@ 100442

Last change on this file since 100442 was 98103, checked in by vboxsync, 21 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.8 KB
Line 
1/** @file
2 * IPRT - C++ Representational State Transfer (REST) Any Object Class.
3 */
4
5/*
6 * Copyright (C) 2008-2023 Oracle and/or its affiliates.
7 *
8 * This file is part of VirtualBox base platform packages, as
9 * available from https://www.virtualbox.org.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation, in version 3 of the
14 * License.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, see <https://www.gnu.org/licenses>.
23 *
24 * The contents of this file may alternatively be used under the terms
25 * of the Common Development and Distribution License Version 1.0
26 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
27 * in the VirtualBox distribution, in which case the provisions of the
28 * CDDL are applicable instead of those of the GPL.
29 *
30 * You may elect to license modified versions of this file under the
31 * terms and conditions of either the GPL or the CDDL or both.
32 *
33 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
34 */
35
36#ifndef IPRT_INCLUDED_cpp_restanyobject_h
37#define IPRT_INCLUDED_cpp_restanyobject_h
38#ifndef RT_WITHOUT_PRAGMA_ONCE
39# pragma once
40#endif
41
42#include <iprt/cpp/restbase.h>
43#include <iprt/cpp/restarray.h>
44#include <iprt/cpp/reststringmap.h>
45
46
47/** @defgroup grp_rt_cpp_restanyobj C++ Representational State Transfer (REST) Any Object Class.
48 * @ingroup grp_rt_cpp
49 * @{
50 */
51
52/**
53 * Wrapper object that can represent any kind of basic REST object.
54 *
55 * This class is the result of a couple of design choices made in our REST
56 * data model. If could have been avoided if we used pointers all over
57 * the place and didn't rely entirely on the object specific implementations
58 * of deserializeFromJson and fromString to do the deserializing or everything.
59 *
60 * The assumption, though, was that most of the data we're dealing with has a
61 * known structure and maps to fixed types. So, the data model was optimized
62 * for that rather than flexiblity here.
63 */
64class RT_DECL_CLASS RTCRestAnyObject : public RTCRestObjectBase
65{
66public:
67 /** Default constructor. */
68 RTCRestAnyObject() RT_NOEXCEPT;
69 /** Destructor. */
70 virtual ~RTCRestAnyObject();
71
72 /** Copy constructor. */
73 RTCRestAnyObject(RTCRestAnyObject const &a_rThat);
74 /** Copy assignment operator. */
75 RTCRestAnyObject &operator=(RTCRestAnyObject const &a_rThat);
76
77 /** Safe copy assignment method. */
78 int assignCopy(RTCRestAnyObject const &a_rThat) RT_NOEXCEPT;
79 /** Safe copy assignment method, boolean variant. */
80 int assignCopy(RTCRestBool const &a_rThat) RT_NOEXCEPT;
81 /** Safe copy assignment method, int64_t variant. */
82 int assignCopy(RTCRestInt64 const &a_rThat) RT_NOEXCEPT;
83 /** Safe copy assignment method, int32_t variant. */
84 int assignCopy(RTCRestInt32 const &a_rThat) RT_NOEXCEPT;
85 /** Safe copy assignment method, int16_t variant. */
86 int assignCopy(RTCRestInt16 const &a_rThat) RT_NOEXCEPT;
87 /** Safe copy assignment method, double variant. */
88 int assignCopy(RTCRestDouble const &a_rThat) RT_NOEXCEPT;
89 /** Safe copy assignment method, string variant. */
90 int assignCopy(RTCRestString const &a_rThat) RT_NOEXCEPT;
91 /** Safe copy assignment method, array variant. */
92 int assignCopy(RTCRestArray<RTCRestAnyObject> const &a_rThat) RT_NOEXCEPT;
93 /** Safe copy assignment method, string map variant. */
94 int assignCopy(RTCRestStringMap<RTCRestAnyObject> const &a_rThat) RT_NOEXCEPT;
95
96 /** Safe value assignment method, boolean variant. */
97 int assignValue(bool a_fValue) RT_NOEXCEPT;
98 /** Safe value assignment method, int64_t variant. */
99 int assignValue(int64_t a_iValue) RT_NOEXCEPT;
100 /** Safe value assignment method, int32_t variant. */
101 int assignValue(int32_t a_iValue) RT_NOEXCEPT;
102 /** Safe value assignment method, int16_t variant. */
103 int assignValue(int16_t a_iValue) RT_NOEXCEPT;
104 /** Safe value assignment method, double variant. */
105 int assignValue(double a_iValue) RT_NOEXCEPT;
106 /** Safe value assignment method, string variant. */
107 int assignValue(RTCString const &a_rValue) RT_NOEXCEPT;
108 /** Safe value assignment method, C-string variant. */
109 int assignValue(const char *a_pszValue) RT_NOEXCEPT;
110
111 /** Make a clone of this object. */
112 inline RTCRestAnyObject *clone() const RT_NOEXCEPT { return (RTCRestAnyObject *)baseClone(); }
113
114 /* Overridden methods: */
115 virtual RTCRestObjectBase *baseClone() const RT_NOEXCEPT RT_OVERRIDE;
116 virtual int setNull(void) RT_NOEXCEPT RT_OVERRIDE;
117 virtual int resetToDefault() RT_NOEXCEPT RT_OVERRIDE;
118 virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_NOEXCEPT RT_OVERRIDE;
119 virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_NOEXCEPT RT_OVERRIDE;
120 virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = kCollectionFormat_Unspecified) const RT_NOEXCEPT RT_OVERRIDE;
121 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL,
122 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_NOEXCEPT RT_OVERRIDE;
123 virtual kTypeClass typeClass(void) const RT_NOEXCEPT RT_OVERRIDE;
124 virtual const char *typeName(void) const RT_NOEXCEPT RT_OVERRIDE;
125
126 /** Factory method. */
127 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void) RT_NOEXCEPT;
128 /** Deserialization w/ instantiation. */
129 static FNDESERIALIZEINSTANCEFROMJSON deserializeInstanceFromJson;
130
131protected:
132 /** The data. */
133 RTCRestObjectBase *m_pData;
134};
135
136/** @} */
137
138#endif /* !IPRT_INCLUDED_cpp_restanyobject_h */
139
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