Free Electron
DispatchI.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __signal_dispatchi_h__
8 #define __signal_dispatchi_h__
9 
10 namespace fe
11 {
12 namespace ext
13 {
14 
15 /** Signature map */
16 typedef std::map<String, Signature> SignatureMap;
17 
18 /** @brief General call mechanism to enable exposure to scripting without
19  requiring any binding work
20 
21  @ingroup signal
22 
23  This is similar in purpose to ParserI but but can handle multiple types.
24 
25  This (and ParserI) should probably reside in some other module than signal
26 
27  see @ref component_binding
28  */
29 class FE_DL_EXPORT DispatchI:
30  public virtual Component,
31  public CastableAs<DispatchI>
32 {
33  public:
34  /** Execute the call. See Signature for matching support.
35  */
36 virtual bool call( const String &a_name,
37  Array<Instance>& a_argv) = 0;
38 
39 virtual bool call( const String &a_name,
40  InstanceMap& a_argv) = 0;
41 
42  /** Return a the signature supported by call() */
43 virtual SignatureMap &signatures(void) = 0;
44 
45  template<class T>
46  bool call( const String &a_name,
47  T &a_arg1);
48  template<class T>
49  bool call( const String &a_name,
50  const T &a_arg1);
51  template<class T, class U>
52  bool call( const String &a_name,
53  T &a_arg1,
54  U &a_arg2);
55  template<class T, class U>
56  bool call( const String &a_name,
57  const T &a_arg1,
58  const U &a_arg2);
59 
60 #if 0
61  template <class T>
62  void dispatch(const String &a_name);
63 #endif
64 
65 virtual bool checkedCall(const String &a_name,
66  Array<Instance> a_argv) = 0;
67 
68 };
69 
70 template<class T>
71 bool DispatchI::call(const String &a_name, T &a_arg1)
72 {
73  Array<Instance> args;
74  Instance instance;
75  instance.set<T>(registry()->master()->typeMaster(), a_arg1);
76  args.push_back(instance);
77  return call(a_name, args);
78 }
79 
80 template<class T>
81 bool DispatchI::call(const String &a_name, const T &a_arg1)
82 {
83  T arg1;
84  arg1 = a_arg1;
85  Array<Instance> args;
86  Instance instance;
87  instance.set<T>(registry()->master()->typeMaster(), arg1);
88  args.push_back(instance);
89  return call(a_name, args);
90 }
91 
92 template<class T, class U>
93 bool DispatchI::call(const String &a_name, T &a_arg1, U &a_arg2)
94 {
95  Array<Instance> args;
96  Instance instance;
97  instance.set<T>(registry()->master()->typeMaster(), a_arg1);
98  args.push_back(instance);
99  instance.set<U>(registry()->master()->typeMaster(), a_arg2);
100  args.push_back(instance);
101  return call(a_name, args);
102 }
103 
104 template<class T, class U>
105 bool DispatchI::call(const String &a_name, const T &a_arg1, const U &a_arg2)
106 {
107  T arg1;
108  U arg2;
109  arg1 = a_arg1;
110  arg2 = a_arg2;
111  Array<Instance> args;
112  Instance instance;
113  instance.set<T>(registry()->master()->typeMaster(), arg1);
114  args.push_back(instance);
115  instance.set<U>(registry()->master()->typeMaster(), arg2);
116  args.push_back(instance);
117  return call(a_name, args);
118 }
119 
120 #if 0
121 template<class T>
122 void DispatchI::dispatch(const String &a_name)
123 {
124  m_dispatchSignatures[a_name].append(
125  registry()->master()->typeMaster()->lookupType(TypeInfo(typeid(T))));
126 }
127 #endif
128 
129 } /* namespace ext */
130 } /* namespace fe */
131 
132 #endif /* __signal_dispatchi_h__ */
133 
virtual bool call(const String &a_name, Array< Instance > &a_argv)=0
Execute the call.
Smart pointer used with types represented by BaseType.
Definition: Instance.h:28
kernel
Definition: namespace.dox:3
std::map< String, Signature > SignatureMap
Signature map.
Definition: DispatchI.h:16
C++ type_info wrapper.
Definition: Type.h:20
General call mechanism to enable exposure to scripting without requiring any binding work...
Definition: DispatchI.h:29
Automatically reference-counted string container.
Definition: String.h:128
Group of named instances.
Definition: InstanceMap.h:17
Wrapper for std::vector.
Definition: Array.h:21
Base for all interfacable components.
Definition: Component.h:20
sp< Master > master(void) const
Access the Master (ptr may not be valid)
Definition: Registry.cc:98
Per-class participation non-RTTI fallback dynamic casting mechanism.
Definition: Castable.h:192