Graphite  Version 3
An experimental 3D geometry processing program
meta_class.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_CLASS_H
38 #define H_OGF_META_TYPES_META_CLASS_H
39 
40 #include <OGF/gom/common/common.h>
48 
49 #include <set>
50 #include <map>
51 
57 namespace OGF {
58 
59  class ArgList;
60 
64  gom_class GOM_API MetaClass : public MetaType {
65  public:
66 
76  explicit MetaClass(
77  const std::string& class_name, MetaClass* super_class = nullptr,
78  bool is_abstract = false
79  );
80 
89  explicit MetaClass(
90  const std::string& class_name,
91  const std::string& super_class_name,
92  bool is_abstract = false
93  );
94 
98  ~MetaClass() override;
99 
103  void pre_delete() override;
104 
105  gom_slots:
106 
112  MetaClass* super_class() const;
113 
118  const std::string& super_class_name() const {
119  return super_class_name_;
120  }
121 
127  bool is_abstract() const {
128  return abstract_;
129  }
130 
138  Object* create(const ArgList& args);
139 
149  size_t nb_members(bool super = true) const;
150 
157  MetaMember* ith_member(index_t i, bool super = true) const;
158 
167  const std::string& member_name, bool super = true
168  ) const;
169 
170 
178  size_t nb_signals(bool super = true) const;
179 
186  MetaSignal* ith_signal(index_t i, bool super = true) const;
187 
195  size_t nb_slots(bool super = true) const;
196 
203  MetaSlot* ith_slot(index_t i, bool super = true) const;
204 
212  size_t nb_properties(bool super = true) const;
213 
214 
221  MetaProperty* ith_property(index_t i, bool super = true) const;
222 
227  size_t nb_constructors() const;
228 
235 
246  const std::string& method_name, bool super = true
247  ) const;
248 
257  const std::string& slot_name, bool super = true
258  ) const;
259 
268  const std::string& signal_name, bool super = true
269  ) const;
270 
279  const std::string& property_name, bool super = true
280  ) const;
281 
291  const std::string& name, bool is_abstract=false
292  );
293 
300  virtual bool is_subclass_of(const MetaClass* other) const;
301 
302  public:
303 
309  void set_abstract(bool b) {
310  abstract_ = b;
311  }
312 
313 
320  void add_member(MetaMember* member) {
321  members_.push_back(member);
322  }
323 
331  std::vector<MetaMember*>& result, bool super = true
332  ) const {
333  result.clear();
334  append_members(result, super);
335  }
336 
346  std::vector<MetaMethod*>& result, bool super = true
347  ) const {
348  result.clear();
349  append_methods(result, super);
350  }
351 
359  std::vector<MetaSignal*>& result, bool super = true
360  ) const {
361  result.clear();
362  append_signals(result, super);
363  }
364 
371  void get_slots(
372  std::vector<MetaSlot*>& result, bool super = true
373  ) const {
374  result.clear();
375  append_slots(result, super);
376  }
377 
385  std::vector<MetaProperty*>& result, bool super = true
386  ) const {
387  result.clear();
388  append_properties(result, super);
389  }
390 
395  void get_constructors(std::vector<MetaConstructor*>& result) const;
396 
400  bool is_subtype_of(const MetaType* other) const override;
401 
412  std::set<std::string>& used_types, bool super = true
413  ) const;
414 
425 
433  Factory* factory() const {
434  return factory_;
435  }
436 
442  void set_factory(Factory* f) {
443  factory_ = f;
444  }
445 
449  void search(const std::string& needle, const std::string& path = "") override;
450 
454  std::string get_doc() const override;
455 
456 
457  protected:
458 
466  std::string new_constructor_name() const;
467 
475  std::vector<MetaMember*>& result, bool super = true
476  ) const;
477 
487  std::vector<MetaMethod*>& result, bool super = true
488  ) const;
489 
497  std::vector<MetaSignal*>& result, bool super = true
498  ) const;
499 
507  std::vector<MetaSlot*>& result, bool super = true
508  ) const;
509 
517  std::vector<MetaProperty*>& result, bool super = true
518  ) const;
519 
520  private:
521  std::string super_class_name_;
522  std::vector<MetaMember_var> members_;
523  bool abstract_;
524  Factory_var factory_;
525  friend class ::OGF::MetaConstructor;
526  };
527 
532 
533  /*******************************************************************/
534 
538  class GOM_API FactoryMetaClass : public Factory {
539  public:
544  FactoryMetaClass(MetaClass* mclass) : meta_class_(mclass) {
545  }
546 
555  virtual Object* create(const ArgList& args);
556 
562  return meta_class_;
563  }
564 
565  private:
566  MetaClass* meta_class_;
567  };
568 
569  /*******************************************************************/
570 }
571 #endif
Represents a list of name-value pairs.
Definition: arg_list.h:65
A Factory that uses a MetaClass.
Definition: meta_class.h:538
virtual Object * create(const ArgList &args)
Creates an objet.
FactoryMetaClass(MetaClass *mclass)
FactoryMetaClass constructor.
Definition: meta_class.h:544
MetaClass * meta_class() const
Gets the MetaClass.
Definition: meta_class.h:561
Creates instances of a specific class.
Definition: factory.h:61
The representation of a class in the Meta repository.
Definition: meta_class.h:64
MetaMember * ith_member(index_t i, bool super=true) const
Gets a MetaMember by index.
void search(const std::string &needle, const std::string &path="") override
Displays the names of all objects that contain a substring.
void get_members(std::vector< MetaMember * > &result, bool super=true) const
Gets all the members.
Definition: meta_class.h:330
void get_constructors(std::vector< MetaConstructor * > &result) const
Gets all the constructors.
MetaSlot * find_slot(const std::string &slot_name, bool super=true) const
Finds a MetaSlot by name.
MetaSignal * find_signal(const std::string &signal_name, bool super=true) const
Finds a MetaSignal by name.
void set_factory(Factory *f)
Sets the factory.
Definition: meta_class.h:442
const std::string & super_class_name() const
Gets the name of the super class.
Definition: meta_class.h:118
void append_slots(std::vector< MetaSlot * > &result, bool super=true) const
Gets all the slots and appends them to a vector.
virtual bool is_subclass_of(const MetaClass *other) const
Tests whether this MetaClass is a subclass of another MetaClass.
MetaMethod * find_method(const std::string &method_name, bool super=true) const
Finds a MetaMethod by name.
size_t nb_constructors() const
Gets the number of constructors.
MetaConstructor * best_constructor(const ArgList &args)
Gets the best constructors for the specified arguments.
void get_properties(std::vector< MetaProperty * > &result, bool super=true) const
Gets all the properties.
Definition: meta_class.h:384
MetaProperty * find_property(const std::string &property_name, bool super=true) const
Finds a MetaProperty by name.
Object * create(const ArgList &args)
Creates an object of this class.
MetaSlot * ith_slot(index_t i, bool super=true) const
Gets a MetaSlot by index.
void get_used_types(std::set< std::string > &used_types, bool super=true) const
Gets all the types used by this class.
size_t nb_members(bool super=true) const
Gets the number of class members.
void get_signals(std::vector< MetaSignal * > &result, bool super=true) const
Gets all the signals.
Definition: meta_class.h:358
bool is_subtype_of(const MetaType *other) const override
void add_member(MetaMember *member)
Adds a new MetaMember to this class.
Definition: meta_class.h:320
MetaConstructor * ith_constructor(index_t i) const
Gets a MetaConstructor by index.
virtual MetaClass * create_subclass(const std::string &name, bool is_abstract=false)
Creates a new subclass dynamically.
std::string get_doc() const override
Gets the documentation.
MetaProperty * ith_property(index_t i, bool super=true) const
Gets a MetaProperty by index.
void set_abstract(bool b)
Indicate that the class is abstract.
Definition: meta_class.h:309
MetaClass(const std::string &class_name, const std::string &super_class_name, bool is_abstract=false)
Constructs a new MetaClass.
void get_methods(std::vector< MetaMethod * > &result, bool super=true) const
Gets all the methods.
Definition: meta_class.h:345
size_t nb_slots(bool super=true) const
Gets the number of slots.
void append_properties(std::vector< MetaProperty * > &result, bool super=true) const
Gets all the properties.
void append_methods(std::vector< MetaMethod * > &result, bool super=true) const
Gets all the methods and appends them to a vector.
bool is_abstract() const
Tests if the class is abstract.
Definition: meta_class.h:127
void pre_delete() override
Removes all variables that use the meta type system before deleting.
~MetaClass() override
MetaClass destructor.
Factory * factory() const
Gets the factory.
Definition: meta_class.h:433
void get_slots(std::vector< MetaSlot * > &result, bool super=true) const
Gets all the slots.
Definition: meta_class.h:371
size_t nb_signals(bool super=true) const
Gets the number of signals.
MetaSignal * ith_signal(index_t i, bool super=true) const
Gets a MetaSignal by index.
std::string new_constructor_name() const
Generates a dummy name for a constructor.
void append_signals(std::vector< MetaSignal * > &result, bool super=true) const
Gets all the signals and appends them to a vector.
MetaMember * find_member(const std::string &member_name, bool super=true) const
Finds a MetaMember by name.
MetaClass(const std::string &class_name, MetaClass *super_class=nullptr, bool is_abstract=false)
Constructs a new MetaClass.
void append_members(std::vector< MetaMember * > &result, bool super=true) const
Gets all the members and appends them to a vector.
size_t nb_properties(bool super=true) const
Gets the number of properties.
The representation of a constructor in the Meta repository.
The base class for class members in the Meta repository.
Definition: meta_member.h:56
The representation of a method in the Meta repository.
Definition: meta_method.h:72
The representation of a property in the Meta repository.
The representation of a signal in the Meta repository.
Definition: meta_signal.h:54
The representation of a slot in the Meta repository.
Definition: meta_slot.h:55
The representation of a type in the Meta repository.
Definition: meta_type.h:221
Base class for all objects in the GOM system.
Definition: object.h:65
Meta-information attached to arguments.
Meta-information attached to constructors.
representation of properties in the Meta system
Meta-information attached to signals.
Meta-information attached to slots.
Base class for meta informations.
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Global Graphite namespace.
Definition: common.h:76
SmartPointer< MetaClass > MetaClass_var
An automatic reference-counted pointer to a MetaClass.
Definition: meta_class.h:531
Definitions common to all include files in the gom library.
Classes to create objects from type name and argument list.