Graphite  Version 3
An experimental 3D geometry processing program
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 
40 #include <OGF/gom/common/common.h>
41 #include <OGF/gom/types/gom.h>
42 #include <OGF/gom/types/arg_list.h>
48 
56 namespace OGF {
57 
58 //_________________________________________________________________________
59 
70  template <class T> class ogf_declare_builtin_type {
71  public:
77  explicit ogf_declare_builtin_type(const std::string& type_name) {
78  // We create the MetaType using a SmartPointer, because
79  // it may be already registered in the Meta repository. If
80  // it is the case, then the SmartPointer will deallocate it.
81  // We need though to call Meta::bind_meta_type() since the
82  // type may be an alias. The result is finally retreived in
83  // the Meta instance (if there was a previous MetaType declared
84  // with the same name, it will use this one).
85  MetaBuiltinType_var meta_type = new MetaBuiltinType(type_name);
86  meta_type->set_serializer(new GenericSerializer<T>);
87  meta_type->set_life_cycle(new GenericLifeCycle<T>);
89  meta_type, typeid(T).name()
90  );
91  result_ = dynamic_cast<MetaBuiltinType*>(
92  Meta::instance()->resolve_meta_type(type_name)
93  );
94  }
99  operator MetaBuiltinType*() {
100  return result_;
101  }
102  private:
103  MetaBuiltinType* result_;
104  };
105 
111  template<> class ogf_declare_builtin_type<bool> {
112  public:
116  explicit ogf_declare_builtin_type(const std::string& type_name) {
117  // We create the MetaType using a SmartPointer, because
118  // it may be already registered in the Meta repository. If
119  // it is the case, then the SmartPointer will deallocate it.
120  // We need though to call Meta::bind_meta_type() since the
121  // type may be an alias. The result is finally retreived in
122  // the Meta instance (if there was a previous MetaType declared
123  // with the same name, it will use this one).
124  MetaBuiltinType_var meta_type = new MetaBuiltinType(type_name);
125  meta_type->set_serializer(new BoolSerializer);
126  meta_type->set_life_cycle(new GenericLifeCycle<bool>);
128  meta_type, typeid(bool).name()
129  );
130  result_ = dynamic_cast<MetaBuiltinType*>(
131  Meta::instance()->resolve_meta_type(type_name)
132  );
133  }
137  operator MetaBuiltinType*() {
138  return result_;
139  }
140  private:
141  MetaBuiltinType* result_;
142  };
143 
149  template<> class ogf_declare_builtin_type<void> {
150  public:
154  explicit ogf_declare_builtin_type(const std::string& type_name) {
155  // We create the MetaType using a SmartPointer, because
156  // it may be already registered in the Meta repository. If
157  // it is the case, then the SmartPointer will deallocate it.
158  // We need though to call Meta::bind_meta_type() since the
159  // type may be an alias. The result is finally retreived in
160  // the Meta instance (if there was a previous MetaType declared
161  // with the same name, it will use this one).
162  MetaBuiltinType_var meta_type = new MetaBuiltinType(type_name);
164  meta_type, typeid(void).name()
165  );
166  result_ = dynamic_cast<MetaBuiltinType*>(
167  Meta::instance()->resolve_meta_type(type_name)
168  );
169  }
173  operator MetaBuiltinType*() {
174  return result_;
175  }
176  private:
177  MetaBuiltinType* result_;
178  };
179 
185  template<> class ogf_declare_builtin_type<std::string> {
186  public:
190  explicit ogf_declare_builtin_type(const std::string& type_name) {
191  // We create the MetaType using a SmartPointer, because
192  // it may be already registered in the Meta repository. If
193  // it is the case, then the SmartPointer will deallocate it.
194  // We need though to call Meta::bind_meta_type() since the
195  // type may be an alias. The result is finally retreived in
196  // the Meta instance (if there was a previous MetaType declared
197  // with the same name, it will use this one).
198  MetaBuiltinType_var meta_type = new MetaBuiltinType(type_name);
199  meta_type->set_serializer(new StringSerializer);
200  meta_type->set_life_cycle(new GenericLifeCycle<std::string>);
202  meta_type, typeid(std::string).name()
203  );
204  result_ = dynamic_cast<MetaBuiltinType*>(
205  Meta::instance()->resolve_meta_type(type_name)
206  );
207  }
211  operator MetaBuiltinType*() {
212  return result_;
213  }
214  private:
215  MetaBuiltinType* result_;
216  };
217 
232  template <class T> class ogf_declare_pointer_type {
233  public:
239  explicit ogf_declare_pointer_type(const std::string& type_name) {
240  // We create the MetaType using a SmartPointer, because
241  // it may be already registered in the Meta repository. If
242  // it is the case, then the SmartPointer will deallocate it.
243  // We need though to call Meta::bind_meta_type() since the
244  // type may be an alias. The result is finally retreived in
245  // the Meta instance (if there was a previous MetaType declared
246  // with the same name, it will use this one).
247  MetaBuiltinType_var meta_type = new MetaBuiltinType(type_name);
248  meta_type->set_serializer(new PointerSerializer);
249  meta_type->set_life_cycle(new GenericLifeCycle<T>);
251  meta_type, typeid(T).name()
252  );
253  result_ = dynamic_cast<MetaBuiltinType*>(
254  Meta::instance()->resolve_meta_type(type_name)
255  );
256  }
261  operator MetaBuiltinType*() {
262  return result_;
263  }
264  private:
265  MetaBuiltinType* result_;
266  };
267 
281  template <class T> class ogf_declare_enum {
282  public:
288  explicit ogf_declare_enum(const std::string& type_name) {
289  MetaEnum* meta_type = new MetaEnum(type_name);
291  meta_type, typeid(T).name()
292  );
293  meta_type->set_life_cycle(new GenericLifeCycle<T>);
294  result_ = meta_type;
295  }
296 
301  operator MetaEnum*() {
302  return result_;
303  }
304  private:
305  MetaEnum* result_;
306  };
307 
320  template <class T> class ogf_declare_class {
321  public:
330  const std::string& class_name, MetaClass* super_class
331  ) {
332  MetaClass* meta_type = new MetaClass(class_name, super_class);
334  meta_type, typeid(T).name()
335  );
336  result_ = meta_type;
337  }
338 
347  const std::string& class_name, const std::string& super_class_name
348  ) {
349  MetaClass* meta_type = new MetaClass(class_name, super_class_name);
351  meta_type, typeid(T).name()
352  );
353  result_ = meta_type;
354  }
355 
361  explicit ogf_declare_class(const std::string& class_name) {
362  MetaClass* meta_type = new MetaClass(class_name);
364  meta_type, typeid(T).name()
365  );
366  result_ = meta_type;
367  }
368 
373  operator MetaClass*() {
374  return result_;
375  }
376  private:
377  MetaClass* result_;
378  };
379 
380 
393  template <class T> class ogf_declare_abstract_class {
394  public:
395 
404  const std::string& class_name, MetaClass* super_class
405  ) {
406  MetaClass* meta_type = new MetaClass(class_name, super_class);
407  meta_type->set_abstract(true);
409  meta_type, typeid(T).name()
410  );
411  result_ = meta_type;
412  }
413 
422  const std::string& class_name, const std::string& super_class_name
423  ) {
424  MetaClass* meta_type = new MetaClass(class_name, super_class_name);
425  meta_type->set_abstract(true);
427  meta_type, typeid(T).name()
428  );
429  result_ = meta_type;
430  }
431 
437  explicit ogf_declare_abstract_class(const std::string& class_name) {
438  MetaClass* meta_type = new MetaClass(class_name);
439  meta_type->set_abstract(true);
441  meta_type, typeid(T).name()
442  );
443  result_ = meta_type;
444  }
445 
450  operator MetaClass*() {
451  return result_;
452  }
453  private:
454  MetaClass* result_;
455  };
456 
457 //_________________________________________________________________________
458 
459 }
460 
461 #endif
Generic arguments and argument lists.
A smart pointer with reference-counted copy semantics.
Definition: smart_pointer.h:76
Implementation of Serializer for bool.
Definition: serializer.h:123
Concrete implementation of LifeCycle.
Definition: life_cycle.h:212
Generic implementation of Serializer.
Definition: serializer.h:206
MetaType for builting types.
Definition: meta_builtin.h:55
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:309
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:276
static Meta * instance()
Gets the instance.
bool bind_meta_type(MetaType *meta_type)
Declares a MetaType to the system.
MetaType * resolve_meta_type(const std::string &type_name) const
Finds a MetaType by type name.
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.
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 generic object lifecycle service.
Definitions common to all include files in the gom library.