C++ TargetRTS
Loading...
Searching...
No Matches
RTJsonResult.h
1/*
2 * Licensed Materials - Property of HCL and/or IBM
3 * Copyright HCL Technologies Ltd. 2016, 2024. All Rights Reserved.
4 * Copyright IBM Corporation 1999, 2016. All Rights Reserved.
5 *
6 * U.S. Government Users Restricted Rights - Use, duplication or
7 * disclosure restricted by GSA ADP Schedule.
8 */
9
10#ifndef __RTJsonResult_h__
11#define __RTJsonResult_h__ included
12
13#ifdef PRAGMA
14#pragma interface
15#endif
16
17#include <map>
18#include <string>
19#include <vector>
20#include <RTConfig.h>
21
29{
30public:
34 typedef enum
35 {
49
50 explicit RTJsonResult();
52
58 const RTJsonResult& operator[]( const std::string& key ) const;
59
67 const RTJsonResult& operator[]( size_t index ) const;
68
73 RTS_INLINE size_t get_size() const;
74
76 RTS_INLINE std::map<std::string, RTJsonResult>::const_iterator keys_begin() const;
77
79 RTS_INLINE std::map<std::string, RTJsonResult>::const_iterator keys_end() const;
80
83
85 RTJsonResult( const RTJsonResult & other );
86
88 static const RTJsonResult ERROR;
89
91 RTS_INLINE bool ok() const;
92
95 const std::string& get_string() const;
96
99
101 bool get_bool() const;
102
106 int get_int() const;
107
111 float get_float() const;
112
116 double get_double() const;
117
119 bool operator==(const RTJsonResult&) const;
120
122 bool operator==(const bool) const;
123
125 bool operator==(const int) const;
126
128 bool operator==(const float) const;
129
131 bool operator==(const double) const;
132
134 bool operator==(const char*) const;
135
136
137private:
138 friend class RTJsonParser;
139 friend class RTJsonParserUtils;
140
142 std::string value;
143 std::vector <RTJsonResult> arrayValues;
144 std::map <std::string, RTJsonResult> keysValues;
145
146 RTS_INLINE void put_string( const std::string & val );
147 RTS_INLINE void put_number( const std::string & val );
148 RTS_INLINE void put_bool( bool );
149 RTS_INLINE void put_object();
150 RTS_INLINE void put_array();
151 RTS_INLINE void put_null();
152 RTS_INLINE void clear();
153};
154
155#if RTS_INLINES
156#include <RTJsonResult.inl>
157#endif
158
159#endif // __RTJsonResult_h__
Utility for parsing JSON.
Definition: RTJsonParser.h:23
Definition: RTJsonParserUtils.h:47
Represents the result of parsing a JSON string.
Definition: RTJsonResult.h:29
RTJsonResult & operator=(const RTJsonResult &other)
Assignment operator.
bool operator==(const int) const
Determines if the JSON value is numeric and equal to the given int.
std::map< std::string, RTJsonResult >::const_iterator keys_begin() const
For a JSON object, return its keys begin iterator.
Definition: RTJsonResult.inl:21
RTJsonResult(const RTJsonResult &other)
Copy constructor.
double get_double() const
Interpret the JSON value as a double.
bool operator==(const char *) const
Determines if the JSON value is a string and equal to the given string.
const std::string & get_string() const
Get a string representation of the JSON value.
bool operator==(const RTJsonResult &) const
Determines if the JSON value is equal (but not necessarily the same) as another JSON value.
bool get_bool() const
Interpret the JSON value as a bool.
float get_float() const
Interpret the JSON value as a float.
RTJsonType get_type() const
Get the type of JSON value represented by the RTJsonResult.
bool ok() const
Returns false if this object represents an error result, true otherwise.
Definition: RTJsonResult.inl:31
std::map< std::string, RTJsonResult >::const_iterator keys_end() const
For a JSON object, return its keys end iterator.
Definition: RTJsonResult.inl:26
bool operator==(const double) const
Determines if the JSON value is numeric and equal to the given double.
RTJsonType
The type of JSON value represented by the RTJsonResult object.
Definition: RTJsonResult.h:35
@ RTJSON_NUM
JSON numeric value.
Definition: RTJsonResult.h:45
@ RTJSON_BOOL
JSON boolean value.
Definition: RTJsonResult.h:47
@ RTJSON_ARR
JSON array value.
Definition: RTJsonResult.h:41
@ RTJSON_STR
JSON string value.
Definition: RTJsonResult.h:43
@ RTJSON_NULL
The special null value.
Definition: RTJsonResult.h:37
@ RTJSON_OBJ
JSON object value.
Definition: RTJsonResult.h:39
int get_int() const
Interpret the JSON value as an int.
const RTJsonResult & operator[](size_t index) const
For a JSON array, return the value at the given index.
bool operator==(const bool) const
Determines if the JSON value is boolean and equal to the given bool.
bool operator==(const float) const
Determines if the JSON value is numeric and equal to the given float.
const RTJsonResult & operator[](const std::string &key) const
For a JSON object, return the value for the key with the given name.
static const RTJsonResult ERROR
This special object represents an error result.
Definition: RTJsonResult.h:88
size_t get_size() const
For a JSON array, return the number of array elements.
Definition: RTJsonResult.inl:36