libqi-api  2.4.3.28
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dynamicobjectbuilder.hxx
Go to the documentation of this file.
1 #pragma once
2 /*
3 ** Copyright (C) 2013 Aldebaran Robotics
4 ** See COPYING for the license
5 */
6 
7 #ifndef _QITYPE_DETAILS_GENERICOBJECTBUILDER_HXX_
8 #define _QITYPE_DETAILS_GENERICOBJECTBUILDER_HXX_
9 
11 #include <qi/type/metamethod.hpp>
12 
13 namespace qi {
14 
15  template <typename FUNCTION_TYPE>
16  unsigned int DynamicObjectBuilder::advertiseMethod(const std::string& name,
17  FUNCTION_TYPE function,
18  const std::string& desc,
19  MetaCallType threadingModel)
20  {
21  MetaMethodBuilder builder;
23  builder.setName(name);
24  builder.setSignature(f);
25  builder.setDescription(desc);
26  // throw on error
27  return xAdvertiseMethod(builder, f, threadingModel);
28  }
29 
30  template <typename OBJECT_TYPE, typename METHOD_TYPE>
31  inline unsigned int DynamicObjectBuilder::advertiseMethod(const std::string& name,
32  OBJECT_TYPE object,
33  METHOD_TYPE method,
34  const std::string& desc,
35  MetaCallType threadingModel)
36  {
37  MetaMethodBuilder builder;
38  AnyFunction f = AnyFunction::from(method, object).dropFirstArgument();
39  builder.setName(name);
40  builder.setSignature(f);
41  builder.setDescription(desc);
42  // throw on error
43  return xAdvertiseMethod(builder, f, threadingModel);
44  }
45 
46  template <typename FUNCTION_TYPE>
48  FUNCTION_TYPE function,
49  MetaCallType threadingModel)
50  {
52  builder.setSignature(f);
53  // throw on error
54  return xAdvertiseMethod(builder, f, threadingModel);
55  }
56 
57  template <typename OBJECT_TYPE, typename METHOD_TYPE>
59  OBJECT_TYPE object,
60  METHOD_TYPE method,
61  MetaCallType threadingModel)
62  {
63  AnyFunction f = AnyFunction::from(method, object).dropFirstArgument();
64  builder.setSignature(f);
65  // throw on error
66  return xAdvertiseMethod(builder, f, threadingModel);
67  }
68 
69  #define gen(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma) \
70  QI_GEN_MAYBE_TEMPLATE_OPEN(comma) ATYPEDECL QI_GEN_MAYBE_TEMPLATE_CLOSE(comma) \
71  inline unsigned int DynamicObjectBuilder::advertiseSignal(const std::string& s) \
72  { \
73  return advertiseSignalF<void(ATYPES)>(s); \
74  }
75 
76  QI_GEN_RANGE(gen, 8)
77  #undef gen
78 
79  template <typename T> unsigned int DynamicObjectBuilder::advertiseSignalF(const std::string& name)
80  {
82  }
83 
84  template <typename T> unsigned int DynamicObjectBuilder::advertiseProperty(const std::string& name)
85  {
86  // we must end up with name event, get_name and set_name methods
87  unsigned int isig = advertiseSignal<const T&>(name);
88  isig = xAdvertiseProperty(name, typeOf<T>()->signature(), isig);
89  return isig;
90  }
91 
92  template<typename T> qi::AnyObject DynamicObjectBuilder::object(boost::shared_ptr<T> other)
93  {
94  DynamicObject* dobj = bareObject();
95  qi::AnyObject ao = makeDynamicAnyObject(dobj, other);
96  setManageable(dobj, ao.asGenericObject());
97  return ao;
98  }
99 
100 }
101 #endif // _QITYPE_DETAILS_GENERICOBJECTBUILDER_HXX_
GenericObject * asGenericObject() const
Definition: object.hxx:523
#define QI_GEN_RANGE(f, max)
Definition: preproc.hpp:477
unsigned int advertiseProperty(const std::string &name)
unsigned int xAdvertiseProperty(const std::string &name, const Signature &sig, int id=-1)
static AnyFunction from(F func)
AnyObject makeDynamicAnyObject(DynamicObject *obj, bool destroyObject=true, boost::function< void(GenericObject *)> onDelete=boost::function< void(GenericObject *)>())
void setName(const std::string &name)
unsigned int xAdvertiseMethod(const Signature &sigret, const std::string &name, const Signature &signature, AnyFunction func, const std::string &desc="", MetaCallType threadingModel=MetaCallType_Auto)
void setDescription(const std::string &documentation)
unsigned int advertiseMethod(const std::string &name, OBJECT_TYPE object, METHOD_TYPE method, const std::string &desc="", MetaCallType threadingModel=MetaCallType_Auto)
unsigned int advertiseSignalF(const std::string &name)
Advertise a signal using a function signature.
#define gen(n, ATYPEDECL, ATYPES, ADECL, AUSE, comma)
unsigned int xAdvertiseSignal(const std::string &name, const Signature &signature)
MetaCallType
Definition: typeobject.hpp:19
qi::AnyObject object(boost::function< void(GenericObject *)> onDelete=boost::function< void(GenericObject *)>())
const AnyFunction & dropFirstArgument() const
Change signature, drop the first argument passed to call.
void setSignature(const AnyFunction &f)