-
Notifications
You must be signed in to change notification settings - Fork 10
/
tlVariant.h
1538 lines (1331 loc) · 37.2 KB
/
tlVariant.h
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
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
KLayout Layout Viewer
Copyright (C) 2013-2018 Matthias Koefferlein
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef _HDR_tlVariant
#define _HDR_tlVariant
#include "config.h"
#include <string>
#include <vector>
#include <map>
#include <stdexcept>
#include "tlAssert.h"
namespace tl
{
class Extractor;
template <class T> KLAYOUT_DLL void extractor_impl (tl::Extractor &, T &);
template<class T> std::string to_string (const T &o);
/**
* @brief A base class which describes a class, i.e. an object capable of converting and handling void *
*
* There must be one particular class object per class. In particular the equality of the
* class object pointer's must indicate that two object's share the same class.
*/
class KLAYOUT_DLL VariantUserClassBase
{
public:
VariantUserClassBase () { }
virtual ~VariantUserClassBase () { }
virtual void *create () const = 0;
virtual void destroy (void *) const = 0;
virtual bool equal (void *, void *) const = 0;
virtual bool less (void *, void *) const = 0;
virtual void *clone (void *) const = 0;
virtual std::string to_string (void *) const = 0;
virtual void read (void *, tl::Extractor &ex) const = 0;
virtual const char *name () const = 0;
virtual unsigned int type_code () const = 0;
};
/**
* @brief A derived class encapsulating a certain user type without the capability to compare
*/
template <class T>
class VariantUserClass
: public VariantUserClassBase
{
public:
VariantUserClass () { }
virtual void *create () const
{
return new T ();
}
virtual void destroy (void *t) const
{
delete (T *)t;
}
// TODO: not implemented to be more generic
virtual bool equal (void *, void *) const { tl_assert (false); return false; }
virtual bool less (void *, void *) const { tl_assert (false); return false; }
virtual void *clone (void *t) const
{
return new T(*(T *)t);
}
std::string to_string (void *t) const { return tl::to_string (*(T *)t); }
void read (void *, tl::Extractor &ex) const { }
const char *name () const { return ""; }
unsigned int type_code () const { return 0; }
T &get (void *t) const { return *(T *)t; }
const T &get (const void *t) const { return *(const T *)t; }
static KLAYOUT_DLL VariantUserClass<T> &instance ()
{
return ms_instance;
}
/**
* @brief DLL local instance
* Use this version instead of instance() in DLL code if T is defined inside the DLL
*/
static VariantUserClass<T> &dll_local_instance ()
{
return ms_instance;
}
private:
static VariantUserClass<T> ms_instance;
};
template <class T> VariantUserClass<T> VariantUserClass<T>::ms_instance;
/**
* @brief A class providing an equality operator
*/
template <class T>
class VariantUserClassWithEqual
: public VariantUserClass<T>
{
public:
VariantUserClassWithEqual () : VariantUserClass<T> () { }
virtual bool equal (void *a, void *b) const
{
return *(const T *)a == *(const T *)b;
}
static KLAYOUT_DLL VariantUserClassWithEqual<T> &instance ()
{
return ms_instance;
}
/**
* @brief DLL local instance
* Use this version instead of instance() in DLL code if T is defined inside the DLL
*/
static VariantUserClassWithEqual<T> &dll_local_instance ()
{
return ms_instance;
}
private:
static VariantUserClassWithEqual<T> ms_instance;
};
template <class T> VariantUserClassWithEqual<T> VariantUserClassWithEqual<T>::ms_instance;
/**
* @brief A class providing an equality operator
*/
template <class T>
class VariantUserClassWithEqualAndLess
: public VariantUserClassWithEqual<T>
{
public:
VariantUserClassWithEqualAndLess () : VariantUserClassWithEqual<T> () { }
virtual bool less (void *a, void *b) const
{
return *(const T *)a < *(const T *)b;
}
static KLAYOUT_DLL VariantUserClassWithEqualAndLess<T> &instance ()
{
return ms_instance;
}
/**
* @brief DLL local instance
* Use this version instead of instance() in DLL code if T is defined inside the DLL
*/
static VariantUserClassWithEqualAndLess<T> &dll_local_instance ()
{
return ms_instance;
}
private:
static VariantUserClassWithEqualAndLess<T> ms_instance;
};
template <class T> VariantUserClassWithEqualAndLess<T> VariantUserClassWithEqualAndLess<T>::ms_instance;
void register_variant_complex_type (const VariantUserClassBase *cls, unsigned int type, const char *name);
/**
* @brief A class providing everything required for the complex types
*/
template <class T>
class VariantComplexTypeClass
: public VariantUserClassWithEqualAndLess<T>
{
public:
VariantComplexTypeClass (unsigned int t, const char *name)
: VariantUserClassWithEqualAndLess<T> (), m_type_code (t), mp_name (name)
{
register_variant_complex_type (this, t, name);
}
void read (void *t, tl::Extractor &ex) const
{
extractor_impl<T> (ex, *(T* )t);
}
unsigned int type_code () const
{
return m_type_code;
}
const char *name () const
{
return mp_name;
}
static KLAYOUT_DLL VariantComplexTypeClass<T> &instance ()
{
return ms_instance;
}
/**
* @brief DLL local instance
* Use this version instead of instance() in DLL code if T is defined inside the DLL
*/
static VariantComplexTypeClass<T> &dll_local_instance ()
{
return ms_instance;
}
private:
static VariantComplexTypeClass<T> ms_instance;
unsigned int m_type_code;
const char *mp_name;
};
/**
* @brief A basic variant type
*
* This variant is capable of storing long, double, std::string, void (nil) and lists
* of other variants.
*/
class KLAYOUT_DLL Variant
{
public:
enum type {
t_nil,
t_bool,
t_char,
t_schar,
t_uchar,
t_short,
t_ushort,
t_int,
t_uint,
t_long,
t_ulong,
t_longlong,
t_ulonglong,
t_id,
t_float,
t_double,
t_string,
t_stdstring,
t_list,
t_array,
// "complex types": these are types which are basically predefined user types.
// Access to such values is only provided through the to_user<T> method.
t_complex_first,
t_point, // -> db::Point
t_dpoint, // -> db::DPoint
t_box, // -> db::Box
t_dbox, // -> db::DBox
t_edge, // -> db::Edge
t_dedge, // -> db::DEdge
t_vector, // -> db::Vector
t_dvector, // -> db::DVector
t_polygon, // -> db::Polygon
t_dpolygon, // -> db::DPolygon
t_path, // -> db::Path
t_dpath, // -> db::DPath
t_layer, // -> db::LayerProperties
// "real" user types
t_user
};
typedef std::vector<tl::Variant>::const_iterator const_iterator;
typedef std::vector<tl::Variant>::iterator iterator;
typedef std::map<tl::Variant, tl::Variant> array_type;
typedef array_type::const_iterator const_array_iterator;
typedef array_type::iterator array_iterator;
/**
* @brief Initialize the Variant with "nil"
*/
Variant ();
/**
* @brief Copy ctor
*/
Variant (const tl::Variant &d);
/**
* @brief Initialize the Variant with "string"
*/
Variant (const std::string &s);
/**
* @brief Initialize the Variant with "string"
*/
Variant (const char *s);
/**
* @brief Initialize the Variant with "double"
*/
Variant (double d);
/**
* @brief Initialize the Variant with "float"
*/
Variant (float d);
/**
* @brief Initialize the Variant with "char"
*/
Variant (char c);
/**
* @brief Initialize the Variant with "signed char"
*/
Variant (signed char c);
/**
* @brief Initialize the Variant with "unsigned char"
*/
Variant (unsigned char c);
/**
* @brief Initialize the Variant with "short"
*/
Variant (short s);
/**
* @brief Initialize the Variant with "unsigned short"
*/
Variant (unsigned short s);
/**
* @brief Initialize the Variant with "bool"
*/
Variant (bool l);
/**
* @brief Initialize the Variant with "int" (actually "long")
*/
Variant (int l);
/**
* @brief Initialize the Variant with "unsigned int" (actually "unsigned long")
*/
Variant (unsigned int l);
/**
* @brief Initialize the Variant with "long"
*/
Variant (long l);
/**
* @brief Initialize the Variant with "unsigned long"
*/
Variant (unsigned long l);
/**
* @brief Initialize the Variant with "long long"
*/
Variant (long long l);
/**
* @brief Initialize the Variant with "unsigned long long"
*/
Variant (unsigned long long l);
/**
* @brief Initialize the Variant with an "id"
*
* The "id" type is basically a size_t, but is supposed to be used as a representative for another value.
* One application for that type is a placeholder for an OASIS name until it is associated with a real value.
*/
Variant (size_t l, bool /*dummy*/);
/**
* @brief Initialize with a user type based on VariantUserBase
*
* The Variant will take over the ownership over the VariantUserBase object.
*/
Variant (unsigned int utype, void *object, const VariantUserClassBase *cls)
: m_type (type (t_user + utype)), m_string (0)
{
m_var.mp_user.object = object;
m_var.mp_user.cls = cls;
}
/**
* @brief Initialize with a complex type
*/
template <class T>
Variant (const T &obj)
: m_string (0)
{
m_type = (tl::Variant::type) VariantComplexTypeClass<T>::instance ().type_code ();
m_var.mp_user.object = new T (obj);
m_var.mp_user.cls = &VariantComplexTypeClass<T>::instance ();
}
/**
* @brief Initialize the Variant with a list
*/
template <class Iter>
Variant (Iter from, Iter to)
: m_type (t_list), m_string (0)
{
m_var.m_list = new std::vector<tl::Variant> (from, to);
}
/**
* @brief Destructor
*/
~Variant ();
/**
* @brief Assignment
*/
Variant &operator= (const Variant &v);
/**
* @brief Assignment of a string
*/
Variant &operator= (const char *v);
/**
* @brief Assignment of a string
*/
Variant &operator= (const std::string &v);
/**
* @brief Assignment of a double
*/
Variant &operator= (double d);
/**
* @brief Assignment of a float
*/
Variant &operator= (float d);
/**
* @brief Assignment of a bool
*/
Variant &operator= (bool l);
/**
* @brief Assignment of a char
*/
Variant &operator= (char l);
/**
* @brief Assignment of an unsigned char
*/
Variant &operator= (unsigned char c);
/**
* @brief Assignment of a signed char
*/
Variant &operator= (signed char c);
/**
* @brief Assignment of a short
*/
Variant &operator= (short s);
/**
* @brief Assignment of an unsigned char
*/
Variant &operator= (unsigned short s);
/**
* @brief Assignment of a int
*/
Variant &operator= (int l);
/**
* @brief Assignment of a unsigned int
*/
Variant &operator= (unsigned int l);
/**
* @brief Assignment of a long
*/
Variant &operator= (long l);
/**
* @brief Assignment of a unsigned long
*/
Variant &operator= (unsigned long l);
/**
* @brief Assignment of a long long
*/
Variant &operator= (long long l);
/**
* @brief Assignment of a unsigned long long
*/
Variant &operator= (unsigned long long l);
/**
* @brief Reset to nil
*/
void reset ();
/**
* @brief Initialize with a user type
*/
void set_user (unsigned int utype, void *object, const VariantUserClassBase *cls)
{
reset ();
m_type = type (t_user + utype);
m_var.mp_user.object = object;
m_var.mp_user.cls = cls;
}
/**
* @brief Initialize with a complex type
*/
void set_complex (type t, void *object, const VariantUserClassBase *cls)
{
reset ();
m_type = t;
m_var.mp_user.object = object;
m_var.mp_user.cls = cls;
}
/**
* @brief Initialize with a complex type
*/
template <class T>
void set_complex (const T &obj)
{
reset ();
m_type = (tl::Variant::type) VariantComplexTypeClass<T>::instance ().type_code ();
m_var.mp_user.object = new T (obj);
m_var.mp_user.cls = &VariantComplexTypeClass<T>::instance ();
}
/**
* @brief Initialize with an empty list with the given reserve
*/
void set_list (size_t reserve = 0)
{
reset ();
m_type = t_list;
m_var.m_list = new std::vector<tl::Variant> ();
if (reserve > 0) {
m_var.m_list->reserve (reserve);
}
}
/**
* @brief Initialize with an empty array
*/
void set_array ()
{
reset ();
m_type = t_array;
m_var.m_array = new std::map<tl::Variant, tl::Variant> ();
}
/**
* @brief Equality
*
* For user types, this is not implemented yet.
*/
bool operator== (const Variant &d) const;
/**
* @brief Inequality
*
* For user types, this is not implemented yet.
*/
bool operator!= (const Variant &d) const
{
return !operator== (d);
}
/**
* @brief Comparison
*
* For user types, this is not implemented yet.
*/
bool operator< (const Variant &d) const;
/**
* @brief Conversion to a string
*
* This performs the conversion to a string as far as possible.
* No conversion is provided to user types currently.
*/
const char *to_string () const;
/**
* @brief Conversion to a std::string
*
* This performs the conversion to a std::string as far as possible.
* No conversion is provided to user types currently.
*/
std::string to_stdstring () const;
/**
* @brief Conversion to a unsigned long long
*
* This performs the conversion to a unsigned long long as far as possible.
* No conversion is provided to user types currently.
*/
unsigned long long to_ulonglong () const;
/**
* @brief Conversion to a long long
*
* This performs the conversion to a long long as far as possible.
* No conversion is provided to user types currently.
*/
long long to_longlong () const;
/**
* @brief Conversion to a unsigned int
*
* This performs the conversion to a unsigned int as far as possible.
* No conversion is provided to user types currently.
*/
unsigned int to_uint () const;
/**
* @brief Conversion to a int
*
* This performs the conversion to a int as far as possible.
* No conversion is provided to user types currently.
*/
int to_int () const;
/**
* @brief Conversion to a unsigned long
*
* This performs the conversion to a unsigned long as far as possible.
* No conversion is provided to user types currently.
*/
unsigned long to_ulong () const;
/**
* @brief Conversion to a long
*
* This performs the conversion to a long as far as possible.
* No conversion is provided to user types currently.
*/
long to_long () const;
/**
* @brief Conversion to a unsigned long
*
* This performs the conversion to a unsigned short as far as possible.
* No conversion is provided to user types currently.
*/
unsigned short to_ushort () const;
/**
* @brief Conversion to a short
*
* This performs the conversion to a short as far as possible.
* No conversion is provided to user types currently.
*/
short to_short () const;
/**
* @brief Conversion to a signed char
*
* This performs the conversion to a signed char as far as possible.
* No conversion is provided to user types currently.
*/
signed char to_schar () const;
/**
* @brief Conversion to a unsigned char
*
* This performs the conversion to an unsigned char as far as possible.
* No conversion is provided to user types currently.
*/
unsigned char to_uchar () const;
/**
* @brief Conversion to a char
*
* This performs the conversion to a char as far as possible.
* No conversion is provided to user types currently.
*/
char to_char () const;
/**
* @brief Conversion to an id
*
* This gets the id value if the variant is an id.
* No conversion is provided to user types currently.
*/
size_t to_id () const;
/**
* @brief Conversion to a bool
*
* This performs the conversion to a bool as far as possible.
* No conversion is provided to user types currently.
*/
bool to_bool () const;
/**
* @brief Conversion to a double
*
* This performs the conversion to a double value as far as possible.
* No conversion is provided to user types currently.
*/
double to_double () const;
/**
* @brief Conversion to a float
*
* This performs the conversion to a float value as far as possible.
* No conversion is provided to user types currently.
*/
float to_float () const;
/**
* @brief conversion to a standard type
*
* This is a templatized version of the various to_... methods. This
* does also not include conversion to a user type.
* This is the generic version. Specializations follow.
*/
template <class T>
T to () const
{
tl_assert (false);
}
/**
* @brief Convert to the user object
*/
void *to_user_object ()
{
return m_var.mp_user.object;
}
/**
* @brief Convert to the user object (const)
*/
const void *to_user_object () const
{
return m_var.mp_user.object;
}
/**
* @brief Get the user object's class
*/
const VariantUserClassBase *user_cls () const
{
return m_var.mp_user.cls;
}
/**
* @brief Convert to the given complex type
*/
template <class T>
T &to_complex ()
{
tl_assert (is_complex ());
const VariantUserClass<T> *tcls = dynamic_cast<const VariantUserClass<T> *> (m_var.mp_user.cls);
tl_assert (tcls != 0);
return tcls->get (m_var.mp_user.object);
}
/**
* @brief Convert to the given complex type (const version)
*/
template <class T>
const T &to_complex () const
{
tl_assert (is_complex ());
const VariantUserClass<T> *tcls = dynamic_cast<const VariantUserClass<T> *> (m_var.mp_user.cls);
tl_assert (tcls != 0);
return tcls->get (m_var.mp_user.object);
}
/**
* @brief Convert to the given user type
*/
template <class T>
T &to_user ()
{
tl_assert (is_user ());
const VariantUserClass<T> *tcls = dynamic_cast<const VariantUserClass<T> *> (m_var.mp_user.cls);
tl_assert (tcls != 0);
return tcls->get (m_var.mp_user.object);
}
/**
* @brief Convert to the given user type (const version)
*/
template <class T>
const T &to_user () const
{
tl_assert (is_user ());
const VariantUserClass<T> *tcls = dynamic_cast<const VariantUserClass<T> *> (m_var.mp_user.cls);
tl_assert (tcls != 0);
return tcls->get (m_var.mp_user.object);
}
/**
* @brief Morph to the given type
*
* After morphing the variant, the variant will use the given type internally.
* The native pointer can be used to access the value then.
* A nil value is not morphed and remains nil. In that case, the native pointer will be 0.
*/
template<class T>
tl::Variant &morph ()
{
if (! is_nil ()) {
*this = to<T> ();
}
return *this;
}
/**
* @brief Cast to the given type
*
* This creates a new variant which uses the given type internally
*/
template <class T>
Variant cast () const
{
return Variant (to<T> ());
}
/**
* @brief Access the native (internal) object
*
* For nil, 0 is returned.
*/
void *native_ptr ()
{
// saves one implementation ...
return const_cast<void *> (((const tl::Variant *) this)->native_ptr ());
}
/**
* @brief Access the native (internal) object
*
* For nil, 0 is returned.
*/
const void *native_ptr () const;
/**
* @brief Get the list iterators, if it is one
*/
const_iterator begin () const
{
tl_assert (m_type == t_list);
return m_var.m_list->begin ();
}
/**
* @brief Get the list iterators, if it is one
*/
const_iterator end () const
{
tl_assert (m_type == t_list);
return m_var.m_list->end ();
}
/**
* @brief Get the list iterators, if it is one
*/
iterator begin ()
{
tl_assert (m_type == t_list);
return m_var.m_list->begin ();
}
/**
* @brief Get the list iterators, if it is one
*/
iterator end ()
{
tl_assert (m_type == t_list);
return m_var.m_list->end ();
}
/**
* @brief Reserve some length for a list
*/
void reserve (size_t n)
{
tl_assert (m_type == t_list);
m_var.m_list->reserve (n);
}
/**
* @brief Get the length of the list if there is one, otherwise 0
*/
size_t size () const
{
return m_type == t_list ? m_var.m_list->size () : 0;
}
/**
* @brief Add a element to the list
*/
void push (const tl::Variant &v)
{
tl_assert (m_type == t_list);
m_var.m_list->push_back (v);
}
/**
* @brief Get the back element of the list
*/
tl::Variant &back ()
{
tl_assert (m_type == t_list);
return m_var.m_list->back ();
}
/**
* @brief Get the back element of the list (const)
*/
const tl::Variant &back () const
{
tl_assert (m_type == t_list);
return m_var.m_list->back ();
}
/**
* @brief Get the front element of the list
*/
tl::Variant &front ()
{
tl_assert (m_type == t_list);
return m_var.m_list->front ();
}
/**
* @brief Get the front element of the list (const)
*/
const tl::Variant &front () const
{
tl_assert (m_type == t_list);
return m_var.m_list->front ();
}
/**
* @brief Get the list, if it is one
*/
std::vector<tl::Variant> &get_list ()
{
tl_assert (m_type == t_list);
return *m_var.m_list;
}
/**
* @brief Get the list, if it is one (const)
*/
const std::vector<tl::Variant> &get_list () const
{
tl_assert (m_type == t_list);
return *m_var.m_list;
}
/**
* @brief Get the array iterators, if it is one
*/
const_array_iterator begin_array () const
{
tl_assert (m_type == t_array);
return m_var.m_array->begin ();
}
/**
* @brief Get the array iterators, if it is one