Graphite  Version 3
An experimental 3D geometry processing program
meta_method.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_MEMBERS_META_METHOD_H
38 #define H_OGF_META_MEMBERS_META_METHOD_H
39 
40 #include <OGF/gom/common/common.h>
43 
49 namespace OGF {
50 
51  class Object ;
52  class ArgList ;
53 
63  typedef bool (*gom_method_adapter)(
64  Object* target,
65  const std::string& method_name, const ArgList& args,
66  Any& ret_val
67  ) ;
68 
72  gom_class GOM_API MetaMethod : public MetaMember {
73  public:
74 
82  const std::string& name,
83  MetaClass* container,
84  const std::string& return_type
85  ) ;
86 
95  const std::string& name,
96  MetaClass* container,
97  MetaType* return_type
98  ) ;
99 
103  ~MetaMethod() override;
104 
108  void pre_delete() override;
109 
110 
114  std::string get_doc() const override;
115 
116  gom_slots:
117 
122  size_t nb_args() const {
123  return meta_args_.size();
124  }
125 
131  const std::string& ith_arg_name(index_t i) const {
132  ogf_assert(i < meta_args_.size());
133  return meta_args_[i].name();
134  }
135 
141  const std::string& ith_arg_type_name(index_t i) const {
142  ogf_assert(i < meta_args_.size());
143  return meta_args_[i].type_name();
144  }
145 
152  ogf_assert(i < meta_args_.size());
153  return meta_args_[i].type();
154  }
155 
163  ogf_assert(i < meta_args_.size());
164  return meta_args_[i].has_default_value();
165  }
166 
173  return ith_arg_default_value(i).as_string();
174  }
175 
180  const std::string& return_type_name() const {
181  return return_type_name_ ;
182  }
183 
189  MetaType* return_type() const ;
190 
200  index_t i, const std::string& name
201  ) const;
202 
212  index_t i, const std::string& name
213  ) const;
214 
221 
231 
241 
242  public:
243 
250  ogf_assert(i < meta_args_.size());
251  return meta_args_[i].default_value();
252  }
253 
254 
261  const MetaArg* ith_arg(index_t i) const {
262  ogf_assert(i < meta_args_.size()) ;
263  return &(meta_args_[i]) ;
264  }
265 
273  ogf_assert(i < meta_args_.size()) ;
274  return &(meta_args_[i]) ;
275  }
276 
282  void add_arg(const MetaArg& arg) {
283  meta_args_.push_back(arg) ;
284  }
285 
293  bool has_arg(const std::string& meta_arg_name) ;
294 
301  const MetaArg* find_arg(const std::string& meta_arg_name) const ;
302 
308  MetaArg* find_arg(const std::string& meta_arg_name) ;
309 
310 
317  return adapter_ ;
318  }
319 
326  adapter_ = adapter ;
327  }
328 
339  virtual bool invoke(
340  Object* target, const ArgList& args, Any& return_value
341  ) ;
342 
352  virtual bool invoke(
353  const std::string& method_name,
354  const ArgList& args, Any& ret_val
355  ) {
356  return Object::invoke_method(method_name, args, ret_val) ;
357  }
358 
370  virtual bool check_args(const ArgList& args) ;
371 
381  virtual index_t nb_used_args(const ArgList& args) ;
382 
391  virtual index_t nb_default_args(const ArgList& args) ;
392 
400  virtual void add_default_args(ArgList& args) ;
401 
402  protected:
411  static bool emit_signal(
412  Object* target, const std::string& sig_name,
413  const ArgList& args, bool called_from_slot = true
414  ) ;
415 
424  const std::string& signal_name,
425  const ArgList& args, bool called_from_slot = true
426  ) override {
427  return emit_signal(this, signal_name, args, called_from_slot);
428  }
429 
430  private:
431  std::string return_type_name_ ;
432  MetaArgList meta_args_ ;
433  gom_method_adapter adapter_ ;
434  } ;
435 
440 
441 }
442 #endif
443 
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 the arguments in the Meta repository.
Definition: meta_arg.h:60
The representation of a class in the Meta repository.
Definition: meta_class.h:64
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
std::string ith_arg_jth_custom_attribute_value(index_t i, index_t j)
Gets a custom attribute value of an argument by index.
size_t ith_arg_nb_custom_attributes(index_t i)
Gets the number of custom attribute of an argument.
void set_method_adapter(gom_method_adapter adapter)
Sets the method adapter.
Definition: meta_method.h:325
bool has_arg(const std::string &meta_arg_name)
Tests whether the method has an argument of a given name.
virtual bool check_args(const ArgList &args)
Checks whether the specified ArgList contains all the required args.
static bool emit_signal(Object *target, const std::string &sig_name, const ArgList &args, bool called_from_slot=true)
Emits a signal in a target object.
const Any & ith_arg_default_value(index_t i) const
Gets the default value of an argument.
Definition: meta_method.h:249
MetaType * return_type() const
Gets the return type.
gom_method_adapter method_adapter() const
Gets the method adapter.
Definition: meta_method.h:316
bool ith_arg_has_custom_attribute(index_t i, const std::string &name) const
Tests whether an argument has a custom attribute.
void pre_delete() override
Removes all variables that use the meta type system before deleting.
std::string ith_arg_default_value_as_string(index_t i) const
Gets the default value of an argument.
Definition: meta_method.h:172
const std::string & return_type_name() const
Gets the return type name.
Definition: meta_method.h:180
virtual index_t nb_default_args(const ArgList &args)
Counts the number of arguments assigned with their default value when this method is invoked on the s...
~MetaMethod() override
MetaMethod destructor.
MetaMethod(const std::string &name, MetaClass *container, const std::string &return_type)
MetaMethod constructor.
const std::string & ith_arg_type_name(index_t i) const
Gets the type name of an argument by index.
Definition: meta_method.h:141
virtual bool invoke(Object *target, const ArgList &args, Any &return_value)
Invokes this method on a target object.
bool ith_arg_has_default_value(index_t i) const
Tests whether an argument has a default value.
Definition: meta_method.h:162
MetaType * ith_arg_type(index_t i) const
Gets the type of an argument by index.
Definition: meta_method.h:151
virtual bool invoke(const std::string &method_name, const ArgList &args, Any &ret_val)
Implements the dynamic invocation API for the MetaMethod object.
Definition: meta_method.h:352
virtual index_t nb_used_args(const ArgList &args)
Counts the number of arguments this method would use when invoked on the specified args.
std::string ith_arg_custom_attribute_value(index_t i, const std::string &name) const
Gets the value of a custom attribute of an argument.
std::string get_doc() const override
Gets the documentation.
const MetaArg * ith_arg(index_t i) const
Gets a const MetaArg by index.
Definition: meta_method.h:261
const MetaArg * find_arg(const std::string &meta_arg_name) const
Finds an argument by name.
MetaArg * find_arg(const std::string &meta_arg_name)
Finds an argument by name.
MetaArg * ith_arg(index_t i)
Gets a MetaArg by index.
Definition: meta_method.h:272
const std::string & ith_arg_name(index_t i) const
Gets the name of an argument by index.
Definition: meta_method.h:131
void add_arg(const MetaArg &arg)
Adds a new argument to the method.
Definition: meta_method.h:282
virtual void add_default_args(ArgList &args)
Adds the arguments with default values to an ArgList.
MetaMethod(const std::string &name, MetaClass *container, MetaType *return_type)
MetaMethod constructor.
bool emit_signal(const std::string &signal_name, const ArgList &args, bool called_from_slot=true) override
Emits a signal from this MetaMethod.
Definition: meta_method.h:423
std::string ith_arg_jth_custom_attribute_name(index_t i, index_t j)
Gets a custom attribute name of an argument by index.
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
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.
Meta-information attached to arguments.
Meta-information attached to class members.
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Global Graphite namespace.
Definition: common.h:76
bool(* gom_method_adapter)(Object *target, const std::string &method_name, const ArgList &args, Any &ret_val)
Function pointer types for method adapters.
Definition: meta_method.h:63
std::vector< MetaArg > MetaArgList
Meta representation of a list of arguments.
Definition: meta_arg.h:135
SmartPointer< MetaMethod > MetaMethod_var
Automatic reference-counted pointer to a MetaMethod.
Definition: meta_method.h:439
Definitions common to all include files in the gom library.