Graphite  Version 3
An experimental 3D geometry processing program
object.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_OBJECT_H
38 #define H_OGF_GOM_TYPES_OBJECT_H
39 
40 #include <OGF/gom/common/common.h>
41 #include <OGF/gom/types/gom_defs.h>
42 #include <OGF/gom/types/arg_list.h>
43 
44 #include <string>
45 #include <vector>
46 
52 namespace OGF {
53 
54  class MetaType;
55  class MetaClass;
56  class Object;
57  class Connection;
58  class ConnectionTable;
59  class Interpreter;
60 
64  gom_attribute(abstract,"true")
65  gom_class GOM_API Object : public Counted {
66  public:
73  explicit Object(bool transient = false);
74 
78  virtual ~Object();
79 
80  // Run-time type information
81 
86  virtual MetaClass* meta_class() const;
87 
95  virtual void set_meta_class(MetaClass* mclass);
96 
107  unsigned int id() const {
108  return id_;
109  }
110 
118  std::string string_id() const;
119 
120  // Properties and Dynamic invokation interface
121 
128  bool has_method(const std::string& method_name) const;
129 
139  virtual bool invoke_method(
140  const std::string& method_name,
141  const ArgList& args, Any& ret_val
142  );
143 
154  const std::string& method_name, const ArgList& args
155  ) {
156  Any ret_val;
157  return invoke_method(method_name, args, ret_val);
158  }
159 
168  bool invoke_method(const std::string& method_name) {
169  ArgList args;
170  Any ret_val;
171  return invoke_method(method_name, args, ret_val);
172  }
173 
180  bool has_property(const std::string& prop_name) const;
181 
189  virtual bool get_property(
190  const std::string& prop_name, std::string& prop_value
191  ) const;
192 
193  // ************** Signals and slots *************************
194 
203  const std::string& signal_name,
204  Object* to, const std::string& slot_name
205  );
206 
211  virtual void add_connection(Connection* connection);
212 
217  virtual void remove_connection(Connection* connection);
218 
226  static Object* id_to_object(unsigned int id) {
227  if(id_to_object_ == nullptr) {
228  return nullptr;
229  }
230  auto it = id_to_object_->find(id);
231  if(it == id_to_object_->end()) {
232  return nullptr;
233  }
234  return it->second;
235  }
236 
244  virtual void get_element(index_t i, Any& value) const;
245 
253  virtual void set_element(index_t i, const Any& value);
254 
261  virtual void search(
262  const std::string& needle, const std::string& path=""
263  );
264 
265  gom_properties:
266 
272  virtual index_t get_nb_elements() const;
273 
279  bool get_signals_enabled() const {
280  return signals_enabled_;
281  }
282 
288  void set_signals_enabled(bool value) {
289  signals_enabled_ = value;
290  }
291 
297  bool get_slots_enabled() const {
298  return slots_enabled_;
299  }
300 
306  void set_slots_enabled(bool value) {
307  slots_enabled_ = value;
308  }
309 
315  return meta_class();
316  }
317 
325  std::string get_string_id() const {
326  return string_id();
327  }
328 
334  virtual std::string get_doc() const;
335 
336 
337  gom_slots:
338 
347  bool equals(const Object* other) const;
348 
357  virtual Sign compare(const Object* other) const;
358 
359 
360 
367  virtual bool is_a(const MetaType* type) const;
368 
375  void disconnect();
376 
380  void enable_signals() {
381  signals_enabled_ = true;
382  }
383 
388  signals_enabled_ = false;
389  }
390 
394  void enable_slots() {
395  slots_enabled_ = true;
396  }
397 
401  void disable_slots() {
402  slots_enabled_ = false;
403  }
404 
409  void set_properties(const ArgList& args);
410 
418  virtual bool set_property(
419  const std::string& name, const std::string& value
420  );
421 
426  void help() const;
427 
428  public:
429  // Note: set_property() variants that are not slots
430  // need to be declared *after* the set_property() slot
431  // else gomgen does not see the set_property slot.
432 
440  virtual bool set_property(
441  const std::string& name, const Any& value
442  );
443 
451  virtual bool get_property(
452  const std::string& prop_name, Any& prop_value
453  ) const;
454 
455  protected:
456 
469  virtual bool emit_signal(
470  const std::string& signal_name, const ArgList& args,
471  bool called_from_slot = false
472  );
473 
474  private:
475  MetaClass* meta_class_;
476  ConnectionTable* connections_;
477  bool signals_enabled_;
478  bool slots_enabled_;
479  unsigned int id_;
480 
481  // Signal method adapter needs to call
482  // emit_signal() which is protected.
483  friend class MetaMethod;
484  static std::map<index_t, Object*>* id_to_object_;
485  };
486 
487  /**************************************************************/
488 
493 
494  /**************************************************************/
495 
496 }
497 
498 #endif
Generic arguments and argument lists.
Base class for reference-counted objects.
Definition: counted.h:71
A class that stores a variable of arbitrary type.
Definition: any.h:62
Represents a list of name-value pairs.
Definition: arg_list.h:65
The representation of a class in the Meta repository.
Definition: meta_class.h:64
The representation of a method in the Meta repository.
Definition: meta_method.h:72
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
bool has_method(const std::string &method_name) const
Tests whether a method is defined.
virtual ~Object()
Object destructor.
virtual void set_element(index_t i, const Any &value)
Sets an element by index.
static Object * id_to_object(unsigned int id)
Gets an object from a unique object id.
Definition: object.h:226
virtual bool set_property(const std::string &name, const Any &value)
Sets an individual property.
virtual std::string get_doc() const
Gets the documentation.
virtual bool is_a(const MetaType *type) const
Tests whether this object inherits a given type.
virtual MetaClass * meta_class() const
Gets the meta class.
MetaClass * get_meta_class() const
Gets the meta class.
Definition: object.h:314
virtual bool set_property(const std::string &name, const std::string &value)
Sets an individual property.
bool get_signals_enabled() const
Tests wheter signals are enabled.
Definition: object.h:279
void help() const
Displays some help about this object.
void enable_slots()
Enables slots.
Definition: object.h:394
void disconnect()
Removes all connections from signals of this objects.
void set_signals_enabled(bool value)
Enables or disables signals.
Definition: object.h:288
virtual bool emit_signal(const std::string &signal_name, const ArgList &args, bool called_from_slot=false)
Emits a signal and calls the slots it is connected to.
void set_properties(const ArgList &args)
Sets several properties in a single call.
std::string get_string_id() const
Gets the unique string identifier.
Definition: object.h:325
void enable_signals()
Enables signals.
Definition: object.h:380
void set_slots_enabled(bool value)
Enables or disables slots.
Definition: object.h:306
Object(bool transient=false)
Object constructor.
virtual void add_connection(Connection *connection)
Adds a connection to this object.
virtual void set_meta_class(MetaClass *mclass)
Sets the meta class.
std::string string_id() const
Gets the unique string identifier.
virtual void remove_connection(Connection *connection)
Removes a connection to this object.
virtual void get_element(index_t i, Any &value) const
Gets an element by index.
virtual void search(const std::string &needle, const std::string &path="")
Displays the names of all objects that contain a substring.
void disable_slots()
Disables slots.
Definition: object.h:401
void disable_signals()
Disables signals.
Definition: object.h:387
bool get_slots_enabled() const
Tests wheter slots are enabled.
Definition: object.h:297
virtual Sign compare(const Object *other) const
Compares this object with another one.
bool invoke_method(const std::string &method_name)
Invokes a method by method name.
Definition: object.h:168
bool has_property(const std::string &prop_name) const
Tests whether a property is defined.
virtual bool get_property(const std::string &prop_name, std::string &prop_value) const
Gets a property.
virtual bool get_property(const std::string &prop_name, Any &prop_value) const
Gets a property.
unsigned int id() const
Gets the identifier of this object.
Definition: object.h:107
virtual bool invoke_method(const std::string &method_name, const ArgList &args, Any &ret_val)
Invokes a method by method name and argument list, and gets the return value.
bool invoke_method(const std::string &method_name, const ArgList &args)
Invokes a method by method name and argument list.
Definition: object.h:153
virtual Connection * connect_signal_to_slot(const std::string &signal_name, Object *to, const std::string &slot_name)
Connects a signal with a slot of another object.
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Sign
Integer constants that represent the sign of a value.
Definition: numeric.h:68
Global Graphite namespace.
Definition: common.h:76
SmartPointer< Object > Object_var
An automatic reference-counted pointer to an Object.
Definition: object.h:492
Definitions common to all include files in the gom library.