VirtualBox

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

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

IPRT/rest: Early support for polymorphic data objects in the data model. bugref:9167

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