Graphite Version 3
An experimental 3D geometry processing program
Loading...
Searching...
No Matches
gom_implementation.h
Go to the documentation of this file.
1/*
2 * GXML/Graphite: Geometry and Graphics Programming Library + Utilities
3 * Copyright (C) 2000 Bruno Levy
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *
19 * If you modify this software, you should include a notice giving the
20 * name of the person performing the modification, the date of modification,
21 * and the reason for such modification.
22 *
23 * Contact: Bruno Levy
24 *
25 * levy@loria.fr
26 *
27 * ISA Project
28 * LORIA, INRIA Lorraine,
29 * Campus Scientifique, BP 239
30 * 54506 VANDOEUVRE LES NANCY CEDEX
31 * FRANCE
32 *
33 * Note that the GNU General Public License does not permit incorporating
34 * the Software into proprietary programs.
35 */
36
37#ifndef H_OGF_GOM_TYPES_GOM_IMPL_H
38#define H_OGF_GOM_TYPES_GOM_IMPL_H
39
41#include <OGF/gom/types/gom.h>
47#include <OGF/gom/reflection/meta_struct.h>
49
57namespace OGF {
58
59//_________________________________________________________________________
60
71 template <class T> class ogf_declare_builtin_type {
72 public:
78 explicit ogf_declare_builtin_type(const std::string& type_name) {
79 // We create the MetaType using a SmartPointer, because
80 // it may be already registered in the Meta repository. If
81 // it is the case, then the SmartPointer will deallocate it.
82 // We need though to call Meta::bind_meta_type() since the
83 // type may be an alias. The result is finally retreived in
84 // the Meta instance (if there was a previous MetaType declared
85 // with the same name, it will use this one).
86 MetaBuiltinType_var meta_type = new MetaBuiltinType(type_name);
87 meta_type->set_serializer(new GenericSerializer<T>);
88 meta_type->set_life_cycle(new GenericLifeCycle<T>);
90 meta_type, typeid(T).name()
91 );
92 result_ = dynamic_cast<MetaBuiltinType*>(
94 );
95 }
100 operator MetaBuiltinType*() {
101 return result_;
102 }
103 private:
104 MetaBuiltinType* result_;
105 };
106
112 template<> class ogf_declare_builtin_type<bool> {
113 public:
117 explicit ogf_declare_builtin_type(const std::string& type_name) {
118 // We create the MetaType using a SmartPointer, because
119 // it may be already registered in the Meta repository. If
120 // it is the case, then the SmartPointer will deallocate it.
121 // We need though to call Meta::bind_meta_type() since the
122 // type may be an alias. The result is finally retreived in
123 // the Meta instance (if there was a previous MetaType declared
124 // with the same name, it will use this one).
125 MetaBuiltinType_var meta_type = new MetaBuiltinType(type_name);
126 meta_type->set_serializer(new BoolSerializer);
127 meta_type->set_life_cycle(new GenericLifeCycle<bool>);
128
130 meta_type, typeid(bool).name()
131 );
132 result_ = dynamic_cast<MetaBuiltinType*>(
134 );
135 }
139 operator MetaBuiltinType*() {
140 return result_;
141 }
142 private:
143 MetaBuiltinType* result_;
144 };
145
151 template<> class ogf_declare_builtin_type<void> {
152 public:
156 explicit ogf_declare_builtin_type(const std::string& type_name) {
157 // We create the MetaType using a SmartPointer, because
158 // it may be already registered in the Meta repository. If
159 // it is the case, then the SmartPointer will deallocate it.
160 // We need though to call Meta::bind_meta_type() since the
161 // type may be an alias. The result is finally retreived in
162 // the Meta instance (if there was a previous MetaType declared
163 // with the same name, it will use this one).
164 MetaBuiltinType_var meta_type = new MetaBuiltinType(type_name);
166 meta_type, typeid(void).name()
167 );
168 result_ = dynamic_cast<MetaBuiltinType*>(
170 );
171 }
175 operator MetaBuiltinType*() {
176 return result_;
177 }
178 private:
179 MetaBuiltinType* result_;
180 };
181
187 template<> class ogf_declare_builtin_type<std::string> {
188 public:
192 explicit ogf_declare_builtin_type(const std::string& type_name) {
193 // We create the MetaType using a SmartPointer, because
194 // it may be already registered in the Meta repository. If
195 // it is the case, then the SmartPointer will deallocate it.
196 // We need though to call Meta::bind_meta_type() since the
197 // type may be an alias. The result is finally retreived in
198 // the Meta instance (if there was a previous MetaType declared
199 // with the same name, it will use this one).
200 MetaBuiltinType_var meta_type = new MetaBuiltinType(type_name);
201 meta_type->set_serializer(new StringSerializer);
202 meta_type->set_life_cycle(new GenericLifeCycle<std::string>);
204 meta_type, typeid(std::string).name()
205 );
206 result_ = dynamic_cast<MetaBuiltinType*>(
208 );
209 }
213 operator MetaBuiltinType*() {
214 return result_;
215 }
216 private:
217 MetaBuiltinType* result_;
218 };
219
234 template <class T> class ogf_declare_pointer_type {
235 public:
241 explicit ogf_declare_pointer_type(const std::string& type_name) {
242 // We create the MetaType using a SmartPointer, because
243 // it may be already registered in the Meta repository. If
244 // it is the case, then the SmartPointer will deallocate it.
245 // We need though to call Meta::bind_meta_type() since the
246 // type may be an alias. The result is finally retreived in
247 // the Meta instance (if there was a previous MetaType declared
248 // with the same name, it will use this one).
249 MetaBuiltinType_var meta_type = new MetaBuiltinType(type_name);
250 meta_type->set_serializer(new PointerSerializer);
251 meta_type->set_life_cycle(new GenericLifeCycle<T>);
253 meta_type, typeid(T).name()
254 );
255 result_ = dynamic_cast<MetaBuiltinType*>(
257 );
258 }
263 operator MetaBuiltinType*() {
264 return result_;
265 }
266 private:
267 MetaBuiltinType* result_;
268 };
269
283 template <class T> class ogf_declare_enum {
284 public:
290 explicit ogf_declare_enum(const std::string& type_name) {
291 MetaEnum* meta_type = new MetaEnum(type_name);
293 meta_type, typeid(T).name()
294 );
295 meta_type->set_life_cycle(new GenericLifeCycle<T>);
296 result_ = meta_type;
297 }
298
303 operator MetaEnum*() {
304 return result_;
305 }
306 private:
307 MetaEnum* result_;
308 };
309
310 /***************************************************************************/
311
312#define ogf_offset(structtype,field) \
313 &(reinterpret_cast<structtype*>(0)->field)
314
315#define ogf_add_field(structtype, field) \
316 add_field(#field, ogf_offset(structtype, field))
317
330 template <class T> class ogf_declare_struct {
331 public:
337 explicit ogf_declare_struct(const std::string& type_name) {
338 MetaBuiltinStruct* meta_type = new MetaBuiltinStruct(type_name);
340 meta_type, typeid(T).name()
341 );
342 //meta_type->set_serializer(new GenericSerializer<T>);
343 meta_type->set_life_cycle(new GenericLifeCycle<T>);
344 result_ = meta_type;
345 }
346
351 operator MetaBuiltinStruct*() {
352 return result_;
353 }
354
362 return result_;
363 }
364
365 private:
366 MetaBuiltinStruct* result_;
367 };
368
369 /***************************************************************************/
370
383 template <class T> class ogf_declare_class {
384 public:
393 const std::string& class_name, MetaClass* super_class
394 ) {
395 MetaClass* meta_type = new MetaClass(class_name, super_class);
397 meta_type, typeid(T).name()
398 );
399 result_ = meta_type;
400 }
401
410 const std::string& class_name, const std::string& super_class_name
411 ) {
412 MetaClass* meta_type = new MetaClass(class_name, super_class_name);
414 meta_type, typeid(T).name()
415 );
416 result_ = meta_type;
417 }
418
424 explicit ogf_declare_class(const std::string& class_name) {
425 MetaClass* meta_type = new MetaClass(class_name);
427 meta_type, typeid(T).name()
428 );
429 result_ = meta_type;
430 }
431
436 operator MetaClass*() {
437 return result_;
438 }
439 private:
440 MetaClass* result_;
441 };
442
443
456 template <class T> class ogf_declare_abstract_class {
457 public:
458
467 const std::string& class_name, MetaClass* super_class
468 ) {
469 MetaClass* meta_type = new MetaClass(class_name, super_class);
470 meta_type->set_abstract(true);
472 meta_type, typeid(T).name()
473 );
474 result_ = meta_type;
475 }
476
485 const std::string& class_name, const std::string& super_class_name
486 ) {
487 MetaClass* meta_type = new MetaClass(class_name, super_class_name);
488 meta_type->set_abstract(true);
490 meta_type, typeid(T).name()
491 );
492 result_ = meta_type;
493 }
494
500 explicit ogf_declare_abstract_class(const std::string& class_name) {
501 MetaClass* meta_type = new MetaClass(class_name);
502 meta_type->set_abstract(true);
504 meta_type, typeid(T).name()
505 );
506 result_ = meta_type;
507 }
508
513 operator MetaClass*() {
514 return result_;
515 }
516 private:
517 MetaClass* result_;
518 };
519
520//_________________________________________________________________________
521
522}
523
524#endif
Generic arguments and argument lists.
Concrete implementation of LifeCycle.
Definition life_cycle.h:252
A smart pointer with reference-counted copy semantics.
Implementation of Serializer for bool.
Definition serializer.h:123
Generic implementation of Serializer.
Definition serializer.h:206
MetaType for raw C++ structs.
Definition meta_struct.h:89
MetaType for builting types.
The representation of a class in the Meta repository.
Definition meta_class.h:64
void set_abstract(bool b)
Indicate that the class is abstract.
Definition meta_class.h:316
MetaType for enums.
Definition meta_enum.h:56
void set_life_cycle(LifeCycle *life_cycle)
Sets the LifeCycle associated with the type.
Definition meta_type.h:277
MetaType * resolve_meta_type(const std::string &type_name) const
Finds a MetaType by type name.
static Meta * instance()
Gets the instance.
bool bind_meta_type(MetaType *meta_type)
Declares a MetaType to the system.
Implementation of Serializer for pointers.
Definition serializer.h:145
Implementation of Serializer for std::string.
Definition serializer.h:101
A class to declare an abstract class type.
ogf_declare_abstract_class(const std::string &class_name, const std::string &super_class_name)
Declares a new abstract class type.
ogf_declare_abstract_class(const std::string &class_name)
Declares a new abstract class type.
ogf_declare_abstract_class(const std::string &class_name, MetaClass *super_class)
Declares a new abstract class type.
ogf_declare_builtin_type(const std::string &type_name)
Declares a new builtin type.
ogf_declare_builtin_type(const std::string &type_name)
Declares a new builtin type.
ogf_declare_builtin_type(const std::string &type_name)
Declares a new builtin type.
A class to declare a new builtin type.
ogf_declare_builtin_type(const std::string &type_name)
Declares a new builtin type.
A class to declare a class type.
ogf_declare_class(const std::string &class_name)
Declares a new class type.
ogf_declare_class(const std::string &class_name, MetaClass *super_class)
Declares a new class type.
ogf_declare_class(const std::string &class_name, const std::string &super_class_name)
Declares a new class type.
A class to declare a new enum type.
ogf_declare_enum(const std::string &type_name)
Declares a new enum type.
a version of ogf_declare_builtin_type specialization for pointers.
ogf_declare_pointer_type(const std::string &type_name)
Declares a new builtin pointer type.
A class to declare a new struct type.
MetaBuiltinStruct * operator->()
Gets the created MetaBuiltinStruct object.
ogf_declare_struct(const std::string &type_name)
Declares a new struct type.
Includes the files needed to implement GOM objects.
MetaType for builting types.
MetaType for classes.
MetaType for enums.
Base class for meta informations.
Global Graphite namespace.
Definition common.h:76
Implementation of the generic serialization mechanism.
Definitions common to all include files in the gom library.