VirtualBox

source: vbox/trunk/include/iprt/cpp/restbase.h@ 74937

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

IPRT/rest: Missed RT_NOEXCEPT in two place. Went wild adding RT_NOEXCEPT everywhere possible. bugref:9167

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 43.2 KB
Line 
1/** @file
2 * IPRT - C++ Representational State Transfer (REST) Base Classes.
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_restbase_h
27#define ___iprt_cpp_restbase_h
28
29#include <iprt/cdefs.h>
30#include <iprt/types.h>
31#include <iprt/json.h>
32#include <iprt/stdarg.h>
33#include <iprt/time.h>
34#include <iprt/cpp/ministring.h>
35
36
37/** @defgroup grp_rt_cpp_restbase C++ Representational State Transfer (REST) Base Classes.
38 * @ingroup grp_rt_cpp
39 * @{
40 */
41
42/* forward decl: */
43class RTCRestOutputBase;
44class RTCRestJsonPrimaryCursor;
45
46/**
47 * JSON cursor structure.
48 *
49 * This reduces the number of parameters passed around when deserializing JSON
50 * input and also helps constructing full object name for logging and error reporting.
51 */
52struct RT_DECL_CLASS RTCRestJsonCursor
53{
54 /** Handle to the value being parsed. */
55 RTJSONVAL m_hValue;
56 /** Name of the value. */
57 const char *m_pszName;
58 /** Pointer to the parent, NULL if primary. */
59 struct RTCRestJsonCursor const *m_pParent;
60 /** Pointer to the primary cursor structure. */
61 RTCRestJsonPrimaryCursor *m_pPrimary;
62
63 RTCRestJsonCursor(struct RTCRestJsonCursor const &a_rParent) RT_NOEXCEPT
64 : m_hValue(NIL_RTJSONVAL), m_pszName(NULL), m_pParent(&a_rParent), m_pPrimary(a_rParent.m_pPrimary)
65 { }
66
67 RTCRestJsonCursor(RTJSONVAL hValue, const char *pszName, struct RTCRestJsonCursor *pParent) RT_NOEXCEPT
68 : m_hValue(hValue), m_pszName(pszName), m_pParent(pParent), m_pPrimary(pParent->m_pPrimary)
69 { }
70
71 RTCRestJsonCursor(RTJSONVAL hValue, const char *pszName) RT_NOEXCEPT
72 : m_hValue(hValue), m_pszName(pszName), m_pParent(NULL), m_pPrimary(NULL)
73 { }
74
75 ~RTCRestJsonCursor()
76 {
77 if (m_hValue != NIL_RTJSONVAL)
78 {
79 RTJsonValueRelease(m_hValue);
80 m_hValue = NIL_RTJSONVAL;
81 }
82 }
83};
84
85
86/**
87 * The primary JSON cursor class.
88 */
89class RT_DECL_CLASS RTCRestJsonPrimaryCursor
90{
91public:
92 /** The cursor for the first level. */
93 RTCRestJsonCursor m_Cursor;
94 /** Error info keeper. */
95 PRTERRINFO m_pErrInfo;
96
97 /** Creates a primary json cursor with optiona error info. */
98 RTCRestJsonPrimaryCursor(RTJSONVAL hValue, const char *pszName, PRTERRINFO pErrInfo = NULL) RT_NOEXCEPT
99 : m_Cursor(hValue, pszName)
100 , m_pErrInfo(pErrInfo)
101 {
102 m_Cursor.m_pPrimary = this;
103 }
104
105 virtual ~RTCRestJsonPrimaryCursor()
106 { }
107
108 /**
109 * Add an error message.
110 *
111 * @returns a_rc
112 * @param a_rCursor The cursor reporting the error.
113 * @param a_rc The status code.
114 * @param a_pszFormat Format string.
115 * @param ... Format string arguments.
116 */
117 virtual int addError(RTCRestJsonCursor const &a_rCursor, int a_rc, const char *a_pszFormat, ...) RT_NOEXCEPT;
118
119 /**
120 * Reports that the current field is not known.
121 *
122 * @returns Status to propagate.
123 * @param a_rCursor The cursor for the field.
124 */
125 virtual int unknownField(RTCRestJsonCursor const &a_rCursor) RT_NOEXCEPT;
126
127 /**
128 * Copies the full path into pszDst.
129 *
130 * @returns pszDst
131 * @param a_rCursor The cursor to start walking at.
132 * @param a_pszDst Where to put the path.
133 * @param a_cbDst Size of the destination buffer.
134 */
135 virtual char *getPath(RTCRestJsonCursor const &a_rCursor, char *a_pszDst, size_t a_cbDst) const RT_NOEXCEPT;
136};
137
138
139/**
140 * Abstract base class for REST primitive types and data objects (via
141 * RTCRestDataObject).
142 *
143 * The only information this keeps is the null indicator.
144 */
145class RT_DECL_CLASS RTCRestObjectBase
146{
147public:
148 RTCRestObjectBase() RT_NOEXCEPT;
149 RTCRestObjectBase(RTCRestObjectBase const &a_rThat) RT_NOEXCEPT;
150 virtual ~RTCRestObjectBase();
151
152 /**
153 * Create a copy of this object.
154 *
155 * @returns Pointer to copy.
156 */
157 virtual RTCRestObjectBase *baseClone() const RT_NOEXCEPT = 0;
158
159 /**
160 * Tests if the object is @a null.
161 * @returns true if null, false if not.
162 */
163 inline bool isNull(void) const RT_NOEXCEPT { return m_fNullIndicator; };
164
165 /**
166 * Sets the object to @a null and fills it with defaults.
167 * @returns IPRT status code (from resetToDefault).
168 */
169 virtual int setNull(void) RT_NOEXCEPT;
170
171 /**
172 * Sets the object to not-null state (i.e. undoes setNull()).
173 * @remarks Only really important for strings.
174 */
175 virtual void setNotNull(void) RT_NOEXCEPT;
176
177 /**
178 * Resets the object to all default values.
179 * @returns IPRT status code.
180 */
181 virtual int resetToDefault() RT_NOEXCEPT = 0;
182
183 /**
184 * Serialize the object as JSON.
185 *
186 * @returns a_rDst
187 * @param a_rDst The destination for the serialization.
188 */
189 virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_NOEXCEPT = 0;
190
191 /**
192 * Deserialize object from the given JSON iterator.
193 *
194 * @returns IPRT status code.
195 * @param a_rCursor The JSON cursor.
196 */
197 virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_NOEXCEPT = 0;
198
199 /**
200 * Polymorphic JSON deserialization helper that instantiate the matching class using
201 * the discriminator field.
202 *
203 * @returns IPRT status code.
204 * @param a_rCursor The JSON cursor.
205 * @param a_ppInstance Where to return the deserialized instance.
206 * May return an object on failure.
207 */
208 typedef DECLCALLBACK(int) FNDESERIALIZEINSTANCEFROMJSON(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance);
209 /** Pointer to a FNDESERIALIZEINSTANCEFROMJSON function. */
210 typedef FNDESERIALIZEINSTANCEFROMJSON *PFNDESERIALIZEINSTANCEFROMJSON;
211
212 /**
213 * Flags for toString().
214 *
215 * The kCollectionFormat_xxx bunch controls multiple values in arrays
216 * are formatted. They are ignored by everyone else.
217 *
218 * @note When adding collection format types, make sure to also
219 * update RTCRestArrayBase::toString().
220 * @note Bit 24 is reserved (for kHdrField_MapCollection).
221 */
222 enum
223 {
224 kCollectionFormat_Unspecified = 0, /**< Not specified. */
225 kCollectionFormat_csv, /**< Comma-separated list. */
226 kCollectionFormat_ssv, /**< Space-separated list. */
227 kCollectionFormat_tsv, /**< Tab-separated list. */
228 kCollectionFormat_pipes, /**< Pipe-separated list. */
229 kCollectionFormat_multi, /**< Special collection type that must be handled by caller of toString. */
230 kCollectionFormat_Mask = 7, /**< Collection type mask. */
231
232 kToString_Append = 8 /**< Append to the string/object (rather than assigning). */
233 };
234
235 /**
236 * String conversion.
237 *
238 * The default implementation of is a wrapper around serializeAsJson().
239 *
240 * @returns IPRT status code.
241 * @param a_pDst Pointer to the destionation string.
242 * @param a_fFlags kCollectionFormat_xxx.
243 */
244 virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = kCollectionFormat_Unspecified) const RT_NOEXCEPT;
245
246 /**
247 * String convertsion, naive variant.
248 *
249 * @returns String represenation.
250 */
251 RTCString toString() const;
252
253 /**
254 * Convert from (header) string value.
255 *
256 * The default implementation of is a wrapper around deserializeFromJson().
257 *
258 * @returns IPRT status code.
259 * @param a_rValue The string value string to parse.
260 * @param a_pszName Field name or similar.
261 * @param a_pErrInfo Where to return additional error info. Optional.
262 * @param a_fFlags kCollectionFormat_xxx.
263 */
264 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL,
265 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_NOEXCEPT;
266
267 /** Type classification */
268 typedef enum kTypeClass
269 {
270 kTypeClass_Invalid = 0,
271 kTypeClass_Bool, /**< Primitive: bool. */
272 kTypeClass_Int64, /**< Primitive: int64_t. */
273 kTypeClass_Int32, /**< Primitive: int32_t. */
274 kTypeClass_Int16, /**< Primitive: int16_t. */
275 kTypeClass_Double, /**< Primitive: double. */
276 kTypeClass_String, /**< Primitive: string. */
277 kTypeClass_Date, /**< Date. */
278 kTypeClass_Uuid, /**< UUID. */
279 kTypeClass_Binary, /**< Binary blob. */
280 kTypeClass_DataObject, /**< Data object child (RTCRestDataObject). */
281 kTypeClass_AnyObject, /**< Any kind of object (RTCRestAnyObject). */
282 kTypeClass_Array, /**< Array (containing any kind of object). */
283 kTypeClass_StringMap, /**< String map (containing any kind of object). */
284 kTypeClass_StringEnum /**< String enum. */
285 } kTypeClass;
286
287 /**
288 * Returns the object type class.
289 */
290 virtual kTypeClass typeClass(void) const RT_NOEXCEPT = 0;
291
292 /**
293 * Returns the object type name.
294 */
295 virtual const char *typeName(void) const RT_NOEXCEPT = 0;
296
297protected:
298 /** Null indicator.
299 * @remarks The null values could be mapped onto C/C++ NULL pointer values,
300 * with the consequence that all data members in objects and such would
301 * have had to been allocated individually, even simple @a bool members.
302 * Given that we're overly paranoid about heap allocations (std::bad_alloc),
303 * it's more fitting to use a null indicator for us.
304 */
305 bool m_fNullIndicator;
306};
307
308
309/**
310 * Class wrapping 'bool'.
311 */
312class RT_DECL_CLASS RTCRestBool : public RTCRestObjectBase
313{
314public:
315 /** Default constructor. */
316 RTCRestBool() RT_NOEXCEPT;
317 /** Copy constructor. */
318 RTCRestBool(RTCRestBool const &a_rThat) RT_NOEXCEPT;
319 /** From value constructor. */
320 RTCRestBool(bool fValue) RT_NOEXCEPT;
321 /** Destructor. */
322 virtual ~RTCRestBool();
323 /** Copy assignment operator. */
324 RTCRestBool &operator=(RTCRestBool const &a_rThat) RT_NOEXCEPT;
325 /** Safe copy assignment method. */
326 int assignCopy(RTCRestBool const &a_rThat) RT_NOEXCEPT;
327 /** Assign value and clear null indicator. */
328 void assignValue(bool a_fValue) RT_NOEXCEPT;
329 /** Make a clone of this object. */
330 inline RTCRestBool *clone() const RT_NOEXCEPT { return (RTCRestBool *)baseClone(); }
331
332 /* Overridden methods: */
333 virtual RTCRestObjectBase *baseClone() const RT_NOEXCEPT RT_OVERRIDE;
334 virtual int resetToDefault() RT_NOEXCEPT RT_OVERRIDE;
335 virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_NOEXCEPT RT_OVERRIDE;
336 virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_NOEXCEPT RT_OVERRIDE;
337 virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = 0) const RT_NOEXCEPT RT_OVERRIDE;
338 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL,
339 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_NOEXCEPT RT_OVERRIDE;
340 virtual kTypeClass typeClass(void) const RT_NOEXCEPT RT_OVERRIDE;
341 virtual const char *typeName(void) const RT_NOEXCEPT RT_OVERRIDE;
342
343 /** Factory method. */
344 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void) RT_NOEXCEPT;
345 /** @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON */
346 static DECLCALLBACK(int) deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) RT_NOEXCEPT;
347
348public:
349 /** The value. */
350 bool m_fValue;
351};
352
353
354/**
355 * Class wrapping 'int64_t'.
356 */
357class RT_DECL_CLASS RTCRestInt64 : public RTCRestObjectBase
358{
359public:
360 /** Default constructor. */
361 RTCRestInt64() RT_NOEXCEPT;
362 /** Copy constructor. */
363 RTCRestInt64(RTCRestInt64 const &a_rThat) RT_NOEXCEPT;
364 /** From value constructor. */
365 RTCRestInt64(int64_t a_iValue) RT_NOEXCEPT;
366 /** Destructor. */
367 virtual ~RTCRestInt64();
368 /** Copy assignment operator. */
369 RTCRestInt64 &operator=(RTCRestInt64 const &a_rThat) RT_NOEXCEPT;
370 /** Safe copy assignment method. */
371 int assignCopy(RTCRestInt64 const &a_rThat) RT_NOEXCEPT;
372 /** Assign value and clear null indicator. */
373 void assignValue(int64_t a_iValue) RT_NOEXCEPT;
374 /** Make a clone of this object. */
375 inline RTCRestInt64 *clone() const RT_NOEXCEPT { return (RTCRestInt64 *)baseClone(); }
376
377 /* Overridden methods: */
378 virtual RTCRestObjectBase *baseClone() const RT_NOEXCEPT RT_OVERRIDE;
379 virtual int resetToDefault() RT_NOEXCEPT RT_OVERRIDE;
380 virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_NOEXCEPT RT_OVERRIDE;
381 virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_NOEXCEPT RT_OVERRIDE;
382 virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = 0) const RT_NOEXCEPT RT_OVERRIDE;
383 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL,
384 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_NOEXCEPT RT_OVERRIDE;
385 virtual kTypeClass typeClass(void) const RT_NOEXCEPT RT_OVERRIDE;
386 virtual const char *typeName(void) const RT_NOEXCEPT RT_OVERRIDE;
387
388 /** Factory method. */
389 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void) RT_NOEXCEPT;
390 /** @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON */
391 static DECLCALLBACK(int) deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) RT_NOEXCEPT;
392
393public:
394 /** The value. */
395 int64_t m_iValue;
396};
397
398
399/**
400 * Class wrapping 'int32_t'.
401 */
402class RT_DECL_CLASS RTCRestInt32 : public RTCRestObjectBase
403{
404public:
405 /** Default constructor. */
406 RTCRestInt32() RT_NOEXCEPT;
407 /** Copy constructor. */
408 RTCRestInt32(RTCRestInt32 const &a_rThat) RT_NOEXCEPT;
409 /** From value constructor. */
410 RTCRestInt32(int32_t iValue) RT_NOEXCEPT;
411 /** Destructor. */
412 virtual ~RTCRestInt32() RT_NOEXCEPT;
413 /** Copy assignment operator. */
414 RTCRestInt32 &operator=(RTCRestInt32 const &a_rThat) RT_NOEXCEPT;
415 /** Safe copy assignment method. */
416 int assignCopy(RTCRestInt32 const &a_rThat) RT_NOEXCEPT;
417 /** Assign value and clear null indicator. */
418 void assignValue(int32_t a_iValue) RT_NOEXCEPT;
419 /** Make a clone of this object. */
420 inline RTCRestInt32 *clone() const { return (RTCRestInt32 *)baseClone(); }
421
422 /* Overridden methods: */
423 virtual RTCRestObjectBase *baseClone() const RT_NOEXCEPT RT_OVERRIDE;
424 virtual int resetToDefault() RT_NOEXCEPT RT_OVERRIDE;
425 virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_NOEXCEPT RT_OVERRIDE;
426 virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_NOEXCEPT RT_OVERRIDE;
427 virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = 0) const RT_NOEXCEPT RT_OVERRIDE;
428 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL,
429 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_NOEXCEPT RT_OVERRIDE;
430 virtual kTypeClass typeClass(void) const RT_NOEXCEPT RT_OVERRIDE;
431 virtual const char *typeName(void) const RT_NOEXCEPT RT_OVERRIDE;
432
433 /** Factory method. */
434 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void) RT_NOEXCEPT;
435 /** @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON */
436 static DECLCALLBACK(int) deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) RT_NOEXCEPT;
437
438public:
439 /** The value. */
440 int32_t m_iValue;
441};
442
443
444/**
445 * Class wrapping 'int16_t'.
446 */
447class RT_DECL_CLASS RTCRestInt16 : public RTCRestObjectBase
448{
449public:
450 /** Default constructor. */
451 RTCRestInt16() RT_NOEXCEPT;
452 /** Copy constructor. */
453 RTCRestInt16(RTCRestInt16 const &a_rThat) RT_NOEXCEPT;
454 /** From value constructor. */
455 RTCRestInt16(int16_t iValue) RT_NOEXCEPT;
456 /** Destructor. */
457 virtual ~RTCRestInt16();
458 /** Copy assignment operator. */
459 RTCRestInt16 &operator=(RTCRestInt16 const &a_rThat) RT_NOEXCEPT;
460 /** Safe copy assignment method. */
461 int assignCopy(RTCRestInt16 const &a_rThat) RT_NOEXCEPT;
462 /** Assign value and clear null indicator. */
463 void assignValue(int16_t a_iValue) RT_NOEXCEPT;
464 /** Make a clone of this object. */
465 inline RTCRestInt16 *clone() const RT_NOEXCEPT { return (RTCRestInt16 *)baseClone(); }
466
467 /* Overridden methods: */
468 virtual RTCRestObjectBase *baseClone() const RT_NOEXCEPT RT_OVERRIDE;
469 virtual int resetToDefault() RT_NOEXCEPT RT_OVERRIDE;
470 virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_NOEXCEPT RT_OVERRIDE;
471 virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_NOEXCEPT RT_OVERRIDE;
472 virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = 0) const RT_NOEXCEPT RT_OVERRIDE;
473 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL,
474 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_NOEXCEPT RT_OVERRIDE;
475 virtual kTypeClass typeClass(void) const RT_NOEXCEPT RT_OVERRIDE;
476 virtual const char *typeName(void) const RT_NOEXCEPT RT_OVERRIDE;
477
478 /** Factory method. */
479 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void) RT_NOEXCEPT;
480 /** @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON */
481 static DECLCALLBACK(int) deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) RT_NOEXCEPT;
482
483public:
484 /** The value. */
485 int16_t m_iValue;
486};
487
488
489/**
490 * Class wrapping 'double'.
491 */
492class RT_DECL_CLASS RTCRestDouble : public RTCRestObjectBase
493{
494public:
495 /** Default constructor. */
496 RTCRestDouble() RT_NOEXCEPT;
497 /** Copy constructor. */
498 RTCRestDouble(RTCRestDouble const &a_rThat) RT_NOEXCEPT;
499 /** From value constructor. */
500 RTCRestDouble(double rdValue) RT_NOEXCEPT;
501 /** Destructor. */
502 virtual ~RTCRestDouble();
503 /** Copy assignment operator. */
504 RTCRestDouble &operator=(RTCRestDouble const &a_rThat) RT_NOEXCEPT;
505 /** Safe copy assignment method. */
506 int assignCopy(RTCRestDouble const &a_rThat) RT_NOEXCEPT;
507 /** Assign value and clear null indicator. */
508 void assignValue(double a_rdValue) RT_NOEXCEPT;
509 /** Make a clone of this object. */
510 inline RTCRestDouble *clone() const RT_NOEXCEPT { return (RTCRestDouble *)baseClone(); }
511
512 /* Overridden methods: */
513 virtual RTCRestObjectBase *baseClone() const RT_NOEXCEPT RT_OVERRIDE;
514 virtual int resetToDefault() RT_NOEXCEPT RT_OVERRIDE;
515 virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_NOEXCEPT RT_OVERRIDE;
516 virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_NOEXCEPT RT_OVERRIDE;
517 virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = 0) const RT_NOEXCEPT RT_OVERRIDE;
518 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL,
519 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_NOEXCEPT RT_OVERRIDE;
520 virtual kTypeClass typeClass(void) const RT_NOEXCEPT RT_OVERRIDE;
521 virtual const char *typeName(void) const RT_NOEXCEPT RT_OVERRIDE;
522
523 /** Factory method. */
524 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void) RT_NOEXCEPT;
525 /** @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON */
526 static DECLCALLBACK(int) deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) RT_NOEXCEPT;
527
528public:
529 /** The value. */
530 double m_rdValue;
531};
532
533
534/**
535 * Class wrapping 'RTCString'.
536 */
537class RT_DECL_CLASS RTCRestString : public RTCRestObjectBase, public RTCString
538{
539public:
540 /** Default constructor. */
541 RTCRestString() RT_NOEXCEPT;
542 /** Destructor. */
543 virtual ~RTCRestString();
544
545 /** Copy constructor. */
546 RTCRestString(RTCRestString const &a_rThat);
547 /** From value constructor. */
548 RTCRestString(RTCString const &a_rThat);
549 /** From value constructor. */
550 RTCRestString(const char *a_pszSrc);
551 /** Safe copy assignment method. */
552 int assignCopy(RTCRestString const &a_rThat) RT_NOEXCEPT;
553 /** Safe copy assignment method. */
554 int assignCopy(RTCString const &a_rThat) RT_NOEXCEPT;
555 /** Safe copy assignment method. */
556 int assignCopy(const char *a_pszThat) RT_NOEXCEPT;
557 /** Make a clone of this object. */
558 inline RTCRestString *clone() const RT_NOEXCEPT { return (RTCRestString *)baseClone(); }
559
560 /* Overridden methods: */
561 virtual RTCRestObjectBase *baseClone() const RT_NOEXCEPT RT_OVERRIDE;
562 virtual int setNull(void) RT_NOEXCEPT RT_OVERRIDE; /* (ambigious, so overrider it to make sure.) */
563 virtual int resetToDefault() RT_NOEXCEPT RT_OVERRIDE;
564 virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_NOEXCEPT RT_OVERRIDE;
565 virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_NOEXCEPT RT_OVERRIDE;
566 virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = kCollectionFormat_Unspecified) const RT_NOEXCEPT RT_OVERRIDE;
567 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL,
568 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_NOEXCEPT RT_OVERRIDE;
569 virtual kTypeClass typeClass(void) const RT_NOEXCEPT RT_OVERRIDE;
570 virtual const char *typeName(void) const RT_NOEXCEPT RT_OVERRIDE;
571
572 /** Factory method. */
573 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void) RT_NOEXCEPT;
574 /** @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON */
575 static DECLCALLBACK(int) deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) RT_NOEXCEPT;
576
577 /** @name RTCString assignment methods we need to replace to manage the null indicator
578 * @{ */
579 int assignNoThrow(const RTCString &a_rSrc) RT_NOEXCEPT;
580 int assignNoThrow(const char *a_pszSrc) RT_NOEXCEPT;
581 int assignNoThrow(const RTCString &a_rSrc, size_t a_offSrc, size_t a_cchSrc = npos) RT_NOEXCEPT;
582 int assignNoThrow(const char *a_pszSrc, size_t a_cchSrc) RT_NOEXCEPT;
583 int assignNoThrow(size_t a_cTimes, char a_ch) RT_NOEXCEPT;
584 int printfNoThrow(const char *pszFormat, ...) RT_NOEXCEPT RT_IPRT_FORMAT_ATTR(1, 2);
585 int printfVNoThrow(const char *pszFormat, va_list va) RT_NOEXCEPT RT_IPRT_FORMAT_ATTR(1, 0);
586 RTCRestString &operator=(const char *a_pcsz);
587 RTCRestString &operator=(const RTCString &a_rThat);
588 RTCRestString &operator=(const RTCRestString &a_rThat);
589 RTCRestString &assign(const RTCString &a_rSrc);
590 RTCRestString &assign(const char *a_pszSrc);
591 RTCRestString &assign(const RTCString &a_rSrc, size_t a_offSrc, size_t a_cchSrc = npos);
592 RTCRestString &assign(const char *a_pszSrc, size_t a_cchSrc);
593 RTCRestString &assign(size_t a_cTimes, char a_ch);
594 RTCRestString &printf(const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
595 RTCRestString &printfV(const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(1, 0);
596 /** @} */
597};
598
599
600/**
601 * Date class.
602 *
603 * There are numerous ways of formatting a timestamp and the specifications
604 * we're currently working with doesn't have a way of telling it seems.
605 * Thus, decoding need to have fail safes built in so the user can give hints.
606 * The formatting likewise needs to be told which format to use by the user.
607 *
608 * Two side-effects of the format stuff is that the default constructor creates
609 * an object that is null, and resetToDefault will do the same bug leave the
610 * format as a hint.
611 */
612class RT_DECL_CLASS RTCRestDate : public RTCRestObjectBase
613{
614public:
615 /** Default constructor.
616 * @note The result is a null-object. */
617 RTCRestDate() RT_NOEXCEPT;
618 /** Copy constructor. */
619 RTCRestDate(RTCRestDate const &a_rThat);
620 /** Destructor. */
621 virtual ~RTCRestDate();
622 /** Copy assignment operator. */
623 RTCRestDate &operator=(RTCRestDate const &a_rThat);
624 /** Safe copy assignment method. */
625 int assignCopy(RTCRestDate const &a_rThat) RT_NOEXCEPT;
626 /** Make a clone of this object. */
627 inline RTCRestDate *clone() const RT_NOEXCEPT{ return (RTCRestDate *)baseClone(); }
628
629 /* Overridden methods: */
630 virtual RTCRestObjectBase *baseClone() const RT_NOEXCEPT RT_OVERRIDE;
631 virtual int resetToDefault() RT_NOEXCEPT RT_OVERRIDE;
632 virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_NOEXCEPT RT_OVERRIDE;
633 virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_NOEXCEPT RT_OVERRIDE;
634 virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = 0) const RT_NOEXCEPT RT_OVERRIDE;
635 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL,
636 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_NOEXCEPT RT_OVERRIDE;
637 virtual kTypeClass typeClass(void) const RT_NOEXCEPT RT_OVERRIDE;
638 virtual const char *typeName(void) const RT_NOEXCEPT RT_OVERRIDE;
639
640 /** Factory method. */
641 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void) RT_NOEXCEPT;
642 /** @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON */
643 static DECLCALLBACK(int) deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) RT_NOEXCEPT;
644
645 /** Date formats. */
646 typedef enum
647 {
648 kFormat_Invalid = 0,
649 kFormat_Rfc2822, /**< Format it according to RFC-2822. */
650 kFormat_Rfc7131, /**< Format it according to RFC-7131 (HTTP). */
651 kFormat_Rfc3339, /**< Format it according to RFC-3339 (ISO-8601) (no fraction). */
652 kFormat_Rfc3339_Fraction_2, /**< Format it according to RFC-3339 (ISO-8601) with two digit fraction (hundreths). */
653 kFormat_Rfc3339_Fraction_3, /**< Format it according to RFC-3339 (ISO-8601) with three digit fraction (milliseconds). */
654 kFormat_Rfc3339_Fraction_6, /**< Format it according to RFC-3339 (ISO-8601) with six digit fraction (microseconds). */
655 kFormat_Rfc3339_Fraction_9, /**< Format it according to RFC-3339 (ISO-8601) with nine digit fraction (nanoseconds). */
656 kFormat_End
657 } kFormat;
658
659 /**
660 * Assigns the value, formats it as a string and clears the null indicator.
661 *
662 * @returns VINF_SUCCESS, VERR_NO_STR_MEMORY or VERR_INVALID_PARAMETER.
663 * @param a_pTimeSpec The time spec to set.
664 * @param a_enmFormat The date format to use when formatting it.
665 */
666 int assignValue(PCRTTIMESPEC a_pTimeSpec, kFormat a_enmFormat) RT_NOEXCEPT;
667 int assignValueRfc2822(PCRTTIMESPEC a_pTimeSpec) RT_NOEXCEPT; /**< Convenience method for email/whatnot. */
668 int assignValueRfc7131(PCRTTIMESPEC a_pTimeSpec) RT_NOEXCEPT; /**< Convenience method for HTTP date. */
669 int assignValueRfc3339(PCRTTIMESPEC a_pTimeSpec) RT_NOEXCEPT; /**< Convenience method for ISO-8601 timstamp. */
670
671 /**
672 * Assigns the current UTC time and clears the null indicator .
673 *
674 * @returns VINF_SUCCESS, VERR_NO_STR_MEMORY or VERR_INVALID_PARAMETER.
675 * @returns VINF_SUCCESS or VERR_NO_STR_MEMORY.
676 * @param a_enmFormat The date format to use when formatting it.
677 */
678 int assignNow(kFormat a_enmFormat) RT_NOEXCEPT;
679 int assignNowRfc2822() RT_NOEXCEPT; /**< Convenience method for email/whatnot. */
680 int assignNowRfc7131() RT_NOEXCEPT; /**< Convenience method for HTTP date. */
681 int assignNowRfc3339() RT_NOEXCEPT; /**< Convenience method for ISO-8601 timstamp. */
682
683 /**
684 * Sets the format to help deal with decoding issues.
685 *
686 * This can also be used to change the date format for an okay timespec.
687 * @returns IPRT status code.
688 * @param a_enmFormat The date format to try/set.
689 */
690 int setFormat(kFormat a_enmFormat) RT_NOEXCEPT;
691
692 /** Check if the value is okay (m_TimeSpec & m_Exploded). */
693 inline bool isOkay() const RT_NOEXCEPT { return m_fTimeSpecOkay; }
694 /** Get the timespec value. */
695 inline RTTIMESPEC const &getTimeSpec() const RT_NOEXCEPT { return m_TimeSpec; }
696 /** Get the exploded time. */
697 inline RTTIME const &getExploded() const RT_NOEXCEPT { return m_Exploded; }
698 /** Gets the format. */
699 inline kFormat getFormat() const RT_NOEXCEPT { return m_enmFormat; }
700 /** Get the formatted/raw string value. */
701 inline RTCString const &getString() const RT_NOEXCEPT { return m_strFormatted; }
702
703 /** Get nanoseconds since unix epoch. */
704 inline int64_t getEpochNano() const RT_NOEXCEPT { return RTTimeSpecGetNano(&m_TimeSpec); }
705 /** Get seconds since unix epoch. */
706 inline int64_t getEpochSeconds() const RT_NOEXCEPT { return RTTimeSpecGetSeconds(&m_TimeSpec); }
707 /** Checks if UTC time. */
708 inline bool isUtc() const RT_NOEXCEPT { return (m_Exploded.fFlags & RTTIME_FLAGS_TYPE_MASK) != RTTIME_FLAGS_TYPE_LOCAL; }
709 /** Checks if local time. */
710 inline bool isLocal() const RT_NOEXCEPT { return (m_Exploded.fFlags & RTTIME_FLAGS_TYPE_MASK) == RTTIME_FLAGS_TYPE_LOCAL; }
711
712protected:
713 /** The value. */
714 RTTIMESPEC m_TimeSpec;
715 /** The exploded time value. */
716 RTTIME m_Exploded;
717 /** Set if m_TimeSpec is okay, consult m_strFormatted if not. */
718 bool m_fTimeSpecOkay;
719 /** The format / format hint. */
720 kFormat m_enmFormat;
721 /** The formatted date string.
722 * This will be the raw input string for a deserialized value, where as for
723 * a value set by the user it will be the formatted value. */
724 RTCString m_strFormatted;
725
726 /**
727 * Explodes and formats the m_TimeSpec value.
728 *
729 * Sets m_Exploded, m_strFormatted, m_fTimeSpecOkay, and m_enmFormat, clears m_fNullIndicator.
730 *
731 * @returns VINF_SUCCESS or VERR_NO_STR_MEMORY.
732 * @param a_enmFormat The format to use.
733 */
734 int explodeAndFormat(kFormat a_enmFormat) RT_NOEXCEPT;
735
736 /**
737 * Formats the m_Exploded value.
738 *
739 * Sets m_strFormatted, m_fTimeSpecOkay, and m_enmFormat, clears m_fNullIndicator.
740 *
741 * @returns VINF_SUCCESS or VERR_NO_STR_MEMORY.
742 * @param a_enmFormat The format to use.
743 */
744 int format(kFormat a_enmFormat) RT_NOEXCEPT;
745
746 /**
747 * Internal worker that attempts to decode m_strFormatted.
748 *
749 * Sets m_fTimeSpecOkay.
750 *
751 * @returns IPRT status code.
752 * @param enmFormat Specific format to try, kFormat_Invalid (default) to try guess it.
753 */
754 int decodeFormattedString(kFormat enmFormat = kFormat_Invalid) RT_NOEXCEPT;
755};
756
757
758/** We should provide a proper UUID class eventually. Currently it is not used. */
759typedef RTCRestString RTCRestUuid;
760
761
762/**
763 * String enum base class.
764 */
765class RT_DECL_CLASS RTCRestStringEnumBase : public RTCRestObjectBase
766{
767public:
768 /** Enum map entry. */
769 typedef struct ENUMMAPENTRY
770 {
771 const char *pszName;
772 uint32_t cchName;
773 int32_t iValue;
774 } ENUMMAPENTRY;
775
776 /** Default constructor. */
777 RTCRestStringEnumBase() RT_NOEXCEPT;
778 /** Destructor. */
779 virtual ~RTCRestStringEnumBase();
780
781 /** Copy constructor. */
782 RTCRestStringEnumBase(RTCRestStringEnumBase const &a_rThat);
783 /** Copy assignment operator. */
784 RTCRestStringEnumBase &operator=(RTCRestStringEnumBase const &a_rThat);
785
786 /** Safe copy assignment method. */
787 int assignCopy(RTCRestStringEnumBase const &a_rThat) RT_NOEXCEPT;
788 /** Safe copy assignment method. */
789 inline int assignCopy(RTCString const &a_rThat) RT_NOEXCEPT { return setByString(a_rThat); }
790 /** Safe copy assignment method. */
791 inline int assignCopy(const char *a_pszThat) RT_NOEXCEPT { return setByString(a_pszThat); }
792
793 /* Overridden methods: */
794 virtual int resetToDefault() RT_NOEXCEPT RT_OVERRIDE;
795 virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_NOEXCEPT RT_OVERRIDE;
796 virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_NOEXCEPT RT_OVERRIDE;
797 virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = kCollectionFormat_Unspecified) const RT_NOEXCEPT RT_OVERRIDE;
798 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL,
799 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_NOEXCEPT RT_OVERRIDE;
800 virtual kTypeClass typeClass(void) const RT_NOEXCEPT RT_OVERRIDE;
801
802 /**
803 * Sets the value given a C-string value.
804 *
805 * @retval VINF_SUCCESS on success.
806 * @retval VWRN_NOT_FOUND if not mappable to enum value.
807 * @retval VERR_NO_STR_MEMORY if not mappable and we're out of memory.
808 * @param a_pszValue The string value.
809 * @param a_cchValue The string value length. Optional.
810 */
811 int setByString(const char *a_pszValue, size_t a_cchValue = RTSTR_MAX) RT_NOEXCEPT;
812
813 /**
814 * Sets the value given a string value.
815 *
816 * @retval VINF_SUCCESS on success.
817 * @retval VWRN_NOT_FOUND if not mappable to enum value.
818 * @retval VERR_NO_STR_MEMORY if not mappable and we're out of memory.
819 * @param a_rValue The string value.
820 */
821 int setByString(RTCString const &a_rValue) RT_NOEXCEPT;
822
823 /**
824 * Gets the string value.
825 */
826 const char *getString() const RT_NOEXCEPT;
827
828 /** Maps the given string value to an enum. */
829 int stringToEnum(const char *a_pszValue, size_t a_cchValue = RTSTR_MAX) RT_NOEXCEPT;
830 /** Maps the given string value to an enum. */
831 int stringToEnum(RTCString const &a_rStrValue) RT_NOEXCEPT;
832 /** Maps the given string value to an enum. */
833 const char *enumToString(int a_iEnumValue, size_t *a_pcchString) RT_NOEXCEPT;
834
835
836protected:
837 /** The enum value. */
838 int m_iEnumValue;
839 /** The string value if not a match. */
840 RTCString m_strValue;
841
842 /**
843 * Worker for setting the object to the given enum value.
844 *
845 * @retval true on success.
846 * @retval false if a_iEnumValue can't be translated.
847 * @param a_iEnumValue The enum value to set.
848 */
849 bool setWorker(int a_iEnumValue) RT_NOEXCEPT;
850
851 /** Helper for implementing RTCRestObjectBase::clone(). */
852 RTCRestObjectBase *cloneWorker(RTCRestStringEnumBase *a_pDst) const RT_NOEXCEPT;
853
854 /**
855 * Gets the mapping table.
856 *
857 * @returns Pointer to the translation table.
858 * @param pcEntries Where to return the translation table size.
859 */
860 virtual ENUMMAPENTRY const *getMappingTable(size_t *pcEntries) const RT_NOEXCEPT = 0;
861};
862
863
864/**
865 * String enum template class.
866 *
867 * Takes the enum type as argument.
868 */
869template <typename EnumType>
870class RTCRestStringEnum : public RTCRestStringEnumBase
871{
872public:
873 typedef EnumType Type; /**< The enum type. */
874
875 /** Default constructor */
876 RTCRestStringEnum() RT_NOEXCEPT : RTCRestStringEnumBase() { }
877 /** Constructor with initial enum value. */
878 RTCRestStringEnum(Type a_enmValue) RT_NOEXCEPT : RTCRestStringEnumBase() { set(a_enmValue); }
879 /** Constructor with string default. */
880 RTCRestStringEnum(const char *a_pszDefault) : RTCRestStringEnumBase() { setByString(a_pszDefault); }
881 /** Copy constructor */
882 RTCRestStringEnum(RTCRestStringEnum const &a_rThat) : RTCRestStringEnumBase(a_rThat) { }
883 /** Make a clone of this object. */
884 inline RTCRestStringEnum *clone() const RT_NOEXCEPT { return (RTCRestStringEnum *)baseClone(); }
885
886 virtual RTCRestObjectBase *baseClone() const RT_NOEXCEPT RT_OVERRIDE
887 {
888 return cloneWorker(new (std::nothrow) RTCRestStringEnum());
889 }
890
891 /**
892 * Gets the enum value.
893 * @returns enum value.
894 * @retval kXxxxInvalid means there was no mapping for the string, or that
895 * no value has been assigned yet.
896 */
897 Type get() const RT_NOEXCEPT { return (Type)m_iEnumValue; }
898
899 /**
900 * Sets the object value to @a a_enmType
901 *
902 * @returns true if a_enmType is valid, false if not.
903 * @param a_enmType The new value.
904 */
905 bool set(Type a_enmType) RT_NOEXCEPT { return setWorker((int)a_enmType); }
906
907 virtual const char *typeName(void) const RT_NOEXCEPT RT_OVERRIDE { return "RTCRestStringEnum<EnumType>"; }
908
909 /** Factory method. */
910 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void) RT_NOEXCEPT
911 {
912 return new (std::nothrow) RTCRestStringEnum();
913 }
914
915 /** @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON */
916 static DECLCALLBACK(int) deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) RT_NOEXCEPT
917 {
918 *a_ppInstance = new (std::nothrow) RTCRestStringEnum();
919 if (*a_ppInstance)
920 return (*a_ppInstance)->deserializeFromJson(a_rCursor);
921 return a_rCursor.m_pPrimary->addError(a_rCursor, VERR_NO_MEMORY, "Out of memory");
922 }
923
924protected:
925 /** Enum mapping table. */
926 static const ENUMMAPENTRY s_aMappingTable[];
927 /** Enum mapping table size. */
928 static const size_t s_cMappingTable;
929
930 virtual ENUMMAPENTRY const *getMappingTable(size_t *pcEntries) const RT_NOEXCEPT RT_OVERRIDE
931 {
932 *pcEntries = s_cMappingTable;
933 return s_aMappingTable;
934 }
935};
936
937
938/**
939 * Class for handling binary blobs (strings).
940 *
941 * There are specializations of this class for body parameters and responses,
942 * see RTCRestBinaryParameter and RTCRestBinaryResponse.
943 */
944class RT_DECL_CLASS RTCRestBinary : public RTCRestObjectBase
945{
946public:
947 /** Default constructor. */
948 RTCRestBinary() RT_NOEXCEPT;
949 /** Destructor. */
950 virtual ~RTCRestBinary();
951
952 /** Safe copy assignment method. */
953 virtual int assignCopy(RTCRestBinary const &a_rThat) RT_NOEXCEPT;
954 /** Safe buffer copy method. */
955 virtual int assignCopy(void const *a_pvData, size_t a_cbData) RT_NOEXCEPT;
956
957 /** Use the specified data buffer directly. */
958 virtual int assignReadOnly(void const *a_pvData, size_t a_cbData) RT_NOEXCEPT;
959 /** Use the specified data buffer directly. */
960 virtual int assignWriteable(void *a_pvBuf, size_t a_cbBuf) RT_NOEXCEPT;
961 /** Frees the data held by the object and resets it default state. */
962 virtual void freeData() RT_NOEXCEPT;
963
964 /** Returns a pointer to the data blob. */
965 inline const uint8_t *getPtr() const RT_NOEXCEPT { return m_pbData; }
966 /** Gets the size of the data. */
967 inline size_t getSize() const RT_NOEXCEPT { return m_cbData; }
968
969 /** Make a clone of this object. */
970 inline RTCRestBinary *clone() const RT_NOEXCEPT { return (RTCRestBinary *)baseClone(); }
971
972 /* Overridden methods: */
973 virtual RTCRestObjectBase *baseClone() const RT_NOEXCEPT RT_OVERRIDE;
974 virtual int setNull(void) RT_NOEXCEPT RT_OVERRIDE;
975 virtual int resetToDefault(void) RT_NOEXCEPT RT_OVERRIDE;
976 virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_NOEXCEPT RT_OVERRIDE;
977 virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_NOEXCEPT RT_OVERRIDE;
978 virtual int toString(RTCString *a_pDst, uint32_t a_fFlags = kCollectionFormat_Unspecified) const RT_NOEXCEPT RT_OVERRIDE;
979 virtual int fromString(RTCString const &a_rValue, const char *a_pszName, PRTERRINFO a_pErrInfo = NULL,
980 uint32_t a_fFlags = kCollectionFormat_Unspecified) RT_NOEXCEPT RT_OVERRIDE;
981 virtual kTypeClass typeClass(void) const RT_NOEXCEPT RT_OVERRIDE;
982 virtual const char *typeName(void) const RT_NOEXCEPT RT_OVERRIDE;
983
984 /** Factory method. */
985 static DECLCALLBACK(RTCRestObjectBase *) createInstance(void) RT_NOEXCEPT;
986 /** @copydoc RTCRestObjectBase::FNDESERIALIZEINSTANCEFROMJSON */
987 static DECLCALLBACK(int) deserializeInstanceFromJson(RTCRestJsonCursor const &a_rCursor, RTCRestObjectBase **a_ppInstance) RT_NOEXCEPT;
988
989protected:
990 /** Pointer to data blob. */
991 uint8_t *m_pbData;
992 /** Amount of valid data in the blob. */
993 size_t m_cbData;
994 /** Number of bytes allocated for the m_pbData buffer. */
995 size_t m_cbAllocated;
996 /** Set if the data is freeable, only ever clear if user data. */
997 bool m_fFreeable;
998 /** Set if the data blob is readonly user provided data. */
999 bool m_fReadOnly;
1000
1001private:
1002 /* No copy constructor or copy assignment: */
1003 RTCRestBinary(RTCRestBinary const &a_rThat);
1004 RTCRestBinary &operator=(RTCRestBinary const &a_rThat);
1005};
1006
1007
1008/**
1009 * Abstract base class for REST data model classes.
1010 */
1011class RT_DECL_CLASS RTCRestDataObject : public RTCRestObjectBase
1012{
1013public:
1014 RTCRestDataObject() RT_NOEXCEPT;
1015 RTCRestDataObject(RTCRestDataObject const &a_rThat) RT_NOEXCEPT;
1016 virtual ~RTCRestDataObject();
1017
1018 /* Overridden methods:*/
1019 virtual int resetToDefault() RT_NOEXCEPT RT_OVERRIDE;
1020 virtual RTCRestOutputBase &serializeAsJson(RTCRestOutputBase &a_rDst) const RT_NOEXCEPT RT_OVERRIDE;
1021 virtual int deserializeFromJson(RTCRestJsonCursor const &a_rCursor) RT_NOEXCEPT RT_OVERRIDE;
1022 virtual kTypeClass typeClass(void) const RT_NOEXCEPT RT_OVERRIDE;
1023
1024 /**
1025 * Serialize the object members as JSON.
1026 *
1027 * @returns a_rDst
1028 * @param a_rDst The destination for the serialization.
1029 */
1030 virtual RTCRestOutputBase &serializeMembersAsJson(RTCRestOutputBase &a_rDst) const RT_NOEXCEPT;
1031
1032 /**
1033 * Deserialize object from the given JSON iterator.
1034 *
1035 * @returns IPRT status code.
1036 * @retval VERR_NOT_FOUND if field is unknown. Top level caller will do
1037 * invoke unknownField() on it.
1038 *
1039 * @param a_rCursor The JSON cursor with the current member.
1040 * @param a_cchName The length of a_rCursor.m_pszName.
1041 */
1042 virtual int deserializeMemberFromJson(RTCRestJsonCursor const &a_rCursor, size_t a_cchName) RT_NOEXCEPT;
1043
1044protected:
1045 /** The is-set bits for all the fields. */
1046 uint64_t m_fIsSet;
1047
1048 /** Copy assignment operator. */
1049 RTCRestDataObject &operator=(RTCRestDataObject const &a_rThat) RT_NOEXCEPT;
1050
1051 /** Safe copy assignment method. */
1052 virtual int assignCopy(RTCRestDataObject const &a_rThat) RT_NOEXCEPT;
1053};
1054
1055
1056/**
1057 * Abstract base class for polymorphic REST data model classes.
1058 */
1059class RT_DECL_CLASS RTCRestPolyDataObject : public RTCRestDataObject
1060{
1061public:
1062 RTCRestPolyDataObject() RT_NOEXCEPT;
1063 RTCRestPolyDataObject(RTCRestPolyDataObject const &a_rThat) RT_NOEXCEPT;
1064 virtual ~RTCRestPolyDataObject();
1065
1066 /* Overridden methods:*/
1067 virtual int resetToDefault() RT_NOEXCEPT RT_OVERRIDE;
1068
1069 /** Checks if the instance is of a child class (@c true) or of the parent (@c false). */
1070 virtual bool isChild() const RT_NOEXCEPT;
1071
1072protected:
1073
1074 /** Copy assignment operator. */
1075 RTCRestPolyDataObject &operator=(RTCRestPolyDataObject const &a_rThat) RT_NOEXCEPT;
1076};
1077
1078
1079/** @} */
1080
1081#endif
1082
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