/
TypeObject.h
4276 lines (3521 loc) · 132 KB
/
TypeObject.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
/*
* Distributed under the OpenDDS License.
* See: http://www.opendds.org/license.html
*/
#ifndef OPENDDS_DCPS_XTYPES_TYPE_OBJECT_H
#define OPENDDS_DCPS_XTYPES_TYPE_OBJECT_H
#include "External.h"
#include <dds/DCPS/PoolAllocationBase.h>
#include <dds/DCPS/PoolAllocator.h>
#include <dds/DCPS/Serializer.h>
#include <ace/CDR_Base.h>
#include <algorithm>
#include <cstring>
OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
namespace OpenDDS {
namespace XTypes {
struct TypeInformation;
}
namespace DCPS {
OpenDDS_Dcps_Export
bool operator<<(Serializer& ser, const XTypes::TypeInformation& type_info);
OpenDDS_Dcps_Export
bool operator>>(Serializer& ser, XTypes::TypeInformation& type_info);
}
namespace XTypes {
template<typename T, typename T_slice, typename TAG>
class Fake_TAO_Array_Forany_T {
public:
typedef T_slice _slice_type;
Fake_TAO_Array_Forany_T (_slice_type *p)
: ptr_(p)
{}
typedef const _slice_type * _in_type;
typedef _slice_type * & _out_type;
_in_type in (void) const
{
return (const T_slice *) this->ptr_;
}
_out_type out (void)
{
return this->ptr_;
}
private:
_slice_type * ptr_;
};
OpenDDS_Dcps_Export
const DCPS::Encoding& get_typeobject_encoding();
template <typename T>
class Optional {
public:
Optional()
: present_(false)
, value_()
{}
Optional(const T& v)
: present_(true)
{
new(value_) T(v);
}
~Optional() {
if (present_) {
value().~T();
}
}
Optional(const Optional& rhs)
: present_(false)
, value_()
{
*this = rhs;
}
Optional& operator=(const Optional& rhs) {
if (this != &rhs) {
if (present_) {
if (rhs.present_) {
value() = rhs.value();
} else {
value().~T();
}
} else {
if (rhs.present_) {
new(value_) T(rhs.value());
}
}
present_ = rhs.present_;
}
return *this;
}
bool operator==(const Optional& other) const
{
if (present_) {
return present_ == other.present_ && value() == other.value();
}
return present_ == other.present_;
}
bool operator!=(const Optional& other) const
{
return !(*this == other);
}
operator bool() const {
return present_;
}
bool has_value() const {
return present_;
}
T& value() {
return reinterpret_cast<T&>(value_);
}
const T& value() const {
return reinterpret_cast<const T&>(value_);
}
private:
bool present_;
union {
ACE_CDR::LongDouble max_alignment;
unsigned char value_[sizeof(T)];
};
};
template <typename T>
struct Sequence {
typedef ACE_CDR::ULong size_type;
typedef OPENDDS_VECTOR(T) Members;
Members members;
Sequence& append(const T& member)
{
members.push_back(member);
return *this;
}
Sequence& sort()
{
std::sort(members.begin(), members.end());
return *this;
}
ACE_CDR::ULong length() const
{
return static_cast<ACE_CDR::ULong>(members.size());
}
void length(ACE_CDR::ULong len)
{
return members.resize(len);
}
const T& operator[](ACE_CDR::ULong i) const
{
return members[i];
}
T& operator[](ACE_CDR::ULong i)
{
return members[i];
}
bool operator<(const Sequence& other) const { return members < other.members; }
bool operator==(const Sequence& other) const { return members == other.members; }
bool operator!=(const Sequence& other) const { return members != other.members; }
T* get_buffer() { return &members[0]; }
const T* get_buffer() const { return &members[0]; }
typedef typename Members::const_iterator const_iterator;
const_iterator begin() const { return members.begin(); }
const_iterator end() const { return members.end(); }
};
// Based on dds-xtypes_typeobject.idl
// The types in this file shall be serialized with XCDR encoding version 2
// ---------- Equivalence Kinds -------------------
typedef ACE_CDR::Octet EquivalenceKind;
const EquivalenceKind EK_MINIMAL = 0xF1; // 0x1111 0001
const EquivalenceKind EK_COMPLETE = 0xF2; // 0x1111 0010
const EquivalenceKind EK_BOTH = 0xF3; // 0x1111 0011
// ---------- TypeKinds (begin) -------------------
typedef ACE_CDR::Octet TypeKind;
// Primitive TKs
const TypeKind TK_NONE = 0x00;
const TypeKind TK_BOOLEAN = 0x01;
const TypeKind TK_BYTE = 0x02;
const TypeKind TK_INT16 = 0x03;
const TypeKind TK_INT32 = 0x04;
const TypeKind TK_INT64 = 0x05;
const TypeKind TK_UINT16 = 0x06;
const TypeKind TK_UINT32 = 0x07;
const TypeKind TK_UINT64 = 0x08;
const TypeKind TK_FLOAT32 = 0x09;
const TypeKind TK_FLOAT64 = 0x0A;
const TypeKind TK_FLOAT128 = 0x0B;
const TypeKind TK_INT8 = 0x0C; // XTypes 1.3 Annex B
const TypeKind TK_UINT8 = 0x0D; // XTypes 1.3 Annex B
const TypeKind TK_CHAR8 = 0x10;
const TypeKind TK_CHAR16 = 0x11;
// String TKs
const TypeKind TK_STRING8 = 0x20;
const TypeKind TK_STRING16 = 0x21;
// Constructed/Named types
const TypeKind TK_ALIAS = 0x30;
// Enumerated TKs
const TypeKind TK_ENUM = 0x40;
const TypeKind TK_BITMASK = 0x41;
// Structured TKs
const TypeKind TK_ANNOTATION = 0x50;
const TypeKind TK_STRUCTURE = 0x51;
const TypeKind TK_UNION = 0x52;
const TypeKind TK_BITSET = 0x53;
// Collection TKs
const TypeKind TK_SEQUENCE = 0x60;
const TypeKind TK_ARRAY = 0x61;
const TypeKind TK_MAP = 0x62;
// ---------- TypeKinds (end) -------------------
// ---------- Extra TypeIdentifiers (begin) ------------
typedef ACE_CDR::Octet TypeIdentifierKind;
const TypeIdentifierKind TI_STRING8_SMALL = 0x70;
const TypeIdentifierKind TI_STRING8_LARGE = 0x71;
const TypeIdentifierKind TI_STRING16_SMALL = 0x72;
const TypeIdentifierKind TI_STRING16_LARGE = 0x73;
const TypeIdentifierKind TI_PLAIN_SEQUENCE_SMALL = 0x80;
const TypeIdentifierKind TI_PLAIN_SEQUENCE_LARGE = 0x81;
const TypeIdentifierKind TI_PLAIN_ARRAY_SMALL = 0x90;
const TypeIdentifierKind TI_PLAIN_ARRAY_LARGE = 0x91;
const TypeIdentifierKind TI_PLAIN_MAP_SMALL = 0xA0;
const TypeIdentifierKind TI_PLAIN_MAP_LARGE = 0xA1;
const TypeIdentifierKind TI_STRONGLY_CONNECTED_COMPONENT = 0xB0;
// ---------- Extra TypeIdentifiers (end) --------------
// The name of some element (e.g. type, type member, module)
// Valid characters are alphanumeric plus the "_" cannot start with digit
const ACE_CDR::Long MEMBER_NAME_MAX_LENGTH = 256;
typedef OPENDDS_STRING MemberName;
// Qualified type name includes the name of containing modules
// using "::" as separator. No leading "::". E.g. "MyModule::MyType"
const ACE_CDR::Long TYPE_NAME_MAX_LENGTH = 256;
typedef OPENDDS_STRING QualifiedTypeName;
// Every type has an ID. Those of the primitive types are pre-defined.
typedef ACE_CDR::Octet PrimitiveTypeId;
// First 14 bytes of MD5 of the serialized TypeObject using XCDR
// version 2 with Little Endian encoding
typedef ACE_CDR::Octet EquivalenceHash[14];
struct EquivalenceHash_tag {};
typedef ACE_CDR::Octet EquivalenceHash_slice;
typedef Fake_TAO_Array_Forany_T<EquivalenceHash, EquivalenceHash_slice, EquivalenceHash_tag> EquivalenceHash_forany;
OpenDDS_Dcps_Export DCPS::String equivalence_hash_to_string(const EquivalenceHash& hash);
// First 4 bytes of MD5 of of a member name converted to bytes
// using UTF-8 encoding and without a 'nul' terminator.
// Example: the member name "color" has NameHash {0x70, 0xDD, 0xA5, 0xDF}
typedef ACE_CDR::Octet NameHash[4];
struct NameHash_tag {};
typedef ACE_CDR::Octet NameHash_slice;
typedef Fake_TAO_Array_Forany_T<NameHash, NameHash_slice, NameHash_tag> NameHash_forany;
inline bool name_hash_equal(const NameHash& x, const NameHash& y)
{
return x[0] == y[0] && x[1] == y[1] && x[2] == y[2] && x[3] == y[3];
}
inline bool name_hash_not_equal(const NameHash& x, const NameHash& y)
{
return !name_hash_equal(x, y);
}
// Long Bound of a collection type
typedef ACE_CDR::ULong LBound;
typedef Sequence<LBound> LBoundSeq;
const LBound INVALID_LBOUND = 0;
// Short Bound of a collection type
typedef ACE_CDR::Octet SBound;
typedef Sequence<SBound> SBoundSeq;
const SBound INVALID_SBOUND = 0;
struct EquivalenceHashWrapper { // not in spec
EquivalenceHashWrapper(ACE_CDR::Octet a, ACE_CDR::Octet b, ACE_CDR::Octet c, ACE_CDR::Octet d,
ACE_CDR::Octet e, ACE_CDR::Octet f, ACE_CDR::Octet g, ACE_CDR::Octet h,
ACE_CDR::Octet i, ACE_CDR::Octet j, ACE_CDR::Octet k, ACE_CDR::Octet l,
ACE_CDR::Octet m, ACE_CDR::Octet n)
{
eh_[0] = a; eh_[1] = b; eh_[2] = c; eh_[3] = d; eh_[4] = e; eh_[5] = f; eh_[6] = g;
eh_[7] = h; eh_[8] = i; eh_[9] = j; eh_[10] = k; eh_[11] = l; eh_[12] = m; eh_[13] = n;
}
EquivalenceHash eh_;
};
// union TypeObjectHashId switch (octet) {
// case EK_COMPLETE:
// case EK_MINIMAL:
// EquivalenceHash hash;
// };
struct TypeObjectHashId {
EquivalenceKind kind;
EquivalenceHash hash;
TypeObjectHashId()
: kind(0)
{}
TypeObjectHashId(const EquivalenceKind& a_kind,
const EquivalenceHashWrapper& a_hash)
: kind(a_kind)
{
std::memcpy(hash, a_hash.eh_, sizeof hash);
}
bool operator<(const TypeObjectHashId& other) const
{
if (kind < other.kind) return true;
if (other.kind < kind) return false;
int ret = std::memcmp(hash, other.hash, sizeof hash);
if (ret < 0) return true;
if (ret > 0) return false;
return false;
}
};
// Flags that apply to struct/union/collection/enum/bitmask/bitset
// members/elements and DO affect type assignability
// Depending on the flag it may not apply to members of all types
// When not all, the applicable member types are listed
typedef ACE_CDR::UShort MemberFlag;
const MemberFlag TRY_CONSTRUCT1 = 1 << 0; // T1 | 00 = INVALID, 01 = DISCARD
const MemberFlag TRY_CONSTRUCT2 = 1 << 1; // T2 | 10 = USE_DEFAULT, 11 = TRIM
const MemberFlag IS_EXTERNAL = 1 << 2; // X StructMember, UnionMember,
// CollectionElement
const MemberFlag IS_OPTIONAL = 1 << 3; // O StructMember
const MemberFlag IS_MUST_UNDERSTAND = 1 << 4; // M StructMember
const MemberFlag IS_KEY = 1 << 5; // K StructMember, UnionDiscriminator
const MemberFlag IS_DEFAULT = 1 << 6; // D UnionMember, EnumerationLiteral
typedef MemberFlag CollectionElementFlag; // T1, T2, X
typedef MemberFlag StructMemberFlag; // T1, T2, O, M, K, X
typedef MemberFlag UnionMemberFlag; // T1, T2, D, X
typedef MemberFlag UnionDiscriminatorFlag; // T1, T2, K
typedef MemberFlag EnumeratedLiteralFlag; // D
typedef MemberFlag AnnotationParameterFlag; // Unused. No flags apply
typedef MemberFlag AliasMemberFlag; // Unused. No flags apply
typedef MemberFlag BitflagFlag; // Unused. No flags apply
typedef MemberFlag BitsetMemberFlag; // Unused. No flags apply
const MemberFlag TryConstructDiscardValue = TRY_CONSTRUCT1;
const MemberFlag TryConstructUseDefaultValue = TRY_CONSTRUCT2;
const MemberFlag TryConstructTrimValue = TRY_CONSTRUCT1 | TRY_CONSTRUCT2;
// Mask used to remove the flags that do not affect assignability
// Selects T1, T2, O, M, K, D
const MemberFlag MemberFlagMinimalMask = 0x003f;
// Flags that apply to type declarations and DO affect assignability
// Depending on the flag it may not apply to all types
// When not all, the applicable types are listed
typedef ACE_CDR::UShort TypeFlag;
const TypeFlag IS_FINAL = 1 << 0; // F |
const TypeFlag IS_APPENDABLE = 1 << 1; // A |- Struct, Union
const TypeFlag IS_MUTABLE = 1 << 2; // M | (exactly one flag)
const TypeFlag IS_NESTED = 1 << 3; // N Struct, Union
const TypeFlag IS_AUTOID_HASH = 1 << 4; // H Struct
typedef TypeFlag StructTypeFlag; // All flags apply
typedef TypeFlag UnionTypeFlag; // All flags apply
typedef TypeFlag CollectionTypeFlag; // Unused. No flags apply
typedef TypeFlag AnnotationTypeFlag; // Unused. No flags apply
typedef TypeFlag AliasTypeFlag; // Unused. No flags apply
typedef TypeFlag EnumTypeFlag; // Unused. No flags apply
typedef TypeFlag BitmaskTypeFlag; // Unused. No flags apply
typedef TypeFlag BitsetTypeFlag; // Unused. No flags apply
// Mask used to remove the flags that do no affect assignability
const TypeFlag TypeFlagMinimalMask = 0x0007; // Selects M, A, F
// Forward declaration
class TypeIdentifier;
// 1 Byte
struct StringSTypeDefn {
SBound bound;
StringSTypeDefn()
: bound(0)
{}
explicit StringSTypeDefn(const SBound a_bound)
: bound(a_bound)
{}
bool operator<(const StringSTypeDefn& other) const
{
return bound < other.bound;
}
};
// 4 Bytes
struct StringLTypeDefn {
LBound bound;
StringLTypeDefn()
: bound(0)
{}
explicit StringLTypeDefn(const LBound a_bound)
: bound(a_bound)
{}
bool operator<(const StringLTypeDefn& other) const
{
return bound < other.bound;
}
};
struct PlainCollectionHeader {
EquivalenceKind equiv_kind;
CollectionElementFlag element_flags;
PlainCollectionHeader()
: equiv_kind(0)
, element_flags(0)
{}
PlainCollectionHeader(const EquivalenceKind& a_equiv_kind,
const CollectionElementFlag& a_element_flags)
: equiv_kind(a_equiv_kind)
, element_flags(a_element_flags)
{}
bool operator<(const PlainCollectionHeader& other) const
{
if (equiv_kind < other.equiv_kind) return true;
if (other.equiv_kind < equiv_kind) return false;
if (element_flags < other.element_flags) return true;
if (other.element_flags < element_flags) return false;
return false;
}
};
struct PlainSequenceSElemDefn {
PlainCollectionHeader header;
SBound bound;
External<TypeIdentifier> element_identifier;
PlainSequenceSElemDefn()
: bound(INVALID_SBOUND)
{}
PlainSequenceSElemDefn(const PlainCollectionHeader& a_header,
const SBound& a_bound,
const TypeIdentifier& a_element_identifier)
: header(a_header)
, bound(a_bound)
, element_identifier(a_element_identifier)
{}
bool operator<(const PlainSequenceSElemDefn& other) const;
};
struct PlainSequenceLElemDefn {
PlainCollectionHeader header;
LBound bound;
External<TypeIdentifier> element_identifier;
PlainSequenceLElemDefn()
: bound(INVALID_LBOUND)
{}
PlainSequenceLElemDefn(const PlainCollectionHeader& a_header,
const LBound& a_bound,
const TypeIdentifier& a_element_identifier)
: header(a_header)
, bound(a_bound)
, element_identifier(a_element_identifier)
{}
bool operator<(const PlainSequenceLElemDefn& other) const;
};
struct PlainArraySElemDefn {
PlainCollectionHeader header;
SBoundSeq array_bound_seq;
External<TypeIdentifier> element_identifier;
PlainArraySElemDefn() {}
PlainArraySElemDefn(const PlainCollectionHeader& a_header,
const SBoundSeq& a_array_bound_seq,
const TypeIdentifier& a_element_identifier)
: header(a_header)
, array_bound_seq(a_array_bound_seq)
, element_identifier(a_element_identifier)
{}
bool operator<(const PlainArraySElemDefn& other) const;
};
struct PlainArrayLElemDefn {
PlainCollectionHeader header;
LBoundSeq array_bound_seq;
External<TypeIdentifier> element_identifier;
PlainArrayLElemDefn() {}
PlainArrayLElemDefn(const PlainCollectionHeader& a_header,
const LBoundSeq& a_array_bound_seq,
const TypeIdentifier& a_element_identifier)
: header(a_header)
, array_bound_seq(a_array_bound_seq)
, element_identifier(a_element_identifier)
{}
bool operator<(const PlainArrayLElemDefn& other) const;
};
struct PlainMapSTypeDefn {
PlainCollectionHeader header;
SBound bound;
External<TypeIdentifier> element_identifier;
CollectionElementFlag key_flags;
External<TypeIdentifier> key_identifier;
PlainMapSTypeDefn()
: bound(INVALID_SBOUND)
, key_flags(0)
{}
PlainMapSTypeDefn(const PlainCollectionHeader& a_header,
const SBound& a_bound,
const TypeIdentifier& a_element_identifier,
const CollectionElementFlag& a_key_flags,
const TypeIdentifier& a_key_identifier)
: header(a_header)
, bound(a_bound)
, element_identifier(a_element_identifier)
, key_flags(a_key_flags)
, key_identifier(a_key_identifier)
{}
bool operator<(const PlainMapSTypeDefn& other) const;
};
struct PlainMapLTypeDefn {
PlainCollectionHeader header;
LBound bound;
External<TypeIdentifier> element_identifier;
CollectionElementFlag key_flags;
External<TypeIdentifier> key_identifier;
PlainMapLTypeDefn()
: bound(INVALID_LBOUND)
, key_flags(0)
{}
PlainMapLTypeDefn(const PlainCollectionHeader& a_header,
const LBound& a_bound,
const TypeIdentifier& a_element_identifier,
const CollectionElementFlag& a_key_flags,
const TypeIdentifier& a_key_identifier)
: header(a_header)
, bound(a_bound)
, element_identifier(a_element_identifier)
, key_flags(a_key_flags)
, key_identifier(a_key_identifier)
{}
bool operator<(const PlainMapLTypeDefn& other) const;
};
// Used for Types that have cyclic dependencies with other types
struct StronglyConnectedComponentId {
TypeObjectHashId sc_component_id; // Hash StronglyConnectedComponent
ACE_CDR::Long scc_length; // StronglyConnectedComponent.length
ACE_CDR::Long scc_index; // identify type in Strongly Connected Comp.
StronglyConnectedComponentId()
: scc_length(0)
, scc_index(0)
{}
StronglyConnectedComponentId(const TypeObjectHashId& a_sc_component_id,
const ACE_CDR::Long& a_scc_length,
const ACE_CDR::Long& a_scc_index)
: sc_component_id(a_sc_component_id)
, scc_length(a_scc_length)
, scc_index(a_scc_index)
{}
bool operator<(const StronglyConnectedComponentId& other) const
{
if (sc_component_id < other.sc_component_id) return true;
if (other.sc_component_id < sc_component_id) return false;
if (scc_length < other.scc_length) return true;
if (other.scc_length < scc_length) return false;
if (scc_index < other.scc_index) return true;
if (other.scc_index < scc_index) return false;
return false;
}
};
// Future extensibility
struct ExtendedTypeDefn {
// Empty. Available for future extension
};
// The TypeIdentifier uniquely identifies a type (a set of equivalent
// types according to an equivalence relationship: COMPLETE, MNIMAL).
//
// In some cases (primitive types, strings, plain types) the identifier
// is a explicit description of the type.
// In other cases the Identifier is a Hash of the type description
//
// In the case of primitive types and strings the implied equivalence
// relation is the identity.
//
// For Plain Types and Hash-defined TypeIdentifiers there are three
// possibilities: MINIMAL, COMPLETE, and COMMON:
// - MINIMAL indicates the TypeIdentifier identifies equivalent types
// according to the MINIMAL equivalence relation
// - COMPLETE indicates the TypeIdentifier identifies equivalent types
// according to the COMPLETE equivalence relation
// - COMMON indicates the TypeIdentifier identifies equivalent types
// according to both the MINIMAL and the COMMON equivalence relation.
// This means the TypeIdentifier is the same for both relationships
//
// @extensibility(FINAL) @nested
// union TypeIdentifier switch (octet) {
// // ============ Primitive types - use TypeKind ====================
// // All primitive types fall here.
// // Commented-out because Unions cannot have cases with no member.
// /*
// case TK_NONE:
// case TK_BOOLEAN:
// case TK_BYTE:
// case TK_INT16:
// case TK_INT32:
// case TK_INT64:
// case TK_UINT16:
// case TK_UINT32:
// case TK_UINT64:
// case TK_FLOAT32:
// case TK_FLOAT64:
// case TK_FLOAT128:
// case TK_CHAR8:
// case TK_CHAR16:
// // No Value
// */
// // ============ Strings - use TypeIdentifierKind ===================
// case TI_STRING8_SMALL:
// case TI_STRING16_SMALL:
// StringSTypeDefn string_sdefn;
// case TI_STRING8_LARGE:
// case TI_STRING16_LARGE:
// StringLTypeDefn string_ldefn;
// // ============ Plain collections - use TypeIdentifierKind =========
// case TI_PLAIN_SEQUENCE_SMALL:
// PlainSequenceSElemDefn seq_sdefn;
// case TI_PLAIN_SEQUENCE_LARGE:
// PlainSequenceLElemDefn seq_ldefn;
// case TI_PLAIN_ARRAY_SMALL:
// PlainArraySElemDefn array_sdefn;
// case TI_PLAIN_ARRAY_LARGE:
// PlainArrayLElemDefn array_ldefn;
// case TI_PLAIN_MAP_SMALL:
// PlainMapSTypeDefn map_sdefn;
// case TI_PLAIN_MAP_LARGE:
// PlainMapLTypeDefn map_ldefn;
// // ============ Types that are mutually dependent on each other ===
// case TI_STRONGLY_CONNECTED_COMPONENT:
// StronglyConnectedComponentId sc_component_id;
// // ============ The remaining cases - use EquivalenceKind =========
// case EK_COMPLETE:
// case EK_MINIMAL:
// EquivalenceHash equivalence_hash;
// // =================== Future extensibility ============
// // Future extensions
// default:
// ExtendedTypeDefn extended_defn;
// };
class OpenDDS_Dcps_Export TypeIdentifier : public DCPS::PoolAllocationBase {
public:
explicit TypeIdentifier(ACE_CDR::Octet kind = TK_NONE);
TypeIdentifier(const TypeIdentifier& other);
TypeIdentifier& operator=(const TypeIdentifier& other);
~TypeIdentifier() { reset(); }
TypeIdentifier(ACE_CDR::Octet kind, const StringSTypeDefn& sdefn);
TypeIdentifier(ACE_CDR::Octet kind, const StringLTypeDefn& ldefn);
TypeIdentifier(ACE_CDR::Octet kind, const PlainSequenceSElemDefn& sdefn);
TypeIdentifier(ACE_CDR::Octet kind, const PlainSequenceLElemDefn& ldefn);
TypeIdentifier(ACE_CDR::Octet kind, const PlainArraySElemDefn& sdefn);
TypeIdentifier(ACE_CDR::Octet kind, const PlainArrayLElemDefn& ldefn);
TypeIdentifier(ACE_CDR::Octet kind, const EquivalenceHashWrapper& equivalence_hash);
TypeIdentifier(ACE_CDR::Octet kind, const StronglyConnectedComponentId& sc_component_id);
ACE_CDR::Octet kind() const { return kind_; }
#define OPENDDS_UNION_ACCESSORS(T, N) \
const T& N() const { return *static_cast<T*>(active_); } \
T& N() { return *static_cast<T*>(active_); }
OPENDDS_UNION_ACCESSORS(StringSTypeDefn, string_sdefn);
OPENDDS_UNION_ACCESSORS(StringLTypeDefn, string_ldefn);
OPENDDS_UNION_ACCESSORS(PlainSequenceSElemDefn, seq_sdefn);
OPENDDS_UNION_ACCESSORS(PlainSequenceLElemDefn, seq_ldefn);
OPENDDS_UNION_ACCESSORS(PlainArraySElemDefn, array_sdefn);
OPENDDS_UNION_ACCESSORS(PlainArrayLElemDefn, array_ldefn);
OPENDDS_UNION_ACCESSORS(PlainMapSTypeDefn, map_sdefn);
OPENDDS_UNION_ACCESSORS(PlainMapLTypeDefn, map_ldefn);
OPENDDS_UNION_ACCESSORS(StronglyConnectedComponentId, sc_component_id);
OPENDDS_UNION_ACCESSORS(EquivalenceHash, equivalence_hash);
OPENDDS_UNION_ACCESSORS(ExtendedTypeDefn, extended_defn);
#undef OPENDDS_UNION_ACCESSORS
bool operator<(const TypeIdentifier& other) const
{
if (kind_ != other.kind_) {
return kind_ < other.kind_;
}
switch (kind_) {
case TI_STRONGLY_CONNECTED_COMPONENT:
return sc_component_id() < other.sc_component_id();
case EK_COMPLETE:
case EK_MINIMAL:
return std::memcmp(equivalence_hash(), other.equivalence_hash(), sizeof equivalence_hash()) < 0;
case TI_STRING8_SMALL:
case TI_STRING16_SMALL:
return string_sdefn() < other.string_sdefn();
case TI_STRING8_LARGE:
case TI_STRING16_LARGE:
return string_ldefn() < other.string_ldefn();
case TI_PLAIN_SEQUENCE_SMALL:
return seq_sdefn() < other.seq_sdefn();
case TI_PLAIN_SEQUENCE_LARGE:
return seq_ldefn() < other.seq_ldefn();
case TI_PLAIN_ARRAY_SMALL:
return array_sdefn() < other.array_sdefn();
case TI_PLAIN_ARRAY_LARGE:
return array_ldefn() < other.array_ldefn();
case TI_PLAIN_MAP_SMALL:
return map_sdefn() < other.map_sdefn();
case TI_PLAIN_MAP_LARGE:
return map_ldefn() < other.map_ldefn();
default:
return false;
}
}
bool operator==(const TypeIdentifier& other) const
{
return !(*this < other) && !(other < *this);
}
private:
ACE_CDR::Octet kind_;
void* active_;
union {
ACE_CDR::ULongLong max_alignment;
#define OPENDDS_UNION_MEMBER(T, N) unsigned char N ## _[sizeof(T)]
OPENDDS_UNION_MEMBER(StringSTypeDefn, string_sdefn);
OPENDDS_UNION_MEMBER(StringLTypeDefn, string_ldefn);
OPENDDS_UNION_MEMBER(PlainSequenceSElemDefn, seq_sdefn);
OPENDDS_UNION_MEMBER(PlainSequenceLElemDefn, seq_ldefn);
OPENDDS_UNION_MEMBER(PlainArraySElemDefn, array_sdefn);
OPENDDS_UNION_MEMBER(PlainArrayLElemDefn, array_ldefn);
OPENDDS_UNION_MEMBER(PlainMapSTypeDefn, map_sdefn);
OPENDDS_UNION_MEMBER(PlainMapLTypeDefn, map_ldefn);
OPENDDS_UNION_MEMBER(StronglyConnectedComponentId, sc_component_id);
OPENDDS_UNION_MEMBER(EquivalenceHash, equivalence_hash);
OPENDDS_UNION_MEMBER(ExtendedTypeDefn, extended_defn);
#undef OPENDDS_UNION_MEMBER
};
void activate(const TypeIdentifier* other = 0);
void reset();
};
typedef Sequence<TypeIdentifier> TypeIdentifierSeq;
// Operators less-than of member types of TypeIdentifier
inline bool PlainSequenceSElemDefn::operator<(const PlainSequenceSElemDefn& other) const
{
if (header < other.header) return true;
if (other.header < header) return false;
if (bound < other.bound) return true;
if (other.bound < bound) return false;
if (*element_identifier < *other.element_identifier) return true;
if (*other.element_identifier < *element_identifier) return false;
return false;
}
inline bool PlainSequenceLElemDefn::operator<(const PlainSequenceLElemDefn& other) const
{
if (header < other.header) return true;
if (other.header < header) return false;
if (bound < other.bound) return true;
if (other.bound < bound) return false;
if (*element_identifier < *other.element_identifier) return true;
if (*other.element_identifier < *element_identifier) return false;
return false;
}
inline bool PlainArraySElemDefn::operator<(const PlainArraySElemDefn& other) const
{
if (header < other.header) return true;
if (other.header < header) return false;
if (array_bound_seq < other.array_bound_seq) return true;
if (other.array_bound_seq < array_bound_seq) return false;
if (*element_identifier < *other.element_identifier) return true;
if (*other.element_identifier < *element_identifier) return false;
return false;
}
inline bool PlainArrayLElemDefn::operator<(const PlainArrayLElemDefn& other) const
{
if (header < other.header) return true;
if (other.header < header) return false;
if (array_bound_seq < other.array_bound_seq) return true;
if (other.array_bound_seq < array_bound_seq) return false;
if (*element_identifier < *other.element_identifier) return true;
if (*other.element_identifier < *element_identifier) return false;
return false;
}
inline bool PlainMapSTypeDefn::operator<(const PlainMapSTypeDefn& other) const
{
if (header < other.header) return true;
if (other.header < header) return false;
if (bound < other.bound) return true;
if (other.bound < bound) return false;
if (*element_identifier < *other.element_identifier) return true;
if (*other.element_identifier < *element_identifier) return false;
if (key_flags < other.key_flags) return true;
if (other.key_flags < key_flags) return false;
if (*key_identifier < *other.key_identifier) return true;
if (*other.key_identifier < *key_identifier) return false;
return false;
}
inline bool PlainMapLTypeDefn::operator<(const PlainMapLTypeDefn& other) const
{
if (header < other.header) return true;
if (other.header < header) return false;
if (bound < other.bound) return true;
if (other.bound < bound) return false;
if (*element_identifier < *other.element_identifier) return true;
if (*other.element_identifier < *element_identifier) return false;
if (key_flags < other.key_flags) return true;
if (other.key_flags < key_flags) return false;
if (*key_identifier < *other.key_identifier) return true;
if (*other.key_identifier < *key_identifier) return false;
return false;
}
// --- Annotation usage: -----------------------------------------------
// ID of a type member
typedef ACE_CDR::ULong MemberId;
const ACE_CDR::ULong MEMBER_ID_INVALID = ACE_UINT32_MAX;
// Union discriminator does not have an Id specified in TypeObject or DynamicType.
// OpenDDS uses the following sentinels for interacting with DynamicData and
// for serialization, respectively.
const ACE_CDR::ULong DISCRIMINATOR_ID = MEMBER_ID_INVALID - 1;
const ACE_CDR::ULong DISCRIMINATOR_SERIALIZED_ID = 0;
const ACE_CDR::ULong ANNOTATION_STR_VALUE_MAX_LEN = 128;
const ACE_CDR::ULong ANNOTATION_OCTETSEC_VALUE_MAX_LEN = 128;
struct ExtendedAnnotationParameterValue {
// Empty. Available for future extension
bool operator==(const ExtendedAnnotationParameterValue&) const
{
return true;
}
bool operator!=(const ExtendedAnnotationParameterValue& other) const
{
return !(*this == other);
}
};
/* Literal value of an annotation member: either the default value in its
* definition or the value applied in its usage.
*/
// @extensibility(FINAL) @nested
// union AnnotationParameterValue switch (octet) {
// case TK_BOOLEAN:
// boolean boolean_value;
// case TK_BYTE:
// octet byte_value;
// case TK_INT8:
// int8 int8_value;
// case TK_UINT8:
// uint8 uint8_value;
// case TK_INT16:
// short int16_value;
// case TK_UINT16:
// unsigned short uint_16_value;
// case TK_INT32:
// long int32_value;
// case TK_UINT32:
// unsigned long uint32_value;
// case TK_INT64:
// long long int64_value;
// case TK_UINT64:
// unsigned long long uint64_value;
// case TK_FLOAT32:
// float float32_value;
// case TK_FLOAT64:
// double float64_value;
// case TK_FLOAT128:
// long double float128_value;
// case TK_CHAR8:
// char char_value;
// case TK_CHAR16:
// wchar wchar_value;
// case TK_ENUM:
// long enumerated_value;
// case TK_STRING8:
// string<ANNOTATION_STR_VALUE_MAX_LEN> string8_value;
// case TK_STRING16:
// wstring<ANNOTATION_STR_VALUE_MAX_LEN> string16_value;
// default:
// ExtendedAnnotationParameterValue extended_value;
// };
class OpenDDS_Dcps_Export AnnotationParameterValue {
public:
explicit AnnotationParameterValue(ACE_CDR::Octet kind = TK_NONE);
AnnotationParameterValue(const AnnotationParameterValue& other);
AnnotationParameterValue& operator=(const AnnotationParameterValue& other);
~AnnotationParameterValue() { reset(); }
ACE_CDR::Octet kind() const { return kind_; }
#define OPENDDS_UNION_ACCESSORS(T, N) \
const T& N() const { return *static_cast<T*>(active_); } \
T& N() { return *static_cast<T*>(active_); }
OPENDDS_UNION_ACCESSORS(ACE_CDR::Boolean, boolean_value);
OPENDDS_UNION_ACCESSORS(ACE_CDR::Octet, byte_value);
OPENDDS_UNION_ACCESSORS(ACE_CDR::Char, int8_value);
OPENDDS_UNION_ACCESSORS(ACE_CDR::Octet, uint8_value);
OPENDDS_UNION_ACCESSORS(ACE_CDR::Short, int16_value);
OPENDDS_UNION_ACCESSORS(ACE_CDR::UShort, uint16_value); // OMG Issue DDSXTY14-46.
OPENDDS_UNION_ACCESSORS(ACE_CDR::Long, int32_value);
OPENDDS_UNION_ACCESSORS(ACE_CDR::ULong, uint32_value);
OPENDDS_UNION_ACCESSORS(ACE_CDR::LongLong, int64_value);
OPENDDS_UNION_ACCESSORS(ACE_CDR::ULongLong, uint64_value);