Graphite  Version 3
An experimental 3D geometry processing program
meta_type.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_META_TYPES_META_TYPE_H
38 #define H_OGF_META_TYPES_META_TYPE_H
39 
40 #include <OGF/gom/common/common.h>
41 #include <OGF/gom/services/life_cycle.h>
43 #include <OGF/gom/types/arg_list.h>
44 #include <OGF/gom/types/object.h>
45 #include <string>
46 
52 namespace OGF {
53 
63  class GOM_API CustomAttributes {
64  public:
65 
70  size_t nb_custom_attributes() const {
71  return custom_attributes_.nb_args() ;
72  }
73 
80  std::string ith_custom_attribute_name(index_t i) const {
81  return (i < nb_custom_attributes())
82  ? custom_attributes_.ith_arg_name(i)
83  : std::string();
84  }
85 
92  std::string ith_custom_attribute_value(index_t i) const {
93  return (i < nb_custom_attributes())
94  ? custom_attributes_.ith_arg_value(i).as_string()
95  : std::string();
96  }
97 
104  bool has_custom_attribute(const std::string& name) const {
105  return custom_attributes_.has_arg(name) ;
106  }
107 
115  const std::string& name, const std::string& value
116  ) {
117  custom_attributes_.create_arg(name, value) ;
118  }
119 
127  const std::string& name, const std::string& value
128  ) {
129  custom_attributes_.set_arg(name, value) ;
130  }
131 
138  std::string custom_attribute_value(const std::string& name) const {
139  return
140  has_custom_attribute(name) ?
141  custom_attributes_.get_arg(name) : std::string();
142  }
143 
148  custom_attributes_.clear();
149  }
150 
151  private:
152  ArgList custom_attributes_ ;
153  } ;
154 
155 
159  gom_attribute(abstract,"true")
160  gom_class GOM_API MetaInformation : public Object, public CustomAttributes {
161  public:
162  MetaInformation() {
163  }
164  virtual ~MetaInformation() ;
165 
166 
170  virtual void search(
171  const std::string& needle, const std::string& path = ""
172  );
173 
174  gom_slots:
175 
179  size_t nb_custom_attributes() const;
180 
184  bool has_custom_attribute(const std::string& name) const;
185 
189  std::string ith_custom_attribute_name(index_t i) const;
190 
194  std::string ith_custom_attribute_value(index_t i) const;
195 
199  std::string custom_attribute_value(const std::string& name) const;
200 
205  const std::string& name, const std::string& value
206  );
207 
212  const std::string& name, const std::string& value
213  );
214 
215  } ;
216 
220  gom_attribute(abstract,"true")
221  gom_class GOM_API MetaType : public MetaInformation {
222  public:
223 
228  explicit MetaType(const std::string& name) ;
229 
233  ~MetaType() override;
234 
235 
241  const std::string& name() const {
242  return name_ ;
243  }
244 
250  void set_typeid_name(const std::string& typeid_name ) {
251  typeid_name_ = typeid_name ;
252  }
253 
258  const std::string& typeid_name() const {
259  return typeid_name_ ;
260  }
261 
268  return life_cycle_;
269  }
270 
276  void set_life_cycle(LifeCycle* life_cycle) {
277  life_cycle_ = life_cycle;
278  // life_cycle_->ref();
279  }
280 
287  return serializer_ ;
288  }
289 
296  serializer_ = ser ;
297  }
298 
306  virtual void pre_delete();
307 
308  gom_slots:
309 
316  virtual bool is_subtype_of(const MetaType* other) const;
317 
318  gom_properties:
324  const std::string& get_name() const {
325  return name();
326  }
327 
328 
329  private:
330  std::string name_;
331  std::string typeid_name_;
332  LifeCycle_var life_cycle_;
333  Serializer_var serializer_;
334  } ;
335 
340 }
341 
342 #endif
Generic arguments and argument lists.
Represents a list of name-value pairs.
Definition: arg_list.h:65
Stores a set of custom attributes, i.e. name-value pairs attached to the objects.
Definition: meta_type.h:63
void set_custom_attribute(const std::string &name, const std::string &value)
Sets the value of a new custom attribute.
Definition: meta_type.h:126
void create_custom_attribute(const std::string &name, const std::string &value)
Creates a new custom attribute.
Definition: meta_type.h:114
std::string custom_attribute_value(const std::string &name) const
Gets the value of a new custom attribute.
Definition: meta_type.h:138
void clear_custom_attributes()
Clears the custom attributes.
Definition: meta_type.h:147
std::string ith_custom_attribute_name(index_t i) const
Gets the name of a custom attribute by index.
Definition: meta_type.h:80
bool has_custom_attribute(const std::string &name) const
Tests whether a given custom attribute exists.
Definition: meta_type.h:104
size_t nb_custom_attributes() const
Gets the number of custom attributes.
Definition: meta_type.h:70
std::string ith_custom_attribute_value(index_t i) const
Gets the value of a custom attribute by index.
Definition: meta_type.h:92
Manages the life cycle of an object.
Definition: life_cycle.h:59
Base class for everything that resides in the Meta repository.
Definition: meta_type.h:160
bool has_custom_attribute(const std::string &name) const
Tests whether a given custom attribute exists.
virtual void search(const std::string &needle, const std::string &path="")
Displays the names of all objects that contain a substring.
std::string custom_attribute_value(const std::string &name) const
Gets the value of a new custom attribute.
std::string ith_custom_attribute_value(index_t i) const
Gets the value of a custom attribute by index.
std::string ith_custom_attribute_name(index_t i) const
Gets the name of a custom attribute by index.
void set_custom_attribute(const std::string &name, const std::string &value)
Sets the value of a new custom attribute.
void create_custom_attribute(const std::string &name, const std::string &value)
Creates a new custom attribute.
The representation of a type in the Meta repository.
Definition: meta_type.h:221
MetaType(const std::string &name)
MetaType constructor.
const std::string & name() const
Gets the C++ name of the type.
Definition: meta_type.h:241
void set_serializer(Serializer *ser)
Sets the serializer associated with the type.
Definition: meta_type.h:295
void set_typeid_name(const std::string &typeid_name)
Sets the typeid name.
Definition: meta_type.h:250
LifeCycle * life_cycle() const
Gets the LifeCycle associated with the type.
Definition: meta_type.h:267
~MetaType() override
MetaType destructor.
virtual void pre_delete()
Removes all variables that use the meta type system before deleting.
void set_life_cycle(LifeCycle *life_cycle)
Sets the LifeCycle associated with the type.
Definition: meta_type.h:276
Serializer * serializer() const
Gets the serializer associated with the type.
Definition: meta_type.h:286
const std::string & typeid_name() const
Gets the typeid name.
Definition: meta_type.h:258
Base class for all objects in the GOM system.
Definition: object.h:65
Abstract base class for reading and writing values from/to streams.
Definition: serializer.h:58
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Global Graphite namespace.
Definition: common.h:76
SmartPointer< MetaType > MetaType_var
Automatic reference-counted pointer to a MetaType.
Definition: meta_type.h:339
The base class for all objects in the GOM system.
Implementation of generic object lifecycle service.
Definitions common to all include files in the gom library.