Graphite Version 3
An experimental 3D geometry processing program
Loading...
Searching...
No Matches
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
43
44#include <string>
45#include <vector>
46
52namespace 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:
67 static constexpr Numeric::uint32 INVALID_ID = 0xbadbeef;
68
75 explicit Object(bool transient = false);
76
80 ~Object() override;
81
82 // Run-time type information
83
88 virtual MetaClass* meta_class() const;
89
97 virtual void set_meta_class(MetaClass* mclass);
98
110 return id_;
111 }
112
120 std::string string_id() const;
121
122 // Properties and Dynamic invokation interface
123
130 bool has_method(const std::string& method_name) const;
131
141 virtual bool invoke_method(
142 const std::string& method_name,
143 const ArgList& args, Any& ret_val
144 );
145
156 const std::string& method_name, const ArgList& args
157 ) {
158 Any ret_val;
159 return invoke_method(method_name, args, ret_val);
160 }
161
170 bool invoke_method(const std::string& method_name) {
171 ArgList args;
172 Any ret_val;
173 return invoke_method(method_name, args, ret_val);
174 }
175
182 bool has_property(const std::string& prop_name) const;
183
191 virtual bool get_property(
192 const std::string& prop_name, std::string& prop_value
193 ) const;
194
195 // ************** Signals and slots *************************
196
205 const std::string& signal_name,
206 Object* to, const std::string& slot_name
207 );
208
213 virtual void add_connection(Connection* connection);
214
219 virtual void remove_connection(Connection* connection);
220
228 static Object* id_to_object(unsigned int id) {
229 if(id_to_object_ == nullptr) {
230 return nullptr;
231 }
232 auto it = id_to_object_->find(id);
233 if(it == id_to_object_->end()) {
234 return nullptr;
235 }
236 return it->second;
237 }
238
246 virtual void get_element(index_t i, Any& value) const;
247
255 virtual void set_element(index_t i, const Any& value);
256
264 index_t item, index_t component, Any& value
265 ) const {
266 get_element(item * get_dimension() + component, value);
267 }
268
276 index_t item, index_t component, const Any& value
277 ) {
278 set_element(item * get_dimension() + component, value);
279 }
280
287 virtual void search(
288 const std::string& needle, const std::string& path=""
289 );
290
291 gom_properties:
292
298 virtual index_t get_nb_elements() const;
299
300
306 virtual index_t get_dimension() const;
307
313 bool get_signals_enabled() const {
314 return signals_enabled_;
315 }
316
322 void set_signals_enabled(bool value) {
323 signals_enabled_ = value;
324 }
325
331 bool get_slots_enabled() const {
332 return slots_enabled_;
333 }
334
340 void set_slots_enabled(bool value) {
341 slots_enabled_ = value;
342 }
343
349 return meta_class();
350 }
351
359 std::string get_string_id() const {
360 return string_id();
361 }
362
368 virtual std::string get_doc() const;
369
370
371 gom_slots:
372
381 bool equals(const Object* other) const;
382
391 virtual Sign compare(const Object* other) const;
392
393
394
401 virtual bool is_a(const MetaType* type) const;
402
410
415 signals_enabled_ = true;
416 }
417
422 signals_enabled_ = false;
423 }
424
429 slots_enabled_ = true;
430 }
431
436 slots_enabled_ = false;
437 }
438
443 void set_properties(const ArgList& args);
444
452 virtual bool set_property(
453 const std::string& name, const std::string& value
454 );
455
460 void help() const;
461
462 public:
463 // Note: set_property() variants that are not slots
464 // need to be declared *after* the set_property() slot
465 // else gomgen does not see the set_property slot.
466
474 virtual bool set_property(
475 const std::string& name, const Any& value
476 );
477
485 virtual bool get_property(
486 const std::string& prop_name, Any& prop_value
487 ) const;
488
489 protected:
490
502 const std::string& name, const Any& value, Interpreter* interpreter
503 );
504
517 virtual bool emit_signal(
518 const std::string& signal_name, const ArgList& args,
519 bool called_from_slot = false
520 );
521
522 private:
523 MetaClass* meta_class_;
524 ConnectionTable* connections_;
525 bool signals_enabled_;
526 bool slots_enabled_;
527 Numeric::uint32 id_;
528
529 // Signal method adapter needs to call
530 // emit_signal() which is protected.
531 friend class MetaMethod;
532 static std::map<Numeric::uint32, Object*>* id_to_object_;
533 };
534
535 /**************************************************************/
536
541
542 /**************************************************************/
543
544}
545
546#endif
Generic arguments and argument lists.
Base class for reference-counted objects.
Definition counted.h:71
A smart pointer with reference-counted copy semantics.
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
Abstract base class for the GOM interpreter.
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:222
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 void set_element(index_t i, const Any &value)
Sets an element by index.
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.
void set_element(index_t item, index_t component, const Any &value)
Sets an element by item and component.
Definition object.h:275
virtual bool set_property(const std::string &name, const std::string &value)
Sets an individual property.
~Object() override
Object destructor.
bool get_signals_enabled() const
Tests wheter signals are enabled.
Definition object.h:313
void help() const
Displays some help about this object.
virtual index_t get_dimension() const
Gets the number of elements per item.
void enable_slots()
Enables slots.
Definition object.h:428
virtual bool set_property_and_record_to_history(const std::string &name, const Any &value, Interpreter *interpreter)
Sets an individual property and record modification to history.
MetaClass * get_meta_class() const
Gets the meta class.
Definition object.h:348
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.
void disconnect()
Removes all connections from signals of this objects.
void set_signals_enabled(bool value)
Enables or disables signals.
Definition object.h:322
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.
static Object * id_to_object(unsigned int id)
Gets an object from a unique object id.
Definition object.h:228
void set_properties(const ArgList &args)
Sets several properties in a single call.
Numeric::uint32 id() const
Gets the identifier of this object.
Definition object.h:109
std::string get_string_id() const
Gets the unique string identifier.
Definition object.h:359
void enable_signals()
Enables signals.
Definition object.h:414
void set_slots_enabled(bool value)
Enables or disables slots.
Definition object.h:340
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.
void get_element(index_t item, index_t component, Any &value) const
Gets an element by item and component.
Definition object.h:263
virtual void get_element(index_t i, Any &value) const
Gets an element by index.
virtual MetaClass * meta_class() const
Gets the meta class.
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:435
void disable_signals()
Disables signals.
Definition object.h:421
bool get_slots_enabled() const
Tests wheter slots are enabled.
Definition object.h:331
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:170
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.
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:155
uint32_t uint32
Definition numeric.h:142
geo_index_t index_t
The type for storing and manipulating indices.
Definition numeric.h:330
Sign
Integer constants that represent the sign of a value.
Definition numeric.h:69
Global Graphite namespace.
Definition common.h:76
SmartPointer< Object > Object_var
An automatic reference-counted pointer to an Object.
Definition object.h:540
Definitions common to all include files in the gom library.