summaryrefslogtreecommitdiff
path: root/src/components/smart_objects/include/smart_objects/smart_object.h
blob: d81e18569f78dd77ac6010cc979f54f86e2ab686 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
/*
 * Copyright (c) 2014, Ford Motor Company
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following
 * disclaimer in the documentation and/or other materials provided with the
 * distribution.
 *
 * Neither the name of the Ford Motor Company nor the names of its contributors
 * may be used to endorse or promote products derived from this software
 * without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef SRC_COMPONENTS_SMART_OBJECTS_INCLUDE_SMART_OBJECTS_SMART_OBJECT_H_
#define SRC_COMPONENTS_SMART_OBJECTS_INCLUDE_SMART_OBJECTS_SMART_OBJECT_H_

#include <set>
#include <string>
#include <vector>
#include <map>

#include "smart_objects/smart_schema.h"
#include "utils/custom_string.h"
#include "rpc_base/validation_report.h"

namespace NsSmartDeviceLink {
namespace NsSmartObjects {

namespace custom_str = utils::custom_string;

class SmartObject;

/**
 * @brief Enumeration with all types, supported by SmartObject
 **/
enum SmartType {
  /**
   * @brief Null value. Act as initial value.
   **/
  SmartType_Null = 0,

  /**
   * @brief Boolean value.
   **/
  SmartType_Boolean = 1,

  /**
   * @brief Integer value.
   **/
  SmartType_Integer = 2,

  /**
   * @brief Character value.
   **/
  SmartType_Character = 3,

  /**
   * @brief String value.
   **/
  SmartType_String = 4,

  /**
   * @brief Double value.
   **/
  SmartType_Double = 5,

  /**
   * @brief Map value. Gives possibility for object to act like hashtable.
   **/
  SmartType_Map = 6,

  /**
   * @brief Array value. Gives possibility for object to act like array.
   **/
  SmartType_Array = 7,

  /**
   * @brief Binary data value. Gives possibility for object to store binary
   *data.
   **/
  SmartType_Binary = 8,

  /**
   * @brief Unsigned Integer value.
   **/
  SmartType_UInteger = 9,

  /**
   * @brief Invalid value. Represents invalid object that cannot change his
   *type.
   **/
  SmartType_Invalid = -1
};

/**
 * @brief SmartArray type
 **/
typedef std::vector<SmartObject> SmartArray;

/**
 * @brief SmartMap type
 **/
typedef std::map<std::string, SmartObject> SmartMap;

/**
 * @brief SmartBinary type
 **/
typedef std::vector<uint8_t> SmartBinary;

typedef std::shared_ptr<SmartObject> SmartObjectSPtr;

/**
 * @brief List of SmartObjects
 */
typedef std::vector<SmartObjectSPtr> SmartObjectList;

/**
 * @brief Main SmartObject class
 *
 * This class act as Variant type from other languages and can be used as
 *primitive type
 * like bool, int32_t, char, double, string and as complex type like array and
 *map.
 **/

class SmartObject FINAL {
 public:
  /**
   * @brief Constructor.
   *
   * Creates object with Null type.
   **/
  SmartObject();

  /**
   * @brief Copy constructor.
   *
   * @param Other Object to be copied from.
   **/
  SmartObject(const SmartObject& Other);

  /**
   * @brief Constructor for avoid cast
   * from unknown type
   *
   * @param pointer
   **/
  template <typename UnknownType>
  SmartObject(const UnknownType&);

  /**
   * @brief Constructor for creating object of given primitive type.
   *
   * Only primitive types (bool, int32_t, char, double, string) are supported.
   *
   * @param type Type of the created object.
   **/
  explicit SmartObject(SmartType Type);

  /**
   * @brief Destructor
   *
   **/
  ~SmartObject();

  /**
   * @brief Assignment operator.
   *
   * @param  Other Other SmartObject
   * @return SmartObject&
   **/
  SmartObject& operator=(const SmartObject& Other);

  /**
   * @brief Comparison operator
   *
   * @param  Other Other SmartObject to be compared with
   * @return bool Result of comparison
   **/
  bool operator==(const SmartObject& Other) const;

  /**
   * @name Support of type: int32_t
   * @{
   */
  /**
   * @brief Constructor for creating object of type: int32_t
   *
   * @param InitialValue Initial object value
   **/
  explicit SmartObject(const int32_t InitialValue);

  /**
   * @brief Returns current object converted to int64_t
   *
   * @return int64_t
   **/
  int64_t asInt() const;

  /**
   * @brief Assignment operator for type: int32_t
   *
   * @param  NewValue New object value
   * @return SmartObject&
   **/
  SmartObject& operator=(const int32_t NewValue);

  /**
   * @brief Comparison operator for comparing object with integer value
   *
   * @param  Value Value to compare object with
   * @return bool
   **/
  bool operator==(const int32_t Value) const;

  // Support of type: uint32_t
  /**
   * @brief Constructor for creating object of type: int32_t
   *
   * @param InitialValue Initial object value
   **/
  explicit SmartObject(const uint32_t InitialValue);

  /**
   * @brief Returns current object converted to uint64_t
   *
   * @return uint64_t
   **/
  uint64_t asUInt() const;

  /**
   * @brief Assignment operator for type: int32_t
   *
   * @param  NewValue New object value
   * @return SmartObject&
   **/
  SmartObject& operator=(const uint32_t NewValue);

  /**
   * @brief Comparison operator for comparing object with uint32_t value
   *
   * @param  Value Value to compare object with
   * @return bool
   **/
  bool operator==(const uint32_t Value) const;

  /**
   * @name Support of type: int64_t
   * @{
   */
  /**
   * @brief Constructor for creating object of type: int64_t
   *
   * @param InitialValue Initial object value
   **/
  explicit SmartObject(const int64_t InitialValue);

  /**
   * @brief Returns current object converted to int64_t
   *
   * @return int64_t
   **/
  int64_t asInt64() const;

  /**
   * @brief Assignment operator for type: int64_t
   *
   * @param  NewValue New object value
   * @return SmartObject&
   **/
  SmartObject& operator=(const int64_t NewValue);

  /**
   * @brief Comparison operator for comparing object with integer value
   *
   * @param  Value Value to compare object with
   * @return bool
   **/
  bool operator==(const int64_t Value) const;

  /**
    * @name Support of type: uint64_t
    * @{
   **/

  /**
   * @brief Assignment operator for type: uint64_t
   *
   * @param  NewValue New object value
   * @return SmartObject&
   **/
  SmartObject& operator=(const uint64_t NewValue);

  /** @} */

  /**
   * @name Support of type: double
   * @{
   */
  /**
   * @brief Constructor for creating object of type: double
   *
   * @param InitialValue Initial object value
   **/
  explicit SmartObject(double InitialValue);

  /**
   * @brief Returns current object converted to double
   *
   * @return double
   **/
  double asDouble() const;

  /**
   * @brief Assignment operator for type: double
   *
   * @param  new_value New object value
   * @return SmartObject&
   **/
  SmartObject& operator=(double new_value);

  /**
   * @brief Comparison operator for comparing object with double value
   *
   * @param  new_value Value to compare object with
   * @return bool
   **/
  bool operator==(double new_value) const;
  /** @} */

  /**
   * @name Support of type: bool
   * @{
   */
  /**
   * @brief Constructor for creating object of type: bool
   *
   * @param InitialValue Initial object value
   **/
  explicit SmartObject(bool InitialValue);

  /**
   * @brief Returns current object converted to bool
   *
   * @return bool
   **/
  bool asBool() const;

  /**
   * @brief Assignment operator for type: bool
   *
   * @param  NewValue New object value
   * @return SmartObject&
   **/
  SmartObject& operator=(bool NewValue);

  /**
   * @brief Comparison operator for comparing object with bool value
   *
   * @param  Value Value to compare object with
   * @return bool
   **/
  bool operator==(bool Value) const;
  /** @} */

  /**
   * @name Support of type: char
   * @{
   */
  /**
   * @brief Constructor for creating object of type: char
   *
   * @param InitialValue Initial object value
   **/
  explicit SmartObject(char InitialValue);

  /**
   * @brief Returns current object converted to char
   *
   * @return char
   **/
  char asChar() const;

  /**
   * @brief Assignment operator for type: char
   *
   * @param  NewValue New object value
   * @return SmartObject&
   **/
  SmartObject& operator=(char NewValue);

  /**
   * @brief Comparison operator for comparing object with char value
   *
   * @param  Value Value to compare object with
   * @return bool
   **/
  bool operator==(char Value) const;
  /** @} */

  /**
   * @name Support of type: string
   * @{
   */
  /**
   * @brief Constructor for creating object of type: string
   *
   * @param InitialValue Initial object value
   **/
  explicit SmartObject(const std::string& InitialValue);

  /**
   * @brief Constructor for creating object of type: CustomString
   *
   * @param InitialValue Initial object value
   **/
  explicit SmartObject(const custom_str::CustomString& InitialValue);

  /**
   * @brief Constructor for creating object of type: string
   *
   * @param InitialValue Initial object value
   **/
  explicit SmartObject(const char* InitialValue);

  /**
   * @brief Returns current object converted to CustomString
   *
   * @return custom_str::CustomString
   **/
  custom_str::CustomString asCustomString() const;

  /**
   * @brief Returns current object converted to string
   *
   * @return std::string
   **/
  std::string asString() const;

  /**
   * @brief Returns char array from SmartObject data if exist. Otherwise returns
   *        empty string
   *
   * @return const char*
   **/
  const char* asCharArray() const;

  /**
   * @brief Assignment operator for type: CustomString
   *
   * @param  NewValue New object value
   * @return SmartObject&
   **/
  SmartObject& operator=(const custom_str::CustomString& NewValue);

  /**
   * @brief Assignment operator for type: string
   *
   * @param  NewValue New object value
   * @return SmartObject&
   **/
  SmartObject& operator=(const std::string& NewValue);

  /**
   * @brief Assignment operator for type: string
   *
   * @param  NewValue New object value
   * @return SmartObject&
   **/
  SmartObject& operator=(const char* NewValue);

  /**
   * @brief Comparison operator for comparing object with string value
   *
   * @param  Value Value to compare object with
   * @return bool
   **/
  bool operator==(const std::string& Value) const;

  /**
   * @brief Comparison operator for comparing object with string value
   *
   * @param  Value Value to compare object with
   * @return bool
   **/
  bool operator==(const char* Value) const;
  /** @} */

  /**
   * @name Support of type: binary
   * @{
   */
  /**
   * @brief Constructor for creating object of type: binary
   *
   * @param InitialValue Initial binary value
   **/
  explicit SmartObject(const SmartBinary& InitialValue);

  /**
   * @brief Returns current object converted to binary
   *
   * @return SmartBinary
   **/
  SmartBinary asBinary() const;

  /**
   * @brief Returns current object converted to array
   *
   * @return SmartArray
   **/
  SmartArray* asArray() const;

  /**
   * @brief Assignment operator for type: binary
   *
   * @param  NewValue New object value
   * @return SmartObject&
   **/
  SmartObject& operator=(const SmartBinary&);

  /**
   * @brief Comparison operator for comparing object with binary value
   *
   * @param  Value Value to compare object with
   * @return bool
   **/
  bool operator==(const SmartBinary&) const;
  /** @} */

  /**
   * @name Array interface support
   * @{
   */
  /**
   * @brief Support of array-like access
   *
   * @param  Index index of element to return, on -1 create new element at end
   * @return SmartObject&
   **/
  SmartObject& operator[](int32_t Index);
  const SmartObject& operator[](int32_t Index) const;

  /**
   * @brief Get array element.
   *
   * This method does not automatically convert the object to an array or
   * add elements. If this object is not an array or index is out of
   * range then null object is returned.
   *
   * @param Index Index of an element.
   *
   * @return Element of array or null object if element can't be provided.
   **/
  const SmartObject& getElement(size_t Index) const;
  /** @} */

  /**
   * @name Map/Hashtable interface support
   * @{
   */
  /**
   * @brief Support of map-like access
   *
   * @param  Key Key of element to return
   * @return SmartObject&
   **/
  SmartObject& operator[](const std::string& Key);
  const SmartObject& operator[](const std::string& Key) const;

  /**
   * @brief Support of map-like access
   *
   * @param  Key Key of element to return
   * @return SmartObject&
   **/
  SmartObject& operator[](char* Key);
  const SmartObject& operator[](char* Key) const;

  /**
   * @brief Support of map-like access
   *
   * @param  Key Key of element to return
   * @return SmartObject&
   **/
  SmartObject& operator[](const char* Key);

  /**
   * @brief Support of map-like access
   *
   * @param  Key Key of element to return
   * @return const SmartObject&
   **/
  const SmartObject& operator[](const char* Key) const;

  /**
   * @brief Get map element.
   *
   * This method does not automatically convert the object to a map or
   * add elements. If this object is not a map or it does not contain
   * key then invalid object is returned.
   *
   * @param Key Key of an element.
   *
   * @return Element of map or null object if element can't be provided.
   **/
  const SmartObject& getElement(const std::string& Key) const;

  /**
   * @brief Enumerates content of the object when it behaves like a map.
   *
   * @return Set of map keys or empty set if object has type other than map
   **/
  std::set<std::string> enumerate() const;

  SmartMap::iterator map_begin() const {
    DCHECK(m_type == SmartType_Map);
    return m_data.map_value->begin();
  }
  SmartMap::iterator map_end() const {
    DCHECK(m_type == SmartType_Map);
    return m_data.map_value->end();
  }

  /**
   * @brief Checks for key presense when object is behaves like a map
   *
   * @param Key Key to check presense for
   * @return bool
   **/
  bool keyExists(const std::string& Key) const;

  /**
   * @brief Removes element from the map.
   *
   * @param Key Key of the element.
   *
   * @return true if success, false if there is no such element in the map
   */
  bool erase(const std::string& Key);
  /** @} */

  /**
   * @name Validation and schema support
   * @{
   */
  /**
   * @brief Validates object according to attached schema.
   *
   * @return bolean validation result
   **/
  bool isValid() const;

  /**
   * @deprecated
   * @brief Validates object according to attached schema.
   *
   * @return Result of validation.
   */
  DEPRECATED Errors::eType validate();

  /**
   * @brief Validates object according to attached schema.
   *
   * @param report__ object for reporting errors during validation
   * @param messageVersion of the mobile app to check against RPC Spec Schema
   * @return Result of validation.
   */
  Errors::eType validate(
      rpc::ValidationReport* report__,
      const utils::SemanticVersion& MessageVersion = utils::SemanticVersion());

  /**
   * @brief Sets new schema
   *
   * @param schema Schema for object validation
   * @return void
   **/
  void setSchema(const CSmartSchema& schema);

  /**
   * @brief Returns attached schema
   *
   * @return CSmartSchema
   **/
  CSmartSchema getSchema();

  /**
   * @brief Returns current object type
   *
   * @return NsSmartObjects::SmartType
   **/
  SmartType getType() const;

  /**
   * @brief Returns length of object
   *
   * If object has type string, array or map then method returns corresponded
   * size. Otherwise returns zero.
   *
   * @return size_t Length of the object
   **/
  size_t length() const;

  /**
   * @brief Object string/array/map/binary empty state
   *
   * @return Returns object string/array/map/binary empty state
   * or true on other object typed
   **/
  bool empty() const;

  /**
   * @brief Nequation template operator
   *
   * @param  Other value to be compared with
   * @return bool Result of nequation
   **/
  template <typename Type>
  bool operator!=(const Type& Other) const {
    return !(*this == Other);
  }

  static std::string typeToString(SmartType type) {
    switch (type) {
      case SmartType_Null:
        return "Null";
      case SmartType_Boolean:
        return "Boolean";
      case SmartType_Integer:
        return "Integer";
      case SmartType_Character:
        return "Character";
      case SmartType_String:
        return "String";
      case SmartType_Double:
        return "Double";
      case SmartType_Map:
        return "Object";
      case SmartType_Array:
        return "Array";
      case SmartType_Binary:
        return "Binary_Data";
      case SmartType_UInteger:
        return "Unsigned_Integer";
      case SmartType_Invalid:
        return "Invalid_Type";
      default:
        return "Unknown_Type";
    }
  }

 protected:
  static std::string OperatorToTransform(const SmartMap::value_type& pair);
  /**
   * @name Support of type: int32_t (internal)
   * @{
   */
  /**
   * @brief Sets new integer value to the object.
   *
   * This method changes also internal object type
   *
   * @param  NewValue New object value
   * @return void
   **/
  inline void set_value_integer(int64_t NewValue);

  /**
   * @brief Converts object to int32_t type
   *
   * @return int32_t Converted value or invalid_int_value if conversion not
   *possible
   **/
  inline int64_t convert_int() const;
  /** @} */

  /**
   * @name Support of type: char (internal)
   * @{
   */
  /**
   * @brief Sets new char value to the object.
   *
   * This method changes also internal object type
   *
   * @param  NewValue New object value
   * @return void
   **/
  inline void set_value_char(char NewValue);

  /**
   * @brief Converts object to char type
   *
   * @return int32_t Converted value or invalid_char_value if conversion not
   *possible
   **/
  inline char convert_char() const;
  /** @} */

  /**
   * @name Support of type: double (internal)
   * @{
   */
  /**
   * @brief Sets new double value to the object.
   *
   * This method changes also internal object type
   *
   * @param  NewValue New object value
   * @return void
   **/
  inline void set_value_double(double NewValue);

  /**
   * @brief Converts object to double type
   *
   * @return int32_t Converted value or invalid_double_value if conversion not
   *possible
   **/
  inline double convert_double() const;
  /** @} */

  /**
   * @name Support of type: bool (internal)
   * @{
   */
  /**
   * @brief Sets new bool value to the object.
   *
   * This method changes also internal object type
   *
   * @param  NewValue New object value
   * @return void
   **/
  inline void set_value_bool(bool NewValue);

  /**
   * @brief Converts object to bool type
   *
   * @return int32_t Converted value or invalid_bool_value if conversion not
   *possible
   **/
  inline bool convert_bool() const;
  /** @} */

  /**
   * @brief Sets new string value to the object.
   *
   * This method changes also internal object type
   *
   * @param  NewValue New object value
   * @return void
   **/
  inline void set_value_string(const custom_str::CustomString& NewValue);

  /**
   * @brief Sets new CustomString value to the object.
   *
   * This method changes also internal object type
   *
   * @param  NewValue New object value
   * @return void
   **/
  inline void set_value_cstr(const char* NewValue);

  /**
   * @brief Converts object to string type
   *
   * @return int32_t Converted value or invalid_string_value if conversion not
   *possible
   **/
  inline std::string convert_string() const;
  /** @} */

  /**
   * @brief Converts object to CustomString type
   *
   * @return CustomString Converted value or
   * invalid_string_value if conversion not possible
   **/
  inline custom_str::CustomString convert_custom_string() const;

  /**
   * @name Support of type: binary (internal)
   * @{
   */
  /**
   * @brief Sets new binary value to the object.
   *
   * This method changes also internal object type
   *
   * @param  NewValue New object value
   * @return void
   **/
  inline void set_value_binary(const SmartBinary& NewValue);

  /**
   * @brief Converts object to binary type
   *
   * @return int32_t Converted value or invalid_binary_value if conversion not
   *possible
   **/
  inline SmartBinary convert_binary() const;

  /**
   * @brief Returns SmartObject from internal array data by it's index
   *
   * @param Index Index of element to retrieve
   * @return SmartObject&
   **/
  SmartObject& handle_array_access(const int32_t Index);

  /**
   * @brief Returns SmartObject from internal map data by it's key
   *
   * @param Key Key of element to retrieve
   * @return SmartObject&
   **/
  inline SmartObject& handle_map_access(const std::string& Key);

  /**
   * @brief Converts string to double
   *
   * @param Value Pointer to string to convert
   * @return double
   **/
  static double convert_string_to_double(const custom_str::CustomString* Value);

  /**
   * @brief Converts string to int64_t
   *
   * @param Value Pointer to string to convert
   * @return int64_t int64_t
   **/
  static uint64_t convert_string_to_integer(
      const custom_str::CustomString* Value);

  /**
   * @brief Converts double value to string
   *
   * @param Value Value to be converted
   * @return std::string
   **/
  static std::string convert_double_to_string(const double& Value);
  /** @} */

  /**
   * @brief Duplicates another SmartObject
   *
   * After calling that function current SmartObject will have the same
   * type, schema and data, as passed.
   *
   * @param  OtherObject Object to be duplicated
   * @return void
   **/
  void duplicate(const SmartObject& OtherObject);

  /**
   * @brief Cleans up internal data for some types (like string, array or map)
   *
   * @return void
   **/
  void cleanup_data();

  /**
   * @brief Sets new internal type and cleans up if it changes
   *
   * @param NewType New object type
   * @return void
   **/
  void set_new_type(SmartType NewType);

  /**
   * @brief Current type of the object
   **/
  SmartType m_type;

  /**
   * @brief Union for holding actual internal object data
   **/
  typedef union {
    double double_value;
    bool bool_value;
    char char_value;
    int64_t int_value;
    custom_str::CustomString* str_value;
    SmartArray* array_value;
    SmartMap* map_value;
    SmartBinary* binary_value;
  } SmartData;

  /**
   * @brief Current internal object data
   **/
  SmartData m_data;

  /**
   * @brief Validation schema, attached to the object
   **/
  CSmartSchema m_schema;
};

/**
 * @brief Value that is used as invalid value for bool type
 **/
static const bool invalid_bool_value = false;

/**
 * @brief Value that is used as invalid value for int32_t type
 **/
static const int32_t invalid_int_value = -1;
static const uint32_t invalid_unsigned_int_value = 0;
static const int64_t invalid_int64_value = -1;

/**
 * @brief Value that is used as invalid value for char type
 **/
static const char invalid_char_value = 0;

/**
 * @brief Value that is used as invalid value for string type
 **/
static const std::string invalid_string_value = "";

/**
 * @brief Value that is used as invalid value for double type
 **/
static const double invalid_double_value = -1;

/**
 * @brief Value that is used as invalid value for object type
 **/
static SmartObject invalid_object_value(SmartType_Invalid);

/**
 * @brief Value that is used as invalid value for object type
 **/
static const SmartBinary invalid_binary_value;
}  // namespace NsSmartObjects
}  // namespace NsSmartDeviceLink

namespace smart_objects = NsSmartDeviceLink::NsSmartObjects;

#endif  // SRC_COMPONENTS_SMART_OBJECTS_INCLUDE_SMART_OBJECTS_SMART_OBJECT_H_