Graphite Version 3
An experimental 3D geometry processing program
Loading...
Searching...
No Matches
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
48
49#include <set>
50#include <map>
51
57namespace 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 gom_properties:
307 Object* get_instance() const;
308
309 public:
310
316 void set_abstract(bool b) {
317 abstract_ = b;
318 }
319
320
327 void add_member(MetaMember* member) {
328 members_.push_back(member);
329 }
330
338 std::vector<MetaMember*>& result, bool super = true
339 ) const {
340 result.clear();
341 append_members(result, super);
342 }
343
353 std::vector<MetaMethod*>& result, bool super = true
354 ) const {
355 result.clear();
356 append_methods(result, super);
357 }
358
366 std::vector<MetaSignal*>& result, bool super = true
367 ) const {
368 result.clear();
369 append_signals(result, super);
370 }
371
379 std::vector<MetaSlot*>& result, bool super = true
380 ) const {
381 result.clear();
382 append_slots(result, super);
383 }
384
392 std::vector<MetaProperty*>& result, bool super = true
393 ) const {
394 result.clear();
395 append_properties(result, super);
396 }
397
402 void get_constructors(std::vector<MetaConstructor*>& result) const;
403
407 bool is_subtype_of(const MetaType* other) const override;
408
419 std::set<std::string>& used_types, bool super = true
420 ) const;
421
432
440 Factory* factory() const {
441 return factory_;
442 }
443
450 factory_ = f;
451 }
452
456 void search(
457 const std::string& needle, const std::string& path = ""
458 ) override;
459
463 std::string get_doc() const override;
464
469 void set_instance(Object* object) {
470 instance_ = object;
471 }
472
473 protected:
474
482 std::string new_constructor_name() const;
483
491 std::vector<MetaMember*>& result, bool super = true
492 ) const;
493
503 std::vector<MetaMethod*>& result, bool super = true
504 ) const;
505
513 std::vector<MetaSignal*>& result, bool super = true
514 ) const;
515
523 std::vector<MetaSlot*>& result, bool super = true
524 ) const;
525
533 std::vector<MetaProperty*>& result, bool super = true
534 ) const;
535
536 private:
537 std::string super_class_name_;
538 std::vector<MetaMember_var> members_;
539 bool abstract_;
540 Factory_var factory_;
541 friend class ::OGF::MetaConstructor;
542 Object* instance_; // For singletons
543 };
544
549
550 /*******************************************************************/
551
555 class GOM_API FactoryMetaClass : public Factory {
556 public:
561 FactoryMetaClass(MetaClass* mclass) : meta_class_(mclass) {
562 }
563
572 Object* create(const ArgList& args) override ;
573
579 return meta_class_;
580 }
581
582 private:
583 MetaClass* meta_class_;
584 };
585
586 /*******************************************************************/
587}
588#endif
Represents a list of name-value pairs.
Definition arg_list.h:65
A Factory that uses a MetaClass.
Definition meta_class.h:555
Object * create(const ArgList &args) override
Creates an objet.
FactoryMetaClass(MetaClass *mclass)
FactoryMetaClass constructor.
Definition meta_class.h:561
MetaClass * meta_class() const
Gets the MetaClass.
Definition meta_class.h:578
Creates instances of a specific class.
Definition factory.h:61
The representation of a class in the Meta repository.
Definition meta_class.h:64
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:337
MetaMember * ith_member(index_t i, bool super=true) const
Gets a MetaMember by index.
void get_constructors(std::vector< MetaConstructor * > &result) const
Gets all the constructors.
MetaConstructor * ith_constructor(index_t i) const
Gets a MetaConstructor by index.
MetaConstructor * best_constructor(const ArgList &args)
Gets the best constructors for the specified arguments.
void set_factory(Factory *f)
Sets the factory.
Definition meta_class.h:449
void append_slots(std::vector< MetaSlot * > &result, bool super=true) const
Gets all the slots and appends them to a vector.
MetaSignal * find_signal(const std::string &signal_name, bool super=true) const
Finds a MetaSignal by name.
virtual bool is_subclass_of(const MetaClass *other) const
Tests whether this MetaClass is a subclass of another MetaClass.
size_t nb_constructors() const
Gets the number of constructors.
MetaProperty * find_property(const std::string &property_name, bool super=true) const
Finds a MetaProperty by name.
MetaMethod * find_method(const std::string &method_name, bool super=true) const
Finds a MetaMethod by name.
void get_properties(std::vector< MetaProperty * > &result, bool super=true) const
Gets all the properties.
Definition meta_class.h:391
Factory * factory() const
Gets the factory.
Definition meta_class.h:440
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:365
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:327
std::string get_doc() const override
Gets the documentation.
MetaSignal * ith_signal(index_t i, bool super=true) const
Gets a MetaSignal by index.
virtual MetaClass * create_subclass(const std::string &name, bool is_abstract=false)
Creates a new subclass dynamically.
void set_abstract(bool b)
Indicate that the class is abstract.
Definition meta_class.h:316
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:352
MetaMember * find_member(const std::string &member_name, bool super=true) const
Finds a MetaMember by name.
size_t nb_slots(bool super=true) const
Gets the number of slots.
const std::string & super_class_name() const
Gets the name of the super class.
Definition meta_class.h:118
MetaSlot * find_slot(const std::string &slot_name, bool super=true) const
Finds a MetaSlot by name.
Object * create(const ArgList &args)
Creates an object of this class.
MetaProperty * ith_property(index_t i, bool super=true) const
Gets a MetaProperty by index.
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.
void set_instance(Object *object)
For singletons, sets instance.
Definition meta_class.h:469
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.
MetaSlot * ith_slot(index_t i, bool super=true) const
Gets a MetaSlot by index.
void get_slots(std::vector< MetaSlot * > &result, bool super=true) const
Gets all the slots.
Definition meta_class.h:378
size_t nb_signals(bool super=true) const
Gets the number of signals.
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.
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:222
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:548
Definitions common to all include files in the gom library.
Classes to create objects from type name and argument list.