aboutsummaryrefslogtreecommitdiff
path: root/libxsde/xsde/cxx/hybrid/base.hxx
blob: 75753bcc1494780c82a2be5f3712768c653f9934 (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
// file      : xsde/cxx/hybrid/base.hxx
// author    : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC
// license   : GNU GPL v2 + exceptions; see accompanying LICENSE file

#ifndef XSDE_CXX_HYBRID_BASE_HXX
#define XSDE_CXX_HYBRID_BASE_HXX

#include <xsde/cxx/config.hxx>

namespace xsde
{
  namespace cxx
  {
    namespace hybrid
    {
      // boolean
      //
      struct boolean_base
      {
        bool base_value () const {return x_;}
        bool& base_value () {return x_;}
        void base_value (bool x) {x_ = x;}

        operator const bool& () const {return x_;}
        operator bool& () {return x_;}

        boolean_base& operator= (bool x) {x_ = x; return *this;}

      protected:
        bool x_;
      };

      // byte
      //
      struct byte_base
      {
        signed char base_value () const {return x_;}
        signed char& base_value () {return x_;}
        void base_value (signed char x) {x_ = x;}

        operator const signed char& () const {return x_;}
        operator signed char& () {return x_;}

        byte_base& operator= (signed char x) {x_ = x; return *this;}

      protected:
        signed char x_;
      };

      // unsigned_byte
      //
      struct unsigned_byte_base
      {
        unsigned char base_value () const {return x_;}
        unsigned char& base_value () {return x_;}
        void base_value (unsigned char x) {x_ = x;}

        operator const unsigned char& () const {return x_;}
        operator unsigned char& () {return x_;}

        unsigned_byte_base&
        operator= (unsigned char x) {x_ = x; return *this;}

      protected:
        unsigned char x_;
      };

      // short
      //
      struct short_base
      {
        short base_value () const {return x_;}
        short& base_value () {return x_;}
        void base_value (short x) {x_ = x;}

        operator const short& () const {return x_;}
        operator short& () {return x_;}

        short_base& operator= (short x) {x_ = x; return *this;}

      protected:
        short x_;
      };

      // unsigned_short
      //
      struct unsigned_short_base
      {
        unsigned short base_value () const {return x_;}
        unsigned short& base_value () {return x_;}
        void base_value (unsigned short x) {x_ = x;}

        operator const unsigned short& () const {return x_;}
        operator unsigned short& () {return x_;}

        unsigned_short_base&
        operator= (unsigned short x) {x_ = x; return *this;}

      protected:
        unsigned short x_;
      };

      // int
      //
      struct int_base
      {
        int base_value () const {return x_;}
        int& base_value () {return x_;}
        void base_value (int x) {x_ = x;}

        operator const int& () const {return x_;}
        operator int& () {return x_;}

        int_base& operator= (int x) {x_ = x; return *this;}

      protected:
        int x_;
      };

      // unsigned_int
      //
      struct unsigned_int_base
      {
        unsigned int base_value () const {return x_;}
        unsigned int& base_value () {return x_;}
        void base_value (unsigned int x) {x_ = x;}

        operator const unsigned int& () const {return x_;}
        operator unsigned int& () {return x_;}

        unsigned_int_base& operator= (unsigned int x) {x_ = x; return *this;}

      protected:
        unsigned int x_;
      };

      // long
      //
#ifdef XSDE_LONGLONG
      struct long_base
      {
        long long base_value () const {return x_;}
        long long& base_value () {return x_;}
        void base_value (long long x) {x_ = x;}

        operator const long long& () const {return x_;}
        operator long long& () {return x_;}

        long_base& operator= (long long x) {x_ = x; return *this;}

      protected:
        long long x_;
      };
#else
      struct long_base
      {
        long base_value () const {return x_;}
        long& base_value () {return x_;}
        void base_value (long x) {x_ = x;}

        operator const long& () const {return x_;}
        operator long& () {return x_;}

        long_base& operator= (long x) {x_ = x; return *this;}

      protected:
        long x_;
      };
#endif


      // unsigned_long
      //
#ifdef XSDE_LONGLONG
      struct unsigned_long_base
      {
        unsigned long long base_value () const {return x_;}
        unsigned long long& base_value () {return x_;}
        void base_value (unsigned long long x) {x_ = x;}

        operator const unsigned long long& () const {return x_;}
        operator unsigned long long& () {return x_;}

        unsigned_long_base&
        operator= (unsigned long long x) {x_ = x; return *this;}

      protected:
        unsigned long long x_;
      };
#else
      struct unsigned_long_base
      {
        unsigned long base_value () const {return x_;}
        unsigned long& base_value () {return x_;}
        void base_value (unsigned long x) {x_ = x;}

        operator const unsigned long& () const {return x_;}
        operator unsigned long& () {return x_;}

        unsigned_long_base&
        operator= (unsigned long x) {x_ = x; return *this;}

      protected:
        unsigned long x_;
      };
#endif

      // integer
      //
      struct integer_base
      {
        long base_value () const {return x_;}
        long& base_value () {return x_;}
        void base_value (long x) {x_ = x;}

        operator const long& () const {return x_;}
        operator long& () {return x_;}

        integer_base& operator= (long x) {x_ = x; return *this;}

      protected:
        long x_;
      };

      // negative_integer
      //
      struct negative_integer_base
      {
        long base_value () const {return x_;}
        long& base_value () {return x_;}
        void base_value (long x) {x_ = x;}

        operator const long& () const {return x_;}
        operator long& () {return x_;}

        negative_integer_base& operator= (long x) {x_ = x; return *this;}

      protected:
        long x_;
      };

      // non_positive_integer
      //
      struct non_positive_integer_base
      {
        long base_value () const {return x_;}
        long& base_value () {return x_;}
        void base_value (long x) {x_ = x;}

        operator const long& () const {return x_;}
        operator long& () {return x_;}

        non_positive_integer_base& operator= (long x) {x_ = x; return *this;}

      protected:
        long x_;
      };

      // positive_integer
      //
      struct positive_integer_base
      {
        unsigned long base_value () const {return x_;}
        unsigned long& base_value () {return x_;}
        void base_value (unsigned long x) {x_ = x;}

        operator const unsigned long& () const {return x_;}
        operator unsigned long& () {return x_;}

        positive_integer_base&
        operator= (unsigned long x) {x_ = x; return *this;}

      protected:
        unsigned long x_;
      };

      // non_negative_integer
      //
      struct non_negative_integer_base
      {
        unsigned long base_value () const {return x_;}
        unsigned long& base_value () {return x_;}
        void base_value (unsigned long x) {x_ = x;}

        operator const unsigned long& () const {return x_;}
        operator unsigned long& () {return x_;}

        non_negative_integer_base&
        operator= (unsigned long x) {x_ = x; return *this;}

      protected:
        unsigned long x_;
      };

      // float
      //
      struct float_base
      {
        float base_value () const {return x_;}
        float& base_value () {return x_;}
        void base_value (float x) {x_ = x;}

        operator const float& () const {return x_;}
        operator float& () {return x_;}

        float_base& operator= (float x) {x_ = x; return *this;}

      protected:
        float x_;
      };

      // double
      //
      struct double_base
      {
        double base_value () const {return x_;}
        double& base_value () {return x_;}
        void base_value (double x) {x_ = x;}

        operator const double& () const {return x_;}
        operator double& () {return x_;}

        double_base& operator= (double x) {x_ = x; return *this;}

      protected:
        double x_;
      };

      // decimal
      //
      struct decimal_base
      {
        double base_value () const {return x_;}
        double& base_value () {return x_;}
        void base_value (double x) {x_ = x;}

        operator const double& () const {return x_;}
        operator double& () {return x_;}

        decimal_base& operator= (double x) {x_ = x; return *this;}

      protected:
        double x_;
      };

      // string
      //
      struct string_base
      {
        string_base () : x_ (0) {}
        ~string_base () {delete[] x_;}

        const char* base_value () const {return x_;}
        char* base_value () {return x_;}
        void base_value (char* x) {delete[] x_; x_ = x;}

        operator const char* () const {return x_;}
        operator char* () {return x_;}

        string_base& operator= (char* x) {delete[] x_; x_ = x; return *this;}

      protected:
        char* x_;
      };
    }
  }
}

#endif  // XSDE_CXX_HYBRID_BASE_HXX