17
17
#include <cpprest /json.h >
18
18
19
19
#include <map >
20
+ #include <set >
20
21
#include <vector >
21
22
22
23
{ {#modelNamespaceDeclarations} }
@@ -52,6 +53,8 @@ public:
52
53
static utility::string_t toString( const std::shared_ptr< T> & val );
53
54
template < typename T>
54
55
static utility::string_t toString( const std::vector< T> & val );
56
+ template < typename T>
57
+ static utility::string_t toString( const std::set< T> & val );
55
58
56
59
static web::json::value toJson( bool val );
57
60
static web::json::value toJson( float val );
@@ -68,6 +71,8 @@ public:
68
71
template< typename T>
69
72
static web::json::value toJson( const std::vector< T> & val );
70
73
template< typename T>
74
+ static web::json::value toJson( const std::set< T> & val );
75
+ template< typename T>
71
76
static web::json::value toJson( const std::map< utility::string_t, T> & val );
72
77
73
78
static bool fromString( const utility::string_t& val, bool & );
@@ -85,6 +90,8 @@ public:
85
90
template< typename T>
86
91
static bool fromString( const utility::string_t& val, std::vector< T> & );
87
92
template< typename T>
93
+ static bool fromString( const utility::string_t& val, std::set< T> & );
94
+ template< typename T>
88
95
static bool fromString( const utility::string_t& val, std::map< utility::string_t, T> & );
89
96
90
97
static bool fromJson( const web::json::value& val, bool & );
@@ -102,6 +109,8 @@ public:
102
109
template< typename T>
103
110
static bool fromJson( const web::json::value& val, std::vector< T> & );
104
111
template< typename T>
112
+ static bool fromJson( const web::json::value& val, std::set< T> & );
113
+ template< typename T>
105
114
static bool fromJson( const web::json::value& val, std::map< utility::string_t, T> & );
106
115
107
116
@@ -120,6 +129,8 @@ public:
120
129
template < typename T>
121
130
static std::shared_ptr< HttpContent> toHttpContent( const utility::string_t& name, const std::vector< T> & value, const utility::string_t& contentType = utility::conversions::to_string_t(" " ) );
122
131
template < typename T>
132
+ static std::shared_ptr< HttpContent> toHttpContent( const utility::string_t& name, const std::set< T> & value, const utility::string_t& contentType = utility::conversions::to_string_t(" " ) );
133
+ template < typename T>
123
134
static std::shared_ptr< HttpContent> toHttpContent( const utility::string_t& name, const std::map< utility::string_t, T> & value, const utility::string_t& contentType = utility::conversions::to_string_t(" " ) );
124
135
125
136
static bool fromHttpContent( std::shared_ptr< HttpContent> val, bool & );
@@ -136,6 +147,8 @@ public:
136
147
template < typename T>
137
148
static bool fromHttpContent( std::shared_ptr< HttpContent> val, std::vector< T> & );
138
149
template < typename T>
150
+ static bool fromHttpContent( std::shared_ptr< HttpContent> val, std::set< T> & );
151
+ template < typename T>
139
152
static bool fromHttpContent( std::shared_ptr< HttpContent> val, std::map< utility::string_t, T> & );
140
153
141
154
static utility::string_t toBase64( utility::string_t value );
@@ -155,6 +168,8 @@ utility::string_t ModelBase::toString( const std::shared_ptr<T>& val )
155
168
}
156
169
return utility::string_t(ss.str());
157
170
}
171
+
172
+ // std::vector to string
158
173
template<typename T >
159
174
utility::string_t ModelBase::toString( const std::vector<T > & val )
160
175
{
@@ -169,6 +184,24 @@ utility::string_t ModelBase::toString( const std::vector<T> & val )
169
184
}
170
185
return strArray;
171
186
}
187
+
188
+ // std::set to string
189
+ template<typename T >
190
+ utility::string_t ModelBase::toString( const std::set<T > & val )
191
+ {
192
+ utility::string_t strArray;
193
+ for ( const auto &item : val )
194
+ {
195
+ strArray.append( toString(item) + " ," );
196
+ }
197
+ if (val.count() > 0)
198
+ {
199
+ strArray.pop_back();
200
+ }
201
+ return strArray;
202
+ }
203
+
204
+
172
205
template<typename T >
173
206
web::json::value ModelBase::toJson( const std::shared_ptr<T >& val )
174
207
{
@@ -179,6 +212,8 @@ web::json::value ModelBase::toJson( const std::shared_ptr<T>& val )
179
212
}
180
213
return retVal;
181
214
}
215
+
216
+ // std::vector to json
182
217
template<typename T >
183
218
web::json::value ModelBase::toJson( const std::vector<T >& value )
184
219
{
@@ -189,6 +224,21 @@ web::json::value ModelBase::toJson( const std::vector<T>& value )
189
224
}
190
225
return web::json::value::array(ret);
191
226
}
227
+
228
+ // std::set to json
229
+ template<typename T >
230
+ web::json::value ModelBase::toJson( const std::set<T >& value )
231
+ {
232
+ // There' s no protoype web::json::value::array(...) taking a std::set parameter. Converting to std::vector to get an array.
233
+ std::vector<web::json::value> ret;
234
+ for ( const auto& x : value )
235
+ {
236
+ ret.push_back( toJson(x) );
237
+ }
238
+ return web::json::value::array(ret);
239
+ }
240
+
241
+
192
242
template<typename T>
193
243
web::json::value ModelBase::toJson( const std::map<utility::string_t, T>& val )
194
244
{
@@ -279,6 +329,7 @@ std::shared_ptr<HttpContent> ModelBase::toHttpContent(const utility::string_t& n
279
329
}
280
330
return content;
281
331
}
332
+
282
333
template <typename T>
283
334
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const std::vector<T>& value, const utility::string_t& contentType )
284
335
{
@@ -290,6 +341,7 @@ std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t&
290
341
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(json_array.serialize()) ) ) );
291
342
return content;
292
343
}
344
+
293
345
template <typename T>
294
346
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const std::map<utility::string_t, T>& value, const utility::string_t& contentType )
295
347
{
0 commit comments