- Aldebaran documentation |
- C++ Libraries |
- index

libqi-api 2.8.7.4

- Main Page
- Related Pages
- Namespaces
- Classes
- Files
- Examples

- File List
- File Members

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_DETAIL_GENERICOBJECTBUILDER_HXX_
8 #define _QITYPE_DETAIL_GENERICOBJECTBUILDER_HXX_
9
10 #include <qi/type/dynamicobject.hpp>
11 #include <qi/type/dynamicobjectbuilder.hpp>
12 #include <qi/type/metamethod.hpp>
13
14 namespace qi {
15
16 template <typename FUNCTION_TYPE>
17 unsigned int DynamicObjectBuilder::advertiseMethod(const std::string& name,
18 FUNCTION_TYPE function,
19 const std::string& desc,
20 MetaCallType threadingModel)
21 {
22 MetaMethodBuilder builder;
23 AnyFunction f = AnyFunction::from(function).dropFirstArgument();
24 builder.setName(name);
25 builder.setSignature(f);
26 builder.setDescription(desc);
27 // throw on error
28 return xAdvertiseMethod(builder, f, threadingModel);
29 }
30
31 template <typename OBJECT_TYPE, typename METHOD_TYPE>
32 inline unsigned int DynamicObjectBuilder::advertiseMethod(const std::string& name,
33 OBJECT_TYPE object,
34 METHOD_TYPE method,
35 const std::string& desc,
36 MetaCallType threadingModel)
37 {
38 MetaMethodBuilder builder;
39 AnyFunction f = AnyFunction::from(method, object).dropFirstArgument();
40 builder.setName(name);
41 builder.setSignature(f);
42 builder.setDescription(desc);
43 // throw on error
44 return xAdvertiseMethod(builder, f, threadingModel);
45 }
46
47 template <typename FUNCTION_TYPE>
48 inline unsigned int DynamicObjectBuilder::advertiseMethod(MetaMethodBuilder& builder,
49 FUNCTION_TYPE function,
50 MetaCallType threadingModel)
51 {
52 AnyFunction f = AnyFunction::from(function).dropFirstArgument();
53 builder.setSignature(f);
54 // throw on error
55 return xAdvertiseMethod(builder, f, threadingModel);
56 }
57
58 template <typename OBJECT_TYPE, typename METHOD_TYPE>
59 inline unsigned int DynamicObjectBuilder::advertiseMethod(MetaMethodBuilder& builder,
60 OBJECT_TYPE object,
61 METHOD_TYPE method,
62 MetaCallType threadingModel)
63 {
64 AnyFunction f = AnyFunction::from(method, object).dropFirstArgument();
65 builder.setSignature(f);
66 // throw on error
67 return xAdvertiseMethod(builder, f, threadingModel);
68 }
69
70 template <typename... Args>
71 unsigned int DynamicObjectBuilder::advertiseSignal(const std::string& s)
72 {
73 return advertiseSignalF<void(Args...)>(s);
74 }
75
76 template <typename T> unsigned int DynamicObjectBuilder::advertiseSignalF(const std::string& name)
77 {
78 return xAdvertiseSignal(name, detail::FunctionSignature<T>::signature());
79 }
80
81 template <typename T> unsigned int DynamicObjectBuilder::advertiseProperty(const std::string& name)
82 {
83 // we must end up with name event, get_name and set_name methods
84 unsigned int isig = advertiseSignal<const T&>(name);
85 isig = xAdvertiseProperty(name, typeOf<T>()->signature(), isig);
86 return isig;
87 }
88
89 template<typename T> qi::AnyObject DynamicObjectBuilder::object(boost::shared_ptr<T> other)
90 {
91 DynamicObject* dobj = bareObject();
92 qi::AnyObject ao = makeDynamicSharedAnyObject(dobj, other);
93 setManageable(dobj, ao.asGenericObject());
94 return ao;
95 }
96
97 }
98 #endif // _QITYPE_DETAIL_GENERICOBJECTBUILDER_HXX_
qi::Object::asGenericObject
GenericObject * asGenericObject() const
Definition: object.hxx:652
dynamicobject.hpp
qi::DynamicObjectBuilder::advertiseProperty
unsigned int advertiseProperty(const std::string &name)
Definition: dynamicobjectbuilder.hxx:81
qi::DynamicObjectBuilder::xAdvertiseProperty
unsigned int xAdvertiseProperty(const std::string &name, const Signature &sig, int id=-1)
qi::MetaMethodBuilder
Definition: metamethod.hpp:69
dynamicobjectbuilder.hpp
qi::AnyFunction
Definition: anyfunction.hpp:149
qi::DynamicObjectBuilder::xAdvertiseSignal
unsigned int xAdvertiseSignal(const std::string &name, const Signature &signature, bool isSignalProperty=false)
qi::MetaMethodBuilder::setName
void setName(const std::string &name)
qi::DynamicObjectBuilder::xAdvertiseMethod
unsigned int xAdvertiseMethod(const Signature &sigret, const std::string &name, const Signature &signature, AnyFunction func, const std::string &desc="", MetaCallType threadingModel=MetaCallType_Auto)
qi::MetaMethodBuilder::setDescription
void setDescription(const std::string &documentation)
qi::DynamicObjectBuilder::advertiseMethod
unsigned int advertiseMethod(const std::string &name, OBJECT_TYPE object, METHOD_TYPE method, const std::string &desc="", MetaCallType threadingModel=MetaCallType_Auto)
Definition: dynamicobjectbuilder.hxx:32
qi::DynamicObjectBuilder::advertiseSignalF
unsigned int advertiseSignalF(const std::string &name)
Advertise a signal using a function signature.
Definition: dynamicobjectbuilder.hxx:76
qi::DynamicObjectBuilder::advertiseSignal
unsigned int advertiseSignal(const std::string &name)
Definition: dynamicobjectbuilder.hxx:71
qi::makeDynamicSharedAnyObject
AnyObject makeDynamicSharedAnyObject(DynamicObject *obj, boost::shared_ptr< T > other)
Definition: dynamicobject.hpp:88
qi::MetaCallType
MetaCallType
Definition: typeobject.hpp:24
qi::DynamicObject
Definition: dynamicobject.hpp:36
qi::Object< Empty >
qi::DynamicObjectBuilder::object
qi::AnyObject object(boost::function< void(GenericObject *)> onDelete=boost::function< void(GenericObject *)>())
qi::log::env::QI_DEFAULT_LOGHANDLER::name
char const *const name
metamethod.hpp
qi::AnyFunction::from
static AnyFunction from(F &&func)
qi::detail::FunctionSignature
Definition: functionsignature.hxx:103
qi::AnyFunction::dropFirstArgument
const AnyFunction & dropFirstArgument() const
Change signature, drop the first argument passed to call.
qi::MetaMethodBuilder::setSignature
void setSignature(const AnyFunction &f)