-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModelBase.cpp
618 lines (609 loc) · 21.6 KB
/
ModelBase.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
/**
* madana-api
* <h1>Using the madana-api</h1> <p>This documentation contains a Quickstart Guide, relating client functionality and information about the available endpoints and used datamodels. </p> <p> The madana-api and its implementations are still in heavy development. This means that there may be problems in our protocols, or there may be mistakes in our implementations. We take security vulnerabilities very seriously. If you discover a security issue, please bring it to our attention right away! If you find a vulnerability that may affect live deployments -- for example, by exposing a remote execution exploit -- please send your report privately to [email protected]. Please DO NOT file a public issue. If the issue is a protocol weakness that cannot be immediately exploited or something not yet deployed, just discuss it openly </p> <br> <p> Note: Not all functionality might be acessible without having accquired and api-license token. For more information visit <a href=\"https://www.madana.io\">www.madana.io</a> </p> <br>
*
* The version of the OpenAPI document: 0.5.0-master.56
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "ModelBase.h"
namespace com {
namespace madana {
namespace apiclient {
namespace model {
ModelBase::ModelBase(): m_IsSet(false)
{
}
ModelBase::~ModelBase()
{
}
bool ModelBase::isSet() const
{
return m_IsSet;
}
utility::string_t ModelBase::toString( const bool val )
{
utility::stringstream_t ss;
ss << val;
return utility::string_t(ss.str());
}
utility::string_t ModelBase::toString( const float val )
{
utility::stringstream_t ss;
ss << val;
return utility::string_t(ss.str());
}
utility::string_t ModelBase::toString( const double val )
{
utility::stringstream_t ss;
ss << val;
return utility::string_t(ss.str());
}
utility::string_t ModelBase::toString( const int32_t val )
{
utility::stringstream_t ss;
ss << val;
return utility::string_t(ss.str());
}
utility::string_t ModelBase::toString( const int64_t val )
{
utility::stringstream_t ss;
ss << val;
return utility::string_t(ss.str());
}
utility::string_t ModelBase::toString (const utility::string_t &val )
{
utility::stringstream_t ss;
ss << val;
return utility::string_t(ss.str());
}
utility::string_t ModelBase::toString( const utility::datetime &val )
{
return val.to_string(utility::datetime::ISO_8601);
}
utility::string_t ModelBase::toString( const web::json::value &val )
{
return val.serialize();
}
utility::string_t ModelBase::toString( const std::shared_ptr<HttpContent>& val )
{
utility::stringstream_t ss;
if( val != nullptr )
{
ss << val->getData();
}
return utility::string_t(ss.str());
}
web::json::value ModelBase::toJson(bool value)
{
return web::json::value::boolean(value);
}
web::json::value ModelBase::toJson( float value )
{
return web::json::value::number(value);
}
web::json::value ModelBase::toJson( double value )
{
return web::json::value::number(value);
}
web::json::value ModelBase::toJson( int32_t value )
{
return web::json::value::number(value);
}
web::json::value ModelBase::toJson( int64_t value )
{
return web::json::value::number(value);
}
web::json::value ModelBase::toJson( const utility::string_t& value )
{
return web::json::value::string(value);
}
web::json::value ModelBase::toJson( const utility::datetime& value )
{
return web::json::value::string(value.to_string(utility::datetime::ISO_8601));
}
web::json::value ModelBase::toJson( const web::json::value& value )
{
return value;
}
web::json::value ModelBase::toJson( const std::shared_ptr<HttpContent>& content )
{
web::json::value value;
if(content != nullptr)
{
value[utility::conversions::to_string_t("ContentDisposition")] = ModelBase::toJson(content->getContentDisposition());
value[utility::conversions::to_string_t("ContentType")] = ModelBase::toJson(content->getContentType());
value[utility::conversions::to_string_t("FileName")] = ModelBase::toJson(content->getFileName());
value[utility::conversions::to_string_t("InputStream")] = web::json::value::string( ModelBase::toBase64(content->getData()) );
}
return value;
}
bool ModelBase::fromString( const utility::string_t& val, bool &outVal )
{
utility::stringstream_t ss(val);
bool success = true;
try
{
ss >> outVal;
}
catch (...)
{
success = false;
}
return success;
}
bool ModelBase::fromString( const utility::string_t& val, float &outVal )
{
utility::stringstream_t ss(val);
bool success = true;
try
{
ss >> outVal;
}
catch (...)
{
int64_t intVal = 0;
success = ModelBase::fromString(val, intVal);
if(success)
{
outVal = static_cast<float>(intVal);
}
}
return success;
}
bool ModelBase::fromString( const utility::string_t& val, double &outVal )
{
utility::stringstream_t ss(val);
bool success = true;
try
{
ss >> outVal;
}
catch (...)
{
int64_t intVal = 0;
success = ModelBase::fromString(val, intVal);
if(success)
{
outVal = static_cast<double>(intVal);
}
}
return success;
}
bool ModelBase::fromString( const utility::string_t& val, int32_t &outVal )
{
utility::stringstream_t ss(val);
bool success = true;
try
{
ss >> outVal;
}
catch (...)
{
success = false;
}
return success;
}
bool ModelBase::fromString( const utility::string_t& val, int64_t &outVal )
{
utility::stringstream_t ss(val);
bool success = true;
try
{
ss >> outVal;
}
catch (...)
{
success = false;
}
return success;
}
bool ModelBase::fromString( const utility::string_t& val, utility::string_t &outVal )
{
utility::stringstream_t ss(val);
bool success = true;
try
{
ss >> outVal;
}
catch (...)
{
success = false;
}
return success;
}
bool ModelBase::fromString( const utility::string_t& val, utility::datetime &outVal )
{
bool success = true;
auto dt = utility::datetime::from_string(val, utility::datetime::ISO_8601);
if( dt.is_initialized() )
{
outVal = dt;
}
else
{
success = false;
}
return success;
}
bool ModelBase::fromString( const utility::string_t& val, web::json::value &outVal )
{
outVal = web::json::value::parse(val);
return !outVal.is_null();
}
bool ModelBase::fromString( const utility::string_t& val, std::shared_ptr<HttpContent>& outVal )
{
bool ok = true;
if(outVal == nullptr)
{
outVal = std::shared_ptr<HttpContent>(new HttpContent());
}
if(outVal != nullptr)
{
outVal->setData(std::shared_ptr<std::istream>(new std::stringstream(utility::conversions::to_utf8string(val))));
}
else
{
ok = false;
}
return ok;
}
bool ModelBase::fromJson( const web::json::value& val, bool & outVal )
{
outVal = !val.is_boolean() ? false : val.as_bool();
return val.is_boolean();
}
bool ModelBase::fromJson( const web::json::value& val, float & outVal )
{
outVal = !val.is_double() ? std::numeric_limits<float>::quiet_NaN(): static_cast<float>(val.as_double());
return val.is_double();
}
bool ModelBase::fromJson( const web::json::value& val, double & outVal )
{
outVal = !val.is_double() ? std::numeric_limits<double>::quiet_NaN(): val.as_double();
return val.is_double() ;
}
bool ModelBase::fromJson( const web::json::value& val, int32_t & outVal )
{
outVal = !val.is_integer() ? std::numeric_limits<int32_t>::quiet_NaN() : val.as_integer();
return val.is_integer();
}
bool ModelBase::fromJson( const web::json::value& val, int64_t & outVal )
{
outVal = !val.is_null() ? std::numeric_limits<int64_t>::quiet_NaN() : val.as_number().to_int64();
return val.is_number();
}
bool ModelBase::fromJson( const web::json::value& val, utility::string_t & outVal )
{
outVal = val.is_string() ? val.as_string() : utility::conversions::to_string_t("");
return val.is_string();
}
bool ModelBase::fromJson( const web::json::value& val, utility::datetime & outVal )
{
outVal = val.is_null() ? utility::datetime::from_string(utility::conversions::to_string_t("NULL"), utility::datetime::ISO_8601) : utility::datetime::from_string(val.as_string(), utility::datetime::ISO_8601);
return outVal.is_initialized();
}
bool ModelBase::fromJson( const web::json::value& val, web::json::value & outVal )
{
outVal = val;
return !val.is_null();
}
bool ModelBase::fromJson( const web::json::value& val, std::shared_ptr<HttpContent>& content )
{
bool result = false;
if( content != nullptr)
{
result = true;
if(content == nullptr)
{
content = std::shared_ptr<HttpContent>(new HttpContent());
}
if(val.has_field(utility::conversions::to_string_t("ContentDisposition")))
{
utility::string_t value;
result = result && ModelBase::fromJson(val.at(utility::conversions::to_string_t("ContentDisposition")), value);
content->setContentDisposition( value );
}
if(val.has_field(utility::conversions::to_string_t("ContentType")))
{
utility::string_t value;
result = result && ModelBase::fromJson(val.at(utility::conversions::to_string_t("ContentType")), value);
content->setContentType( value );
}
if(val.has_field(utility::conversions::to_string_t("FileName")))
{
utility::string_t value;
result = result && ModelBase::fromJson(val.at(utility::conversions::to_string_t("FileName")), value);
content->setFileName( value );
}
if(val.has_field(utility::conversions::to_string_t("InputStream")))
{
utility::string_t value;
result = result && ModelBase::fromJson(val.at(utility::conversions::to_string_t("InputStream")), value);
content->setData( ModelBase::fromBase64( value ) );
}
}
return result;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, bool value, const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
std::stringstream* valueAsStringStream = new std::stringstream();
(*valueAsStringStream) << value;
content->setData( std::shared_ptr<std::istream>( valueAsStringStream ) );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, float value, const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
std::stringstream* valueAsStringStream = new std::stringstream();
(*valueAsStringStream) << value;
content->setData( std::shared_ptr<std::istream>( valueAsStringStream ) );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, double value, const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
std::stringstream* valueAsStringStream = new std::stringstream();
(*valueAsStringStream) << value;
content->setData( std::shared_ptr<std::istream>( valueAsStringStream ) );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, int32_t value, const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
std::stringstream* valueAsStringStream = new std::stringstream();
(*valueAsStringStream) << value;
content->setData( std::shared_ptr<std::istream>( valueAsStringStream ) );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, int64_t value, const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
std::stringstream* valueAsStringStream = new std::stringstream();
(*valueAsStringStream) << value;
content->setData( std::shared_ptr<std::istream>( valueAsStringStream) ) ;
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const utility::string_t& value, const utility::string_t& contentType)
{
std::shared_ptr<HttpContent> content(new HttpContent);
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value) ) ) );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const utility::datetime& value, const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value.to_string(utility::datetime::ISO_8601) ) ) ) );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const web::json::value& value, const utility::string_t& contentType )
{
std::shared_ptr<HttpContent> content( new HttpContent );
content->setName( name );
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
content->setContentType( contentType );
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(value.serialize()) ) ) );
return content;
}
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const std::shared_ptr<HttpContent>& value )
{
std::shared_ptr<HttpContent> content( new HttpContent );
if( value != nullptr )
{
content->setName( name );
content->setContentDisposition( value->getContentDisposition() );
content->setContentType( value->getContentType() );
content->setData( value->getData() );
content->setFileName( value->getFileName() );
}
return content;
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, bool & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, float & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, double & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, int32_t & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, int64_t & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, utility::string_t & outVal )
{
if( val == nullptr ) return false;
std::shared_ptr<std::istream> data = val->getData();
data->seekg( 0, data->beg );
std::string str((std::istreambuf_iterator<char>(*data.get())),
std::istreambuf_iterator<char>());
outVal = utility::conversions::to_string_t(str);
return true;
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, utility::datetime & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
outVal = utility::datetime::from_string(str, utility::datetime::ISO_8601);
return true;
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, web::json::value & outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, std::shared_ptr<HttpContent>& outVal )
{
utility::string_t str;
if( val == nullptr ) return false;
if( outVal == nullptr )
{
outVal = std::shared_ptr<HttpContent>(new HttpContent());
}
ModelBase::fromHttpContent(val, str);
return fromString(str, outVal);
}
// base64 encoding/decoding based on : https://en.wikibooks.org/wiki/Algorithm_Implementation/Miscellaneous/Base64#C.2B.2B
const static char Base64Chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const static char Base64PadChar = '=';
utility::string_t ModelBase::toBase64( utility::string_t value )
{
std::shared_ptr<std::istream> source( new std::stringstream( utility::conversions::to_utf8string(value) ) );
return ModelBase::toBase64(source);
}
utility::string_t ModelBase::toBase64( std::shared_ptr<std::istream> value )
{
value->seekg( 0, value->end );
size_t length = value->tellg();
value->seekg( 0, value->beg );
utility::string_t base64;
base64.reserve( ((length / 3) + (length % 3 > 0)) * 4 );
char read[3] = { 0 };
uint32_t temp;
for ( size_t idx = 0; idx < length / 3; idx++ )
{
value->read( read, 3 );
temp = (read[0]) << 16;
temp += (read[1]) << 8;
temp += (read[2]);
base64.append( 1, Base64Chars[(temp & 0x00FC0000) >> 18] );
base64.append( 1, Base64Chars[(temp & 0x0003F000) >> 12] );
base64.append( 1, Base64Chars[(temp & 0x00000FC0) >> 6] );
base64.append( 1, Base64Chars[(temp & 0x0000003F)] );
}
switch ( length % 3 )
{
case 1:
value->read( read, 1 );
temp = read[0] << 16;
base64.append( 1, Base64Chars[(temp & 0x00FC0000) >> 18] );
base64.append( 1, Base64Chars[(temp & 0x0003F000) >> 12] );
base64.append( 2, Base64PadChar );
break;
case 2:
value->read( read, 2 );
temp = read[0] << 16;
temp += read[1] << 8;
base64.append( 1, Base64Chars[(temp & 0x00FC0000) >> 18] );
base64.append( 1, Base64Chars[(temp & 0x0003F000) >> 12] );
base64.append( 1, Base64Chars[(temp & 0x00000FC0) >> 6] );
base64.append( 1, Base64PadChar );
break;
}
return base64;
}
std::shared_ptr<std::istream> ModelBase::fromBase64( const utility::string_t& encoded )
{
std::shared_ptr<std::stringstream> result(new std::stringstream);
char outBuf[3] = { 0 };
uint32_t temp = 0;
utility::string_t::const_iterator cursor = encoded.begin();
while ( cursor < encoded.end() )
{
for ( size_t quantumPosition = 0; quantumPosition < 4; quantumPosition++ )
{
temp <<= 6;
if ( *cursor >= 0x41 && *cursor <= 0x5A )
{
temp |= *cursor - 0x41;
}
else if ( *cursor >= 0x61 && *cursor <= 0x7A )
{
temp |= *cursor - 0x47;
}
else if ( *cursor >= 0x30 && *cursor <= 0x39 )
{
temp |= *cursor + 0x04;
}
else if ( *cursor == 0x2B )
{
temp |= 0x3E; //change to 0x2D for URL alphabet
}
else if ( *cursor == 0x2F )
{
temp |= 0x3F; //change to 0x5F for URL alphabet
}
else if ( *cursor == Base64PadChar ) //pad
{
switch ( encoded.end() - cursor )
{
case 1: //One pad character
outBuf[0] = (temp >> 16) & 0x000000FF;
outBuf[1] = (temp >> 8) & 0x000000FF;
result->write( outBuf, 2 );
return result;
case 2: //Two pad characters
outBuf[0] = (temp >> 10) & 0x000000FF;
result->write( outBuf, 1 );
return result;
default:
throw web::json::json_exception( utility::conversions::to_string_t( "Invalid Padding in Base 64!" ).c_str() );
}
}
else
{
throw web::json::json_exception( utility::conversions::to_string_t( "Non-Valid Character in Base 64!" ).c_str() );
}
++cursor;
}
outBuf[0] = (temp >> 16) & 0x000000FF;
outBuf[1] = (temp >> 8) & 0x000000FF;
outBuf[2] = (temp) & 0x000000FF;
result->write( outBuf, 3 );
}
return result;
}
}
}
}
}