@@ -27,11 +27,11 @@ namespace sio
27
27
flag_binary,
28
28
flag_array,
29
29
flag_object,
30
- flag_boolean,
31
- flag_null
30
+ flag_boolean,
31
+ flag_null
32
32
};
33
33
34
- virtual ~message (){};
34
+ virtual ~message (){};
35
35
36
36
class list ;
37
37
@@ -42,11 +42,11 @@ namespace sio
42
42
43
43
typedef shared_ptr<message> ptr;
44
44
45
- virtual bool get_bool () const
46
- {
47
- assert (false );
48
- return false ;
49
- }
45
+ virtual bool get_bool () const
46
+ {
47
+ assert (false );
48
+ return false ;
49
+ }
50
50
51
51
virtual int64_t get_int () const
52
52
{
@@ -114,26 +114,26 @@ namespace sio
114
114
message (flag f):_flag(f){}
115
115
};
116
116
117
- class null_message : public message
118
- {
119
- protected:
117
+ class null_message : public message
118
+ {
119
+ protected:
120
120
null_message ()
121
- :message(flag_null)
121
+ :message(flag_null)
122
122
{
123
123
}
124
124
125
- public:
125
+ public:
126
126
static message::ptr create ()
127
127
{
128
128
return ptr (new null_message ());
129
129
}
130
- };
130
+ };
131
131
132
- class bool_message : public message
133
- {
134
- bool _v;
132
+ class bool_message : public message
133
+ {
134
+ bool _v;
135
135
136
- protected:
136
+ protected:
137
137
bool_message (bool v)
138
138
:message(flag_boolean),_v(v)
139
139
{
@@ -149,7 +149,7 @@ namespace sio
149
149
{
150
150
return _v;
151
151
}
152
- };
152
+ };
153
153
154
154
class int_message : public message
155
155
{
@@ -257,7 +257,77 @@ namespace sio
257
257
{
258
258
return ptr (new array_message ());
259
259
}
260
-
260
+
261
+ void push (message::ptr const & message)
262
+ {
263
+ if (message)
264
+ _v.push_back (message);
265
+ }
266
+
267
+ void push (const string& text)
268
+ {
269
+ _v.push_back (string_message::create (text));
270
+ }
271
+
272
+ void push (string&& text)
273
+ {
274
+ _v.push_back (string_message::create (move (text)));
275
+ }
276
+
277
+ void push (shared_ptr<string> const & binary)
278
+ {
279
+ if (binary)
280
+ _v.push_back (binary_message::create (binary));
281
+ }
282
+
283
+ void push (shared_ptr<const string> const & binary)
284
+ {
285
+ if (binary)
286
+ _v.push_back (binary_message::create (binary));
287
+ }
288
+
289
+ void insert (size_t pos,message::ptr const & message)
290
+ {
291
+ _v.insert (_v.begin ()+pos, message);
292
+ }
293
+
294
+ void insert (size_t pos,const string& text)
295
+ {
296
+ _v.insert (_v.begin ()+pos, string_message::create (text));
297
+ }
298
+
299
+ void insert (size_t pos,string&& text)
300
+ {
301
+ _v.insert (_v.begin ()+pos, string_message::create (move (text)));
302
+ }
303
+
304
+ void insert (size_t pos,shared_ptr<string> const & binary)
305
+ {
306
+ if (binary)
307
+ _v.insert (_v.begin ()+pos, binary_message::create (binary));
308
+ }
309
+
310
+ void insert (size_t pos,shared_ptr<const string> const & binary)
311
+ {
312
+ if (binary)
313
+ _v.insert (_v.begin ()+pos, binary_message::create (binary));
314
+ }
315
+
316
+ size_t size () const
317
+ {
318
+ return _v.size ();
319
+ }
320
+
321
+ const message::ptr& at (size_t i) const
322
+ {
323
+ return _v[i];
324
+ }
325
+
326
+ const message::ptr& operator [] (size_t i) const
327
+ {
328
+ return _v[i];
329
+ }
330
+
261
331
vector<ptr>& get_vector ()
262
332
{
263
333
return _v;
@@ -280,7 +350,58 @@ namespace sio
280
350
{
281
351
return ptr (new object_message ());
282
352
}
283
-
353
+
354
+ void insert (const string & key,message::ptr const & message)
355
+ {
356
+ _v[key] = message;
357
+ }
358
+
359
+ void insert (const string & key,const string& text)
360
+ {
361
+ _v[key] = string_message::create (text);
362
+ }
363
+
364
+ void insert (const string & key,string&& text)
365
+ {
366
+ _v[key] = string_message::create (move (text));
367
+ }
368
+
369
+ void insert (const string & key,shared_ptr<string> const & binary)
370
+ {
371
+ if (binary)
372
+ _v[key] = binary_message::create (binary);
373
+ }
374
+
375
+ void insert (const string & key,shared_ptr<const string> const & binary)
376
+ {
377
+ if (binary)
378
+ _v[key] = binary_message::create (binary);
379
+ }
380
+
381
+ bool has (const string & key)
382
+ {
383
+ return _v.find (key) != _v.end ();
384
+ }
385
+
386
+ const message::ptr& at (const string & key) const
387
+ {
388
+ static shared_ptr<message> not_found;
389
+
390
+ map<string,message::ptr>::const_iterator it = _v.find (key);
391
+ if (it != _v.end ()) return it->second ;
392
+ return not_found;
393
+ }
394
+
395
+ const message::ptr& operator [] (const string & key) const
396
+ {
397
+ return at (key);
398
+ }
399
+
400
+ bool has (const string & key) const
401
+ {
402
+ return _v.find (key) != _v.end ();
403
+ }
404
+
284
405
map<string,message::ptr>& get_map ()
285
406
{
286
407
return _v;
@@ -315,10 +436,10 @@ namespace sio
315
436
return *this ;
316
437
}
317
438
318
- template <typename T>
319
- list (T&& content,
320
- typename enable_if<is_same<vector<message::ptr>,typename remove_reference<T>::type>::value>::type* = 0 ):
321
- m_vector (std::forward<T>(content))
439
+ template <typename T>
440
+ list (T&& content,
441
+ typename enable_if<is_same<vector<message::ptr>,typename remove_reference<T>::type>::value>::type* = 0 ):
442
+ m_vector (std::forward<T>(content))
322
443
{
323
444
}
324
445
@@ -332,6 +453,7 @@ namespace sio
332
453
{
333
454
if (message)
334
455
m_vector.push_back (message);
456
+
335
457
}
336
458
337
459
list (const string& text)
@@ -360,14 +482,57 @@ namespace sio
360
482
{
361
483
if (message)
362
484
m_vector.push_back (message);
485
+ }
486
+
487
+ void push (const string& text)
488
+ {
489
+ m_vector.push_back (string_message::create (text));
490
+ }
491
+
492
+ void push (string&& text)
493
+ {
494
+ m_vector.push_back (string_message::create (move (text)));
495
+ }
363
496
497
+ void push (shared_ptr<string> const & binary)
498
+ {
499
+ if (binary)
500
+ m_vector.push_back (binary_message::create (binary));
501
+ }
502
+
503
+ void push (shared_ptr<const string> const & binary)
504
+ {
505
+ if (binary)
506
+ m_vector.push_back (binary_message::create (binary));
364
507
}
365
508
366
509
void insert (size_t pos,message::ptr const & message)
367
510
{
368
511
m_vector.insert (m_vector.begin ()+pos, message);
369
512
}
370
513
514
+ void insert (size_t pos,const string& text)
515
+ {
516
+ m_vector.insert (m_vector.begin ()+pos, string_message::create (text));
517
+ }
518
+
519
+ void insert (size_t pos,string&& text)
520
+ {
521
+ m_vector.insert (m_vector.begin ()+pos, string_message::create (move (text)));
522
+ }
523
+
524
+ void insert (size_t pos,shared_ptr<string> const & binary)
525
+ {
526
+ if (binary)
527
+ m_vector.insert (m_vector.begin ()+pos, binary_message::create (binary));
528
+ }
529
+
530
+ void insert (size_t pos,shared_ptr<const string> const & binary)
531
+ {
532
+ if (binary)
533
+ m_vector.insert (m_vector.begin ()+pos, binary_message::create (binary));
534
+ }
535
+
371
536
size_t size () const
372
537
{
373
538
return m_vector.size ();
0 commit comments