summaryrefslogtreecommitdiff
path: root/ivi-layermanagement-examples/LayerManagerControl/include/SceneStore.h
blob: d2978fe7e469ee43cf5a387762eb991e3730123c (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
/***************************************************************************
 *
 * Copyright 2012 BMW Car IT GmbH
 *
 *
 * 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.
 *
 ****************************************************************************/

#ifndef __SCENESTORE_H__
#define __SCENESTORE_H__


//=========================================================================
// helper macros fileformat
//=========================================================================
#include <StringMapTree.h>

#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>

using std::string;
using std::stringstream;
using std::ostream;

#include <list>
using std::list;

#include <vector>
using std::vector;




template<typename T> string getPrimitiveType(T var)
{
    return "";
}

template<typename T> string getPrimitiveType(T* var)
{
    (void) var;//suppress warning: unsued variable
    T var2 = 0;
    return getPrimitiveType(var2) + "*";
}

template<> string getPrimitiveType(bool var)
{
    (void) var;//suppress warning: unsued variable
    return "bool";
}

template<> string getPrimitiveType(char var)
{
    (void) var;//suppress warning: unsued variable
    return "char";
}

template<> string getPrimitiveType(signed char var)
{
    (void) var;//suppress warning: unsued variable
    return "signed char";
}

template<> string getPrimitiveType(unsigned char var)
{
    (void) var;//suppress warning: unsued variable
    return "unsigned char";
}

template<> string getPrimitiveType(wchar_t var)
{
    (void) var;//suppress warning: unsued variable
    return "wchar_t";
}

template<> string getPrimitiveType(short int var)
{
    (void) var;//suppress warning: unsued variable
    return "short int";
}

template<> string getPrimitiveType(unsigned short int var)
{
    (void) var;//suppress warning: unsued variable
    return "unsigned short int";
}

template<> string getPrimitiveType(long int var)
{
    (void) var;//suppress warning: unsued variable
    return "long int";
}

template<> string getPrimitiveType(unsigned long int var)
{
    (void) var;//suppress warning: unsued variable
    return "unsigned long int";
}

template<> string getPrimitiveType(int var)
{
    (void) var;//suppress warning: unsued variable
    return "int";
}

template<> string getPrimitiveType(unsigned int var)
{
    (void) var;//suppress warning: unsued variable
    return "unsigned int";
}

template<> string getPrimitiveType(float var)
{
    (void) var;//suppress warning: unsued variable
    return "float";
}

template<> string getPrimitiveType(double var)
{
    (void) var;//suppress warning: unsued variable
    return "double";
}

template<> string getPrimitiveType(long double var)
{
    (void) var;//suppress warning: unsued variable
    return "long double";
}

template<> string getPrimitiveType(string var)
{
    (void) var;//suppress warning: unsued variable
    return "string";
}


#if defined(__GXX_EXPERIMENTAL_CXX0X) || __cplusplus >= 201103L
template<> string getPrimitiveType(char16_t var)
{
    (void) var;//suppress warning: unsued variable
    return "char16_t";
}

template<> string getPrimitiveType(char32_t var)
{
    (void) var;//suppress warning: unsued variable
    return "char32_t";
}

template<> string getPrimitiveType(long long int var)
{
    (void) var;//suppress warning: unsued variable
    return "long long int";
}

template<> string getPrimitiveType(unsigned long long int var)
{
    (void) var;//suppress warning: unsued variable
    return "unsigned long long int";
}
#endif


struct WrapperHelper
{
public:
    const string mType;
    WrapperHelper(string t) :
            mType(t)
    {
    }

    virtual ~WrapperHelper()
    {
    }

    virtual void fromString(string s)
    {
        (void) s;//suppress warning: unsued variable
    }

    virtual string asString()
    {
        return "";
    }

    virtual void toStringMapTree(StringMapTree* parent)
    {
        (void) parent;//suppress warning: unsued variable
    }

    virtual void toGrammarMapTree(StringMapTree* tree)
    {
        (void) tree;//suppress warning: unsued variable
    }

    virtual WrapperHelper* tryClone(string type, StringMapTree* tree)
    {
        (void) type;//suppress warning: unsued variable
        (void) tree;//suppress warning: unsued variable
        return NULL;
    }

    virtual void addToComplexWrapper(WrapperHelper* wrapper)
    {
        (void) wrapper;//suppress warning: unsued variable
    }

    virtual string getWrapperPrimitiveType()
    {
        return "";
    }
};

template<typename T>
struct ComplexWrapper : public WrapperHelper
{
public:
    list<T> components;

    ComplexWrapper(string t) :
            WrapperHelper(t)
    {
    }

    virtual void toStringMapTree(StringMapTree* parent)
    {
        for (typename list<T>::iterator it = components.begin(); it != components.end(); ++it)
        {
            StringMapTree* node = new StringMapTree;
            (*it)->toStringMapTree(node);
            parent->mChildren.push_back(node);
        }
    }
};

template<typename T>
struct BasicWrapper : public WrapperHelper
{
public:
    T value;

    BasicWrapper(string t) :
            WrapperHelper(t)
    {
    }

    virtual void fromString(string s)
    {
        stringstream ss;
        ss.str(s);
        ss >> std::skipws >> value;
    }

    virtual string asString()
    {
        stringstream ss;
        ss << value;
        return    ss.str();
    }

    virtual string getWrapperPrimitiveType()
    {
        return getPrimitiveType(value);
    }
};

template<>
class BasicWrapper<string>: public WrapperHelper
{
public:
    string value;

    BasicWrapper(string t) :
            WrapperHelper(t)
    {
    }

    virtual void fromString(string s)
    {
        value = s;
    }

    virtual string asString()
    {
        return    value;
    }

    virtual string getWrapperPrimitiveType()
    {
        return getPrimitiveType(value);
    }
};

template<>
class BasicWrapper<char*>: public WrapperHelper
{
public:
    const char* value;

    BasicWrapper(char* t) :
            WrapperHelper(t)
    {
    }

    virtual void fromString(string s)
    {
        value = s.c_str();
    }

    virtual string asString()
    {
        return    value;
    }

    virtual string getWrapperPrimitiveType()
    {
        return getPrimitiveType(value);
    }
};

template<typename T>
struct DummyWrapper : public WrapperHelper
{
public:
    T value;

    DummyWrapper(string t) :
            WrapperHelper(t)
    {
    }

    virtual WrapperHelper* tryClone(string type, StringMapTree* tree)
    {
        if (type == mType)
        {
            DummyWrapper<T>* newWrapper = new DummyWrapper<T>(type);
            newWrapper->value.fromStringMapTree(tree);
            return newWrapper;
        }

        return NULL;
    }

    virtual void toGrammarMapTree(StringMapTree* tree)
    {
        value.toGrammarMapTree(tree);
    }

    virtual void addToComplexWrapper(WrapperHelper* wrapper)
    {
        ComplexWrapper<T*>* complexWrapper = static_cast<ComplexWrapper<T*>* >(wrapper);
        complexWrapper->components.push_back(&value);
    }
};

map<int, string> _globalTypeIndexdToType;

#define OBJECT(class_name) \
class class_name;\
ostream& operator<<(ostream& out, class_name& obj )\
{\
    (void) obj;\
    return out;\
}\
istream& operator>>(istream& in, class_name& obj)\
{\
    (void) obj;\
    return in;\
}\
class class_name { \
public:\
    map<string, WrapperHelper*> properties;\
    map<string, string> typesMap;\
    map<string, WrapperHelper*> components;\
    map<string, WrapperHelper*> dummyComponentClones;\
public:\
    const static int classNameIndex = __COUNTER__;\
    static int getClassNameIndex()\
    {\
        return classNameIndex;\
    }\
    \
    string mClassName;\
    template<typename T> bool get(string key, T* p)\
    {\
        if(properties.find(key) != properties.end())\
        {\
            BasicWrapper<T>* obj = (static_cast<BasicWrapper<T>*> (properties[key]));\
            if(obj) *p = obj->value;\
            return obj != NULL;\
        }\
        return false;\
    }\
    template<typename T> bool get(int* count, T*** p)\
    {\
        string type = _globalTypeIndexdToType[T::getClassNameIndex()];\
        if(components.find(type) != components.end())\
        {\
            ComplexWrapper<T*>* obj = static_cast<ComplexWrapper<T*>* >(components[type]);\
            if(obj){\
                vector<T*>* temp = new vector<T*>(obj->components.begin(), obj->components.end());\
                *p = temp->data();\
                *count = obj->components.size();\
            }\
            return obj != NULL;\
        }\
        return false;\
    }\
    template<typename T> bool get(list<T*>* p)\
    {\
        string type = _globalTypeIndexdToType[T::getClassNameIndex()];\
        if(components.find(type) != components.end())\
        {\
            ComplexWrapper<T*>* obj = static_cast<ComplexWrapper<T*>* >(components[type]);\
            if(obj){\
                *p = obj->components;\
            }\
            return obj != NULL;\
        }\
        return false;\
    }\
    template<typename T> bool set(string key, const T& p)\
    {\
        BasicWrapper<T>* obj = (static_cast<BasicWrapper<T>*> (properties[key]));\
        if(obj) obj->value = p;\
        return obj != NULL;\
    }\
    template<typename T> bool set(string key, T* p)\
    {\
        BasicWrapper<T*>* obj = (static_cast<BasicWrapper<T*>*> (properties[key]));\
        if(obj) obj->value = p;\
        return obj != NULL;\
    }\
    string getType(string key)\
    {\
        return typesMap[key];\
    }\
    template<typename T> bool add(T* obj)\
    {\
        if(components.find(obj->mClassName) != components.end())\
        {\
            (static_cast<ComplexWrapper<T*>* > (components[obj->mClassName])->components).push_back(obj);\
            return true;\
        }\
        return false;\
    }\
    template<typename T> bool unwrapAndAdd(DummyWrapper<T>* obj)\
    {\
        if(components.find(obj->mClassName) != components.end())\
        {\
            (static_cast<ComplexWrapper<T*>* > (components[obj->mClassName])->components).push_back(obj);\
            return true;\
        }\
        return false;\
    }\
    template<typename T> bool remove(T* obj)\
    {\
        if(components.find(obj->mClassName) != components.end())\
        {\
            (static_cast<ComplexWrapper<T*>* > (components[obj->mClassName])->components).remove(obj);\
            return true;\
        }\
        return false;\
    }\
    ~class_name()\
    {\
        for(map<string, WrapperHelper*>::iterator it = properties.begin(); it != properties.end();++it)\
            delete (*it).second;\
        for(map<string, WrapperHelper*>::iterator it = components.begin(); it != components.end();++it)\
            delete (*it).second;\
    }\
    class_name():mClassName(#class_name)\
    {\
        _globalTypeIndexdToType[getClassNameIndex()] = #class_name;

#define PROPERTY(type, name) \
    properties[#name] = new BasicWrapper<type>(#type);\
    typesMap[#name] = #type;


#define CONTAINS(type) \
        components[#type] = new ComplexWrapper<type*>(#type);\
        dummyComponentClones[#type]= (new DummyWrapper<type>(#type));


#define OBJECTEND \
    }\
    void toGrammarMapTree(StringMapTree* node)\
    {\
        node->mNodeLabel = mClassName;\
        for(map<string, WrapperHelper*>::iterator it = properties.begin(); it != properties.end();++it)\
        {\
            node->mNodeValues[(*it).first] = make_pair((*it).second->mType, it->second->getWrapperPrimitiveType());\
        }\
        for(map<string, WrapperHelper*>::iterator it = dummyComponentClones.begin(); it != dummyComponentClones.end();++it)\
        {\
            StringMapTree* child = new StringMapTree;\
            node->mChildren.push_back(child);\
            it->second->toGrammarMapTree(child);\
        }\
    }\
    void toStringMapTree(StringMapTree* node)\
    {\
        node->mNodeLabel = mClassName;\
        for(map<string, WrapperHelper*>::iterator it = properties.begin(); it != properties.end();++it)\
        {\
            node->mNodeValues[(*it).first] = make_pair((*it).second->mType, (*it).second->asString());\
        }\
        for(map<string, WrapperHelper*>::iterator it = components.begin(); it != components.end();++it)\
        {\
            it->second->toStringMapTree(node);\
        }\
    }\
    void fromStringMapTree(StringMapTree* node)\
    {\
        mClassName = node->mNodeLabel;\
        for(map<string,pair<string,string> >::iterator it = node->mNodeValues.begin(); it != node->mNodeValues.end();++it)\
        {\
            properties[it->first]->fromString(it->second.second);\
        }\
        for(list<StringMapTree*>::iterator it = node->mChildren.begin(); it != node->mChildren.end(); ++it )\
        {\
            string type = (*it)->mNodeLabel;\
            WrapperHelper* wrapper = dummyComponentClones[type]->tryClone(type, (*it));\
            WrapperHelper* complexWrapper = components[type];\
            wrapper->addToComplexWrapper(complexWrapper);\
        }\
    }\
};



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//**************************************************************************************************************************//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//**************************************************************************************************************************//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

OBJECT(IlmSurface)
    PROPERTY(t_ilm_surface, id)
    PROPERTY(t_ilm_float, opacity)
    PROPERTY(t_ilm_uint, sourceX)
    PROPERTY(t_ilm_uint, sourceY)
    PROPERTY(t_ilm_uint, sourceWidth)
    PROPERTY(t_ilm_uint, sourceHeight)
    PROPERTY(t_ilm_uint, origSourceWidth)
    PROPERTY(t_ilm_uint, origSourceHeight)
    PROPERTY(t_ilm_uint, destX)
    PROPERTY(t_ilm_uint, destY)
    PROPERTY(t_ilm_uint, destWidth)
    PROPERTY(t_ilm_uint, destHeight)
    PROPERTY(int, orientation)
    PROPERTY(t_ilm_bool, visibility)
    PROPERTY(t_ilm_uint, frameCounter)
    PROPERTY(t_ilm_uint, drawCounter)
    PROPERTY(t_ilm_uint, updateCounter)
    PROPERTY(t_ilm_uint, pixelformat)
    PROPERTY(t_ilm_uint, nativeSurface)
    PROPERTY(ilmInputDevice, inputDevicesAcceptance)
    /***/
OBJECTEND

OBJECT(IlmLayer)
    PROPERTY(t_ilm_layer, id)
    PROPERTY(t_ilm_float, opacity)
    PROPERTY(t_ilm_uint, sourceX)
    PROPERTY(t_ilm_uint, sourceY)
    PROPERTY(t_ilm_uint, sourceWidth)
    PROPERTY(t_ilm_uint, sourceHeight)
    PROPERTY(t_ilm_uint, origSourceWidth)
    PROPERTY(t_ilm_uint, origSourceHeight)
    PROPERTY(t_ilm_uint, destX)
    PROPERTY(t_ilm_uint, destY)
    PROPERTY(t_ilm_uint, destWidth)
    PROPERTY(t_ilm_uint, destHeight)
    PROPERTY(int, orientation)
    PROPERTY(t_ilm_bool, visibility)
    PROPERTY(t_ilm_uint, type)
    /***/
    CONTAINS(IlmSurface)
OBJECTEND

OBJECT(IlmDisplay)
    PROPERTY(t_ilm_display, id)
    PROPERTY(t_ilm_uint, width)
    PROPERTY(t_ilm_uint, height)
    /***/
    CONTAINS(IlmLayer)
OBJECTEND

OBJECT(IlmScene)
    /***/
    CONTAINS(IlmSurface)
    CONTAINS(IlmLayer)
    CONTAINS(IlmDisplay)
OBJECTEND

#endif /* __SCENESTORE_H__ */