summaryrefslogtreecommitdiffstats
path: root/src/Authoring/QT3DSDM/Systems/Qt3DSDMDataTypes.h
blob: 7a7157f6006c122612c8ef3b7ec1b964e60f820b (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
/****************************************************************************
**
** Copyright (C) 1993-2009 NVIDIA Corporation.
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt 3D Studio.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#pragma once
#ifndef QT3DSDM_DATA_H
#define QT3DSDM_DATA_H

#include <memory>
#include <functional>

#include "Qt3DSDMErrors.h"
#include "Qt3DSDMStringTable.h"
#include "Qt3DSDMWindowsCompatibility.h"
#include <stdexcept>
#include <vector>
#include <map>
#include <set>
#include <EABase/eabase.h> //char8_t, etc.
#include <EASTL/string.h>
#include <EASTL/vector.h>
#include "foundation/StrConvertUTF.h"
#include "foundation/Qt3DSDiscriminatedUnion.h"

#include <QObject>

namespace qt3dsdm {

typedef const wchar_t *TCharPtr;
struct Qt3DSDMStr : public eastl::basic_string<qt3ds::foundation::TWCharEASTLConverter::TCharType>
{
    typedef qt3ds::foundation::TWCharEASTLConverter::TCharType TCharType;
    typedef eastl::basic_string<qt3ds::foundation::TWCharEASTLConverter::TCharType> TStrType;
    Qt3DSDMStr() {}
    Qt3DSDMStr(const wchar_t *inStr)
        : TStrType(qt3ds::NVUnionCast<const TCharType *>(inStr))
    {
    }
    Qt3DSDMStr(const TStrType &inOther)
        : TStrType(inOther)
    {
    }

    const wchar_t *wide_str() const { return reinterpret_cast<const wchar_t *>(c_str()); }
    bool operator==(const Qt3DSDMStr &inOther) const { return TStrType::compare(inOther) == 0; }
    bool operator!=(const Qt3DSDMStr &inOther) const { return TStrType::compare(inOther) != 0; }
    bool operator==(const wchar_t *inOther) const
    {
        return TStrType::compare(reinterpret_cast<const TCharType *>(inOther)) == 0;
    }
    bool operator!=(const wchar_t *inOther) const
    {
        return TStrType::compare(reinterpret_cast<const TCharType *>(inOther)) != 0;
    }

    TStrType::size_type find_first_of(const wchar_t *p, size_type position = 0) const
    {
        return TStrType::find_first_of(reinterpret_cast<const TCharType *>(p), position);
    }
    TStrType::size_type find_first_not_of(const wchar_t *p, size_type position = 0) const
    {
        return TStrType::find_first_not_of(reinterpret_cast<const TCharType *>(p), position);
    }
    TStrType::size_type find_last_not_of(const wchar_t *p,
                                         size_type position = TStrType::npos) const
    {
        return TStrType::find_last_not_of(reinterpret_cast<const TCharType *>(p), position);
    }
    TStrType::size_type find(const wchar_t *p, size_type position = 0) const
    {
        return TStrType::find(reinterpret_cast<const TCharType *>(p), position);
    }
    TStrType::size_type find(wchar_t p, size_type position = 0) const
    {
        return TStrType::find(static_cast<TCharType>(p), position);
    }
    TStrType::size_type rfind(const wchar_t *p, size_type position = TStrType::npos) const
    {
        return TStrType::rfind(reinterpret_cast<const TCharType *>(p), position);
    }
    TStrType::size_type rfind(wchar_t p, size_type position = TStrType::npos) const
    {
        return TStrType::rfind(p, position);
    }
    Qt3DSDMStr replace(size_type position, size_type length, const wchar_t *inNewStr)
    {
        return TStrType::replace(position, length, reinterpret_cast<const TCharType *>(inNewStr));
    }

    void append(const wchar_t *p) { TStrType::append(reinterpret_cast<const TCharType *>(p)); }
    void append(const wchar_t *p, size_type position, size_type n)
    {
        TStrType::append(reinterpret_cast<const TCharType *>(p), position, n);
    }
    void append(const Qt3DSDMStr &p) { TStrType::append(p); }
    void assign(const wchar_t *p) { TStrType::assign(reinterpret_cast<const TCharType *>(p)); }
    void assign(const Qt3DSDMStr &p) { TStrType::assign(p); }
};
typedef Qt3DSDMStr TCharStr;
typedef std::vector<wchar_t> TCharList;
typedef eastl::vector<TCharStr> TCharStrList;
typedef std::map<TCharStr, int> TCharStrIntMap;
typedef std::map<int, TCharStr> TIntTCharStrMap;
typedef std::vector<int> TIntList;
typedef std::set<int> TIntSet;
typedef eastl::vector<float> TFloatList;

template <typename TDataType>
class CImmutableVector : private std::vector<TDataType>
{
public:
    typedef std::vector<TDataType> base;

    CImmutableVector(const std::vector<TDataType> &inSrc)
        : base(inSrc)
    {
    }
    CImmutableVector(const CImmutableVector &inSrc)
        : base(inSrc)
    {
    }

    CImmutableVector &operator=(const CImmutableVector &inSrc)
    {
        base::operator=(inSrc);
        return *this;
    }

    typename std::vector<TDataType>::const_iterator begin() const { return base::begin(); }
    typename std::vector<TDataType>::const_iterator end() const { return base::end(); }

    size_t size() const { return base::size(); }

    const TDataType &at(int inIndex) const { return base::at(inIndex); }
    const TDataType &operator[](int inIndex) const { return base::at(inIndex); }
};

typedef CImmutableVector<TCharStr> TImmutableCharStrList;
typedef std::shared_ptr<TImmutableCharStrList> TImmutableCharStrListPtr;

class CDataStr
{
    TCharList m_Data;

public:
    CDataStr() {}
    CDataStr(TCharList &inData) { m_Data.swap(inData); }
    CDataStr(const wchar_t *inData)
    {
        if (inData && *inData)
            m_Data.insert(m_Data.begin(), inData, inData + wcslen(inData));
        m_Data.push_back(0);
    }
    CDataStr(const wchar_t *inData, size_t inLen)
    {
        if (inData && *inData)
            m_Data.insert(m_Data.begin(), inData, inData + inLen);
        if (m_Data.size() > 0 && m_Data.back() != 0)
            m_Data.push_back(0);
    }
    CDataStr(const CDataStr &inOther)
        : m_Data(inOther.m_Data)
    {
    }
    virtual ~CDataStr() {}

    CDataStr &operator=(const CDataStr &inOther)
    {
        m_Data = inOther.m_Data;
        return *this;
    }
    const wchar_t *GetData() const { return m_Data.size() <= 1 ? L"" : &(*m_Data.begin()); }
    size_t GetLength() const { return m_Data.size() > 1 ? m_Data.size() - 1 : 0; }
    bool operator==(const CDataStr &inOther) const { return m_Data == inOther.m_Data; }
    QString toQString() const { return QString::fromWCharArray(GetData()); }
};

typedef std::shared_ptr<CDataStr> TDataStrPtr;

struct SFloat2
{
    float m_Floats[2];
    SFloat2(float f1 = 0, float f2 = 0)
    {
        m_Floats[0] = f1;
        m_Floats[1] = f2;
    }
    SFloat2(const SFloat2 &inOther) { operator=(inOther); }
    SFloat2 &operator=(const SFloat2 &inOther)
    {
        m_Floats[0] = inOther.m_Floats[0];
        m_Floats[1] = inOther.m_Floats[1];
        return *this;
    }
    bool operator==(const SFloat2 &other) const
    {
        return m_Floats[0] == other.m_Floats[0] && m_Floats[1] == other.m_Floats[1];
    }
    float &operator[](size_t inIndex)
    {
        switch (inIndex) {
        default:
            throw std::out_of_range("");
        case 0:
        case 1:
            return m_Floats[inIndex];
        }
    }
    const float &operator[](size_t inIndex) const
    {
        switch (inIndex) {
        default:
            throw std::out_of_range("");
        case 0:
        case 1:
            return m_Floats[inIndex];
        }
    }
};

struct SFloat3
{
    float m_Floats[3];

    SFloat3(float f1 = 0, float f2 = 0, float f3 = 0)
    {
        m_Floats[0] = f1;
        m_Floats[1] = f2;
        m_Floats[2] = f3;
    }
    SFloat3(const SFloat3 &inOther) { operator=(inOther); }
    SFloat3 &operator=(const SFloat3 &inOther)
    {
        m_Floats[0] = inOther.m_Floats[0];
        m_Floats[1] = inOther.m_Floats[1];
        m_Floats[2] = inOther.m_Floats[2];
        return *this;
    }

    bool operator==(const SFloat3 &other) const
    {
        return m_Floats[0] == other.m_Floats[0] && m_Floats[1] == other.m_Floats[1]
            && m_Floats[2] == other.m_Floats[2];
    }

    float &operator[](size_t inIndex)
    {
        switch (inIndex) {
        default:
            throw std::out_of_range("");
        case 0:
        case 1:
        case 2:
            return m_Floats[inIndex];
        }
    }
    const float &operator[](size_t inIndex) const
    {
        switch (inIndex) {
        default:
            throw std::out_of_range("");
        case 0:
        case 1:
        case 2:
            return m_Floats[inIndex];
        }
    }
};

struct SFloat4
{
    float m_Floats[4];

    SFloat4(float f1 = 0, float f2 = 0, float f3 = 0, float f4 = 1)
    {
        m_Floats[0] = f1;
        m_Floats[1] = f2;
        m_Floats[2] = f3;
        m_Floats[3] = f4;
    }
    SFloat4(const SFloat4 &inOther) { operator=(inOther); }
    SFloat4 &operator=(const SFloat4 &inOther)
    {
        m_Floats[0] = inOther.m_Floats[0];
        m_Floats[1] = inOther.m_Floats[1];
        m_Floats[2] = inOther.m_Floats[2];
        m_Floats[3] = inOther.m_Floats[3];
        return *this;
    }

    bool operator==(const SFloat4 &other) const
    {
        return m_Floats[0] == other.m_Floats[0] && m_Floats[1] == other.m_Floats[1]
               && m_Floats[2] == other.m_Floats[2] && m_Floats[3] == other.m_Floats[3];
    }

    float &operator[](size_t inIndex)
    {
        if (inIndex < 4)
            return m_Floats[inIndex];

        throw std::out_of_range("");
    }
    const float &operator[](size_t inIndex) const
    {
        if (inIndex < 4)
            return m_Floats[inIndex];

        throw std::out_of_range("");
    }
};

struct SLong4
{
    qt3ds::QT3DSU32 m_Longs[4];

    SLong4(qt3ds::QT3DSU32 l1 = 0,
           qt3ds::QT3DSU32 l2 = 0,
           qt3ds::QT3DSU32 l3 = 0,
           qt3ds::QT3DSU32 l4 = 0)
    {
        m_Longs[0] = l1;
        m_Longs[1] = l2;
        m_Longs[2] = l3;
        m_Longs[3] = l4;
    }
    SLong4(const SLong4 &inOther) { operator=(inOther); }
    SLong4 &operator=(const SLong4 &inOther)
    {
        m_Longs[0] = inOther.m_Longs[0];
        m_Longs[1] = inOther.m_Longs[1];
        m_Longs[2] = inOther.m_Longs[2];
        m_Longs[3] = inOther.m_Longs[3];
        return *this;
    }

    bool operator==(const SLong4 &other) const
    {
        return m_Longs[0] == other.m_Longs[0] && m_Longs[1] == other.m_Longs[1]
            && m_Longs[2] == other.m_Longs[2] && m_Longs[3] == other.m_Longs[3];
    }

    bool operator<(const SLong4 &other) const
    {
        if (m_Longs[0] < other.m_Longs[0])
            return true;
        else if (m_Longs[0] == other.m_Longs[0]) {
            if (m_Longs[1] < other.m_Longs[1])
                return true;
            else if (m_Longs[1] == other.m_Longs[1]) {
                if (m_Longs[2] < other.m_Longs[2])
                    return true;
                else if (m_Longs[3] < other.m_Longs[3])
                    return true;
            }
        }
        return false;
    }

    bool Valid() const
    {
        bool retval = false;
        for (int idx = 0; idx < 4; ++idx)
            retval = retval || m_Longs[0] > 0;
        return retval;
    }
};

typedef std::vector<SLong4> TLong4Vec;

struct SSizet4
{
    size_t m_Longs[4];

    SSizet4(size_t l1 = 0, size_t l2 = 0, size_t l3 = 0, size_t l4 = 0)
    {
        m_Longs[0] = l1;
        m_Longs[1] = l2;
        m_Longs[2] = l3;
        m_Longs[3] = l4;
    }
    SSizet4(const SSizet4 &inOther) { operator=(inOther); }
    SSizet4 &operator=(const SSizet4 &inOther)
    {
        m_Longs[0] = inOther.m_Longs[0];
        m_Longs[1] = inOther.m_Longs[1];
        m_Longs[2] = inOther.m_Longs[2];
        m_Longs[3] = inOther.m_Longs[3];
        return *this;
    }

    bool operator==(const SSizet4 &other) const
    {
        return m_Longs[0] == other.m_Longs[0] && m_Longs[1] == other.m_Longs[1]
            && m_Longs[2] == other.m_Longs[2] && m_Longs[3] == other.m_Longs[3];
    }

    bool operator<(const SSizet4 &other) const
    {
        if (m_Longs[0] < other.m_Longs[0])
            return true;
        else if (m_Longs[0] == other.m_Longs[0]) {
            if (m_Longs[1] < other.m_Longs[1])
                return true;
            else if (m_Longs[1] == other.m_Longs[1]) {
                if (m_Longs[2] < other.m_Longs[2])
                    return true;
                else if (m_Longs[3] < other.m_Longs[3])
                    return true;
            }
        }
        return false;
    }

    bool Valid() const
    {
        bool retval = false;
        for (int idx = 0; idx < 4; ++idx)
            retval = retval || m_Longs[0] > 0;
        return retval;
    }
};

inline bool IsTrivial(const wchar_t *inStr)
{
    return inStr == NULL || *inStr == 0;
}
inline const wchar_t *NonNull(const wchar_t *inStr)
{
    return inStr ? inStr : L"";
}
inline bool AreEqual(const wchar_t *lhs, const wchar_t *rhs)
{
    return wcscmp(NonNull(lhs), NonNull(rhs)) == 0;
}

inline bool IsTrivial(const char8_t *inStr)
{
    return inStr == NULL || *inStr == 0;
}
inline const char8_t *NonNull(const char8_t *inStr)
{
    return inStr ? inStr : "";
}
inline bool AreEqual(const char8_t *lhs, const char8_t *rhs)
{
    return strcmp(NonNull(lhs), NonNull(rhs)) == 0;
}

inline bool AreEqualCaseless(const char8_t *lhs, const char8_t *rhs)
{
    if (IsTrivial(lhs) && IsTrivial(rhs))
        return true;
    if (IsTrivial(lhs) || IsTrivial(rhs))
        return false;
    for (; *lhs && *rhs; ++lhs, ++rhs)
        if (tolower(*lhs) != tolower(*rhs))
            return false;
    if (*lhs || *rhs)
        return false;
    return true;
}

struct SStringRef
{
    const wchar_t *m_Id;

    SStringRef(const wchar_t *id = L"")
        : m_Id(NonNull(id))
    {
    }

    operator const wchar_t *() const { return m_Id; }
    bool operator==(const SStringRef &inOther) const { return AreEqual(m_Id, inOther.m_Id); }
};
}

// Traits specializations have to be in the same namespace as they were first declared.
namespace qt3ds {
namespace foundation {

    template <>
    struct DestructTraits<qt3dsdm::SFloat2>
    {
        void destruct(qt3dsdm::SFloat2 &) {}
    };
    template <>
    struct DestructTraits<qt3dsdm::SFloat3>
    {
        void destruct(qt3dsdm::SFloat3 &) {}
    };
    template <>
    struct DestructTraits<qt3dsdm::SFloat4>
    {
        void destruct(qt3dsdm::SFloat4 &) {}
    };
    template <>
    struct DestructTraits<qt3dsdm::SLong4>
    {
        void destruct(qt3dsdm::SLong4 &) {}
    };
    template <>
    struct DestructTraits<qt3dsdm::SStringRef>
    {
        void destruct(qt3dsdm::SStringRef &) {}
    };

    template <>
    struct EqualVisitorTraits<qt3dsdm::TDataStrPtr>
    {
        bool operator()(const qt3dsdm::TDataStrPtr &lhs, const qt3dsdm::TDataStrPtr &rhs)
        {
            if (lhs && rhs)
                return *lhs == *rhs;
            if (lhs || rhs)
                return false;
            return true;
        }
    };
}
}

namespace qt3dsdm {

using qt3ds::NVUnionCast;

struct ObjectReferenceType
{
    enum Enum {
        Unknown = 0,
        Absolute = 1,
        Relative = 2,
    };
};

template <typename TDataType>
struct SObjectRefTypeTraits
{
};

template <>
struct SObjectRefTypeTraits<SLong4>
{
    ObjectReferenceType::Enum getType() { return ObjectReferenceType::Absolute; }
};
template <>
struct SObjectRefTypeTraits<TDataStrPtr>
{
    ObjectReferenceType::Enum getType() { return ObjectReferenceType::Relative; }
};

struct SObjectRefUnionTraits
{
    typedef ObjectReferenceType::Enum TIdType;
    enum {
        TBufferSize = sizeof(SSizet4),
    };

    static ObjectReferenceType::Enum getNoDataId() { return ObjectReferenceType::Unknown; }

    template <typename TDataType>
    static TIdType getType()
    {
        return SObjectRefTypeTraits<TDataType>().getType();
    }

    template <typename TRetType, typename TVisitorType>
    static TRetType visit(char *inData, TIdType inType, TVisitorType inVisitor)
    {
        switch (inType) {
        case ObjectReferenceType::Absolute:
            return inVisitor(*NVUnionCast<SLong4 *>(inData));
        case ObjectReferenceType::Relative:
            return inVisitor(*NVUnionCast<TDataStrPtr *>(inData));
        default:
            QT3DS_ASSERT(false);
        case ObjectReferenceType::Unknown:
            return inVisitor();
        }
    }

    template <typename TRetType, typename TVisitorType>
    static TRetType visit(const char *inData, TIdType inType, TVisitorType inVisitor)
    {
        switch (inType) {
        case ObjectReferenceType::Absolute:
            return inVisitor(*NVUnionCast<const SLong4 *>(inData));
        case ObjectReferenceType::Relative:
            return inVisitor(*NVUnionCast<const TDataStrPtr *>(inData));
        default:
            QT3DS_ASSERT(false);
        case ObjectReferenceType::Unknown:
            return inVisitor();
        }
    }
};

typedef qt3ds::foundation::
    DiscriminatedUnion<qt3ds::foundation::
                           DiscriminatedUnionGenericBase<SObjectRefUnionTraits,
                                                         SObjectRefUnionTraits::TBufferSize>,
                       SObjectRefUnionTraits::TBufferSize>
        TObjRefUnionType;

template <typename TDataType>
struct Qt3DSDMGetter
{
};

template <typename TRetType, typename TDataType>
TRetType get(const TDataType &inType)
{
    return Qt3DSDMGetter<TDataType>().template doGet<TRetType>(inType);
}

template <>
struct Qt3DSDMGetter<TObjRefUnionType>
{
    template <typename TRetType>
    TRetType doGet(const TObjRefUnionType &inValue)
    {
        return inValue.getData<TRetType>();
    }
};

// Either an absolute reference (SLong4) or a relative reference (string)
struct SObjectRefType
{
    TObjRefUnionType m_Value;

    SObjectRefType(const TDataStrPtr &inValue)
        : m_Value(inValue)
    {
    }
    SObjectRefType(const SLong4 &inValue)
        : m_Value(inValue)
    {
    }
    SObjectRefType(const SObjectRefType &inOther)
        : m_Value(inOther.m_Value)
    {
    }
    SObjectRefType() {}
    SObjectRefType &operator=(const SObjectRefType &inOther)
    {
        m_Value = inOther.m_Value;
        return *this;
    }
    ObjectReferenceType::Enum GetReferenceType() const { return m_Value.getType(); }
    bool operator==(const SObjectRefType &inOther) const { return m_Value == inOther.m_Value; }
};

inline bool Equals(const SObjectRefType &lhs, const SObjectRefType &rhs)
{
    return lhs == rhs;
}

struct SStringOrIntTypes
{
    enum Enum {
        Unknown = 0,
        Int,
        String,
    };
};

template <typename TDataType>
struct SStringOrIntTypeTraits
{
};

template <>
struct SStringOrIntTypeTraits<long>
{
    SStringOrIntTypes::Enum getType() { return SStringOrIntTypes::Int; }
};
template <>
struct SStringOrIntTypeTraits<int>
{
    SStringOrIntTypes::Enum getType() { return SStringOrIntTypes::Int; }
};
template <>
struct SStringOrIntTypeTraits<TDataStrPtr>
{
    SStringOrIntTypes::Enum getType() { return SStringOrIntTypes::String; }
};

struct SStringOrIntUnionTraits
{
    typedef SStringOrIntTypes::Enum TIdType;
    enum {
        TBufferSize = sizeof(TDataStrPtr),
    };

    static SStringOrIntTypes::Enum getNoDataId() { return SStringOrIntTypes::Unknown; }

    template <typename TDataType>
    static TIdType getType()
    {
        return SStringOrIntTypeTraits<TDataType>().getType();
    }

    template <typename TRetType, typename TVisitorType>
    static TRetType visit(char *inData, TIdType inType, TVisitorType inVisitor)
    {
        switch (inType) {
        case SStringOrIntTypes::Int:
            return inVisitor(*NVUnionCast<long *>(inData));
        case SStringOrIntTypes::String:
            return inVisitor(*NVUnionCast<TDataStrPtr *>(inData));
        default:
            QT3DS_ASSERT(false);
        case SStringOrIntTypes::Unknown:
            return inVisitor();
        }
    }

    template <typename TRetType, typename TVisitorType>
    static TRetType visit(const char *inData, TIdType inType, TVisitorType inVisitor)
    {
        switch (inType) {
        case SStringOrIntTypes::Int:
            return inVisitor(*NVUnionCast<const qt3ds::QT3DSI32 *>(inData));
        case SStringOrIntTypes::String:
            return inVisitor(*NVUnionCast<const TDataStrPtr *>(inData));
        default:
            QT3DS_ASSERT(false);
        case SStringOrIntTypes::Unknown:
            return inVisitor();
        }
    }
};

typedef qt3ds::foundation::
    DiscriminatedUnion<qt3ds::foundation::
                           DiscriminatedUnionGenericBase<SStringOrIntUnionTraits,
                                                         SStringOrIntUnionTraits::TBufferSize>,
                       SStringOrIntUnionTraits::TBufferSize>
        TStringOrIntUnionType;

template <>
struct Qt3DSDMGetter<TStringOrIntUnionType>
{
    template <typename TRetType>
    TRetType doGet(const TStringOrIntUnionType &inValue)
    {
        return inValue.getData<TRetType>();
    }
};

struct SStringOrInt
{
    TStringOrIntUnionType m_Value;

    SStringOrInt() {}
    SStringOrInt(int inValue)
        : m_Value(inValue)
    {
    }
    SStringOrInt(TDataStrPtr inValue)
        : m_Value(inValue)
    {
    }
    SStringOrInt(const SStringOrInt &inOther)
        : m_Value(inOther.m_Value)
    {
    }

    SStringOrInt &operator=(const SStringOrInt &inOther)
    {
        m_Value = inOther.m_Value;
        return *this;
    }

    SStringOrIntTypes::Enum GetType() const { return m_Value.getType(); }

    bool operator==(const SStringOrInt &inOther) const { return m_Value == inOther.m_Value; }
};

inline bool Equals(const SStringOrInt &lhs, const SStringOrInt &rhs)
{
    return lhs == rhs;
}

//comes from broken X.h
#ifdef None
#undef None
#endif

#ifdef Bool
#undef Bool
#endif

struct DataModelDataType {

  enum Value {
      None,
      Float,
      Float2,
      Float3,
      Float4,
      Long,
      String,
      Bool,
      Long4,
      StringRef,
      ObjectRef,
      StringOrInt,
      FloatList,
      RangedNumber // datainput-specific type for editor only
  };


  Q_ENUM(Value)
  Q_GADGET
};


class IStringTable;

template <typename TDataType>
struct Qt3DSDMValueTyper
{
};

template <typename TDataType>
inline DataModelDataType::Value GetValueType(const TDataType &inValue)
{
    return Qt3DSDMValueTyper<TDataType>().Get(inValue);
}

template <typename TDataType>
struct SDefaulter
{
};

template <typename TDataType>
inline bool SetDefault(DataModelDataType::Value inDataType, TDataType &outValue)
{
    return SDefaulter<TDataType>().SetDefault(inDataType, outValue);
}

typedef void (*Qt3DSDMDebugLogFunction)(const char *message);
// UICDMSimpleDataCore.cpp
extern Qt3DSDMDebugLogFunction g_DataModelDebugLogger;

#define QT3DSDM_DEBUG_LOG(msg)                                                                       \
    {                                                                                              \
        if (g_DataModelDebugLogger) {                                                                  \
            g_DataModelDebugLogger(msg);                                                               \
        }                                                                                          \
    }
struct Qt3DSDMLogScope
{
    const char *m_EndMessage;
    Qt3DSDMLogScope(const char *inStartMessage, const char *inEndMessage)
        : m_EndMessage(inEndMessage)
    {
        QT3DSDM_DEBUG_LOG(inStartMessage);
    }
    ~Qt3DSDMLogScope() { QT3DSDM_DEBUG_LOG(m_EndMessage); }
};

#define QT3DSDM_LOG_FUNCTION(fnname) Qt3DSDMLogScope __fn_scope(fnname " Enter", fnname " Leave");
}

#endif