summaryrefslogtreecommitdiffstats
path: root/sdo-cpp/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/DataTypeInfo.h
blob: b85ce5738961cd970b94a1a028c08c75cdda387d (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
/*
*
*  Copyright 2007 The Apache Software Foundation or its licensors, as applicable.
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/

/* $Rev$ $Date$ */

#ifndef _DATATYPEINFO_H_
#define _DATATYPEINFO_H_

#include "commonj/sdo/SDODate.h"
#include "commonj/sdo/SDOString.h"

namespace commonj
{
   namespace sdo
   {

      // The DataTypeInfo class provides types that encapsulate the various
      // primitive data types that SDO uses to represent the user level data
      // types defined in the specification. The central artifact is a union
      // of all the C++ data types that are used to represent SDO data
      // types. This is augmented by enumerations that provide a convenient
      // way to label a particular type, plus a method to retrieve a text
      // representation of each enumeration value.

      // There are three different array-like primitive data types.
      // 1. CString: An array of char, terminated by a 0 ie a C style string.
      // 2. ByteArray: An array of bytes. Similar to 1. but without the null
      // terminator.
      // 3. String: An array of wchar_t, terminated by a 0.  In the SDOValue
      // class, the first two are stored in an SDOString (ie std::string),
      // while the third is stored explicitly as a pointer to a buffer.

      class DataTypeInfo
      {
         public:
            // The values of TrueDataType are used as subscripts for an array
            // so they must a) start at zero and b) be contiguous. Elsewhere,
            // TDTWideString is used as the definition of the largest
            // TrueDatatype value, so if any constants are added beyond it the
            // code that depends on it will have to be changed.
            enum TrueDataType
            {
               TDTbool = 0,
               TDTchar = 1,
               TDTwchar_t = 2,
               TDTshort = 3,
               TDTlong = 4,
               TDTint64_t = 5,
               TDTfloat = 6,
               TDTdouble = 7,
               TDTSDODate = 8,
               TDTCString = 9,
               TDTByteArray = 10,
               TDTWideString = 11
            };

            enum PseudoDataType
            {
               PDTunset = -2,
               PDTnull = -1
            };

            // This enum identifies what C++ datatype is present in the union.
            // It does not necessarily say what the SDO type is. Since it is
            // possible for a value to be either unset or null there are
            // enumerations for those cases too. This enum is effectively a
            // union of the two previous enums where TrueDataType includes
            // just those data types that can actually have values, while
            // PseudoDataType includes just null and unset. This allows for
            // methods that have to be told which type to create and for which
            // unset and null are inappropriate.
            enum RawDataType
            {
               SDOunset = PDTunset,
               SDOnull = PDTnull,
               SDObool = TDTbool,
               SDOchar = TDTchar,
               SDOwchar_t = TDTwchar_t,
               SDOshort = TDTshort,
               SDOlong = TDTlong,
               SDOint64_t = TDTint64_t,
               SDOfloat = TDTfloat,
               SDOdouble = TDTdouble,
               SDOSDODate = TDTSDODate,
               SDOCString = TDTCString,
               SDOByteArray = TDTByteArray,
               SDOWideString = TDTWideString,
            };

            // Entities with copy constructors/destructors are not allowed in a union,
            // since in general, the compiler doesn't know what type is
            // actually in there so it can't know which constructor/destructor
            // to call, hence the use of pointers for dates and strings
            union SDODataTypeUnion
            {
                  bool Boolean;
                  char Character;
                  wchar_t WideChar;
                  short Short;
                  long Integer;
                  int64_t Int64;
                  float Float;
                  long double Double;
                  SDODate* Date;
                  SDOString* TextString;
                  struct
                  {
                        wchar_t* data;
                        unsigned int length;
                  } WideString;
            };

            static const SDOString& convertTypeEnumToString(TrueDataType dataType);

         private:
            // Array of text strings that correspond to TrueDataType enumeration values
            static SDO_API const SDOString rawTypeNames[];

      };
   } // End - namespace sdo
} // End - namespace commonj

#endif // _DATATYPEINFO_H_