Microsoft Information Protection (MIP) SDK for C++: Reference 1.15
Doxygen-generated documentation for MIP SDK written in C++
Loading...
Searching...
No Matches
json_value.h
Go to the documentation of this file.
1/*
2 *
3 * Copyright (c) Microsoft Corporation.
4 * All rights reserved.
5 *
6 * This code is licensed under the MIT License.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files(the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions :
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26/**
27 * @brief A file containing the JsonValue interface.
28 *
29 * @file json_value.h
30 */
31#ifndef API_MIP_JSON_VALUE_H_
32#define API_MIP_JSON_VALUE_H_
33
34#include <memory>
35#include <string>
36#include <vector>
37
38#include "mip/mip_namespace.h"
39
40MIP_NAMESPACE_BEGIN
41
42class JsonValue {
43public:
44 /**
45 * @brief check if value is a string.
46 *
47 * @return true if json value is string.
48 */
49 virtual bool IsString() const = 0;
50 /**
51 * @brief check if value is a json array.
52 *
53 * @return true if json value is a json array.
54 */
55 virtual bool IsArray() const = 0;
56 /**
57 * @brief check if value is a json object.
58 *
59 * @return true if json value is a json object.
60 */
61 virtual bool IsObject() const = 0;
62 /**
63 * @brief return true if object has a child with the specified key.
64 *
65 * @return true if object has a child with the specified key.
66 */
67 virtual bool HasMember(const std::string& key) const = 0;
68 /**
69 * @brief Add a value member to an Array. The object should not be modified after being added.
70 */
71 virtual void PushBack(const std::shared_ptr<JsonValue>& jsonValue) = 0;
72 /**
73 * @brief Add a string member to an Array with the specified value.
74 * @param member The value of the member to add.
75 */
76 virtual void PushBack(const std::string& member) = 0;
77 /**
78 * @brief Add a value member to an Object. The object should not be modified after being added.
79 */
80 virtual void AddMember(const std::string& key, const std::shared_ptr<JsonValue>& jsonValue) = 0;
81 /*
82 * @brief Add a string member to an Object with the specified key and value.
83 * @param key The key of the member to add.
84 * @param member The value of the member to add.
85 */
86 virtual void AddMember(const std::string& key, const std::string& member) = 0;
87 /**
88 * @brief Add a boolean member to an Object with the specified key and value.
89 * @param key The key of the member to add.
90 * @param member The value of the member to add.
91 */
92 virtual void AddMember(const std::string& key, bool member) = 0;
93 /**
94 * @brief Add a signed integer member to an Object with the specified key and value.
95 * @param key The key of the member to add.
96 * @param member The value of the member to add.
97 */
98 virtual void AddMember(const std::string& key, int member) = 0;
99 /**
100 * @brief Add an unsigned integer member to an Object with the specified key and value.
101 * @param key The key of the member to add.
102 * @param member The value of the member to add.
103 */
104 virtual void AddMember(const std::string& key, unsigned int member) = 0;
105 /**
106 * @brief return child value with the specified key if this is an Object.
107 *
108 * @return child value with the specified key if this is an Object.
109 */
110 virtual std::shared_ptr<JsonValue> GetMember(const std::string& key) const = 0;
111 /**
112 * @brief return child value at specified index if this is an Array.
113 * @return child value at specified index if this is an Array.
114 */
115 virtual std::shared_ptr<JsonValue> GetMember(unsigned int index) const = 0;
116 /**
117 * @brief return number of child elements.
118 * @return number of child elements.
119 */
120 virtual size_t Size() const = 0;
121 /**
122 * @brief return value array as strings, skip non string elements.
123 *
124 * @return a vector of the string in a json array.
125 */
126 virtual std::vector<std::string> GetStringArray() const = 0;
127 /**
128 * @brief Return all string members of this object and their keys, skip non string elements.
129 * Example: for the json object {"a": "b", "c": "d", "e": 1, "f": {"g": "h"}}
130 * this method would return a vector of two pairs: ("a", "b") and ("c", "d").
131 * @return all string members of this object and their keys as a vector of pairs.
132 */
133 virtual std::vector<std::pair<std::string, std::string>> GetStringObjectMembers() const = 0;
134 /**
135 * @brief If the current value is a string, return it.
136 * @return The current value if it is a string.
137 */
138 virtual std::string GetString() const = 0;
139 /**
140 * @brief Returns true if the current value is an int.
141 * @return true if the current value is an int.
142 */
143 virtual bool IsInt() const = 0;
144 /**
145 * @brief If the current value is an int, return it.
146 * @return The current value if it is an int.
147 */
148 virtual int GetInt() const = 0;
149 /**
150 * @brief Return true if the current value is a bool.
151 * @return true if the current value is a bool.
152 */
153 virtual bool IsBool() const = 0;
154 /**
155 * @brief Return true if the current value is an unsigned int.
156 * @return true if the current value is an unsigned int.
157 */
158 virtual bool IsUint() const = 0;
159 /**
160 * @brief If the current value is a uint, return it.
161 * @return The current value if it is a uint.
162 */
163 virtual unsigned int GetUint() const = 0;
164 /**
165 * @brief Return true if the current value is a number of any type.
166 * @return true if the current value is a number of any type.
167 */
168 virtual bool IsNumber() const = 0;
169 /**
170 * @brief If the current value is a double, return it.
171 * @return The current value if it is a double.
172 */
173 virtual double GetDouble() const = 0;
174 /**
175 * @brief If the current value is a bool, return it.
176 * @return The current value if it is a bool.
177 */
178 virtual bool GetBool() const = 0;
179 /**
180 * @brief Serialize the value and all children as a string.
181 * @return This json value and all children serialized as a string.
182 */
183 virtual std::string SerializeToString() const = 0;
184
185 /** @cond DOXYGEN_HIDE */
186 virtual ~JsonValue() {};
187 /** @endcond */
188};
189
190MIP_NAMESPACE_END
191
192#endif // API_MIP_JSON_VALUE_H_
virtual std::vector< std::string > GetStringArray() const =0
return value array as strings, skip non string elements.
virtual int GetInt() const =0
If the current value is an int, return it.
virtual void AddMember(const std::string &key, unsigned int member)=0
Add an unsigned integer member to an Object with the specified key and value.
virtual std::string SerializeToString() const =0
Serialize the value and all children as a string.
virtual void AddMember(const std::string &key, const std::shared_ptr< JsonValue > &jsonValue)=0
Add a value member to an Object.
virtual double GetDouble() const =0
If the current value is a double, return it.
virtual bool IsObject() const =0
check if value is a json object.
virtual bool IsUint() const =0
Return true if the current value is an unsigned int.
virtual void PushBack(const std::string &member)=0
Add a string member to an Array with the specified value.
virtual bool IsInt() const =0
Returns true if the current value is an int.
virtual void PushBack(const std::shared_ptr< JsonValue > &jsonValue)=0
Add a value member to an Array.
virtual void AddMember(const std::string &key, int member)=0
Add a signed integer member to an Object with the specified key and value.
virtual bool IsArray() const =0
check if value is a json array.
virtual bool GetBool() const =0
If the current value is a bool, return it.
virtual void AddMember(const std::string &key, bool member)=0
Add a boolean member to an Object with the specified key and value.
virtual size_t Size() const =0
return number of child elements.
virtual bool IsBool() const =0
Return true if the current value is a bool.
virtual unsigned int GetUint() const =0
If the current value is a uint, return it.
virtual bool HasMember(const std::string &key) const =0
return true if object has a child with the specified key.
virtual bool IsNumber() const =0
Return true if the current value is a number of any type.
virtual bool IsString() const =0
check if value is a string.
virtual std::shared_ptr< JsonValue > GetMember(unsigned int index) const =0
return child value at specified index if this is an Array.
virtual std::vector< std::pair< std::string, std::string > > GetStringObjectMembers() const =0
Return all string members of this object and their keys, skip non string elements.
virtual std::shared_ptr< JsonValue > GetMember(const std::string &key) const =0
return child value with the specified key if this is an Object.
virtual void AddMember(const std::string &key, const std::string &member)=0
virtual std::string GetString() const =0
If the current value is a string, return it.
MIP namespace macros.