cisst-saw
Loading...
Searching...
No Matches
mtsCallableQualifiedReadMethod.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3
4/*
5
6 Author(s): Anton Deguet
7 Created on: 2010-09-16
8
9 (C) Copyright 2010-2014 Johns Hopkins University (JHU), All Rights Reserved.
10
11--- begin cisst license - do not edit ---
12
13This software is provided "as is" under an open source license, with
14no warranty. The complete license can be found in license.txt and
15http://www.cisst.org/cisst/license.txt.
16
17--- end cisst license ---
18*/
19
20
25
26#ifndef _mtsCallableQualifiedReadMethod_h
27#define _mtsCallableQualifiedReadMethod_h
28
29
32
33#include <string>
34
35
39template <class _classType, class _argumentType, class _resultType>
40class mtsCallableQualifiedReadMethod: public mtsCallableQualifiedReadBase {
41
42public:
44 typedef _argumentType ArgumentType;
45 typedef _resultType ResultType;
46
48 typedef _classType ClassType;
49
51 typedef mtsCallableQualifiedReadMethod<ClassType, ArgumentType, ResultType> ThisType;
52
55 typedef bool(_classType::*ActionType)(const ArgumentType & argument, ResultType & result) const;
56
57private:
59 inline mtsCallableQualifiedReadMethod(const ThisType & CMN_UNUSED(other)) {}
60
61protected:
65
68
69 template <bool a, bool b, typename dummy = void>
71 public:
72 static mtsExecutionResult CallMethod(ClassType * classInstantiation, ActionType action,
73 const mtsGenericObject & argument, mtsGenericObject & result)
74 {
76 if (data1 == 0) {
78 }
80 if (data2 == 0) {
82 }
83 if ( (classInstantiation->*action)(*data1, *data2) ) {
85 }
87 }
88 };
89
90 template <typename dummy>
91 class ConditionalCast<true, false, dummy> {
92 public:
93 static mtsExecutionResult CallMethod(ClassType * classInstantiation, ActionType action,
94 const mtsGenericObject & argument, mtsGenericObject & result)
95 {
96 // First, check if a Proxy object was passed.
97 ArgumentType temp1; // in case needed
98 const ArgumentType * data1 = dynamic_cast<const ArgumentType *>(&argument);
99 // If it isn't a Proxy, maybe it is a ProxyRef
100 if (!data1) {
101 typedef typename ArgumentType::RefType ArgumentRefType;
102 const ArgumentRefType * data1ref = dynamic_cast<const ArgumentRefType *>(&argument);
103 if (!data1ref) {
104 CMN_LOG_INIT_ERROR << "Class mtsCallableQualifiedReadMethod: CallMethod could not cast argument from " << typeid(argument).name()
105 << " to const " << typeid(ArgumentRefType).name() << std::endl;
107 }
108 temp1 = *data1ref;
109 data1 = &temp1;
110 }
112 if (data2 == 0) {
114 }
115 if ( (classInstantiation->*action)(*data1, *data2) ) {
117 }
119 }
120 };
121
122 template <typename dummy>
123 class ConditionalCast<false, true, dummy> {
124 public:
125 static mtsExecutionResult CallMethod(ClassType * classInstantiation, ActionType action,
126 const mtsGenericObject & argument, mtsGenericObject & result)
127 {
129 if (data1 == 0) {
131 }
132 // First, check if a Proxy object was passed.
133 ResultType temp2; // in case needed
134 ResultType * data2 = dynamic_cast<ResultType *>(&result);
135 // If it isn't a Proxy, maybe it is a ProxyRef
136 typedef typename ResultType::RefType ResultRefType;
137 ResultRefType * data2ref = 0;
138 if (!data2) {
139 data2ref = dynamic_cast<ResultRefType *>(&result);
140 if (!data2ref) {
141 CMN_LOG_INIT_ERROR << "Class mtsCallableQualifiedReadMethod: CallMethod could not cast result from " << typeid(result).name()
142 << " to const " << typeid(ResultRefType).name() << std::endl;
144 }
145 data2 = &temp2;
146 }
147 if ( (classInstantiation->*action)(*data1, *data2) ) {
148 if (data2ref) {
149 *data2ref = *data2;
150 }
152 }
154 }
155 };
156
157 template <typename dummy>
158 class ConditionalCast<true, true, dummy> {
159 public:
160 static mtsExecutionResult CallMethod(ClassType * classInstantiation, ActionType action,
161 const mtsGenericObject & argument, mtsGenericObject & result)
162 {
163 // First, check if a Proxy object was passed.
164 ArgumentType temp1; // in case needed
165 const ArgumentType * data1 = dynamic_cast<const ArgumentType *>(&argument);
166 // If it isn't a Proxy, maybe it is a ProxyRef
167 if (!data1) {
168 typedef typename ArgumentType::RefType ArgumentRefType;
169 const ArgumentRefType * data1ref = dynamic_cast<const ArgumentRefType *>(&argument);
170 if (!data1ref) {
171 CMN_LOG_INIT_ERROR << "Class mtsCallableQualifiedReadMethod: CallMethod could not cast argument from " << typeid(argument).name()
172 << " to const " << typeid(ArgumentRefType).name() << std::endl;
174 }
175 temp1 = *data1ref;
176 data1 = &temp1;
177 }
178 // First, check if a Proxy object was passed.
179 ResultType temp2; // in case needed
180 ResultType * data2 = dynamic_cast<ResultType *>(&result);
181 // If it isn't a Proxy, maybe it is a ProxyRef
182 typedef typename ResultType::RefType ResultRefType;
183 ResultRefType * data2ref = 0;
184 if (!data2) {
185 data2ref = dynamic_cast<ResultRefType *>(&result);
186 if (!data2ref) {
187 CMN_LOG_INIT_ERROR << "Class mtsCallableQualifiedReadMethod: CallMethod could not cast result from " << typeid(result).name()
188 << " to const " << typeid(ResultRefType).name() << std::endl;
190 }
191 data2 = &temp2;
192 }
193 if ( (classInstantiation->*action)(*data1, *data2) ) {
194 // Finally, copy the data to the argument
195 if (data2ref) {
196 *data2ref = temp2;
197 }
199 }
201 }
202 };
203
204public:
207
214 BaseType(),
215 Action(action),
216 ClassInstantiation(classInstantiation)
217 {}
218
221
222 /* documented in base class */
224 return ConditionalCast<cmnIsDerivedFromTemplated<ArgumentType, mtsGenericObjectProxy>::IS_DERIVED,
226 ::CallMethod(ClassInstantiation, Action, argument, result);
227 }
228
229 /* documented in base class */
230 void ToStream(std::ostream & outputStream) const {
231 if (this->ClassInstantiation) {
232 outputStream << "method based callable qualified read object using class/object \""
233 << mtsObjectName(this->ClassInstantiation) << "\"";
234 } else {
235 outputStream << "invalid method based callable object";
236 }
237 }
238};
239
240
241
242
243template <class _classType>
244class mtsCallableQualifiedReadMethodGeneric: public mtsCallableQualifiedReadBase {
245
246public:
248
250 typedef _classType ClassType;
251
253 typedef mtsCallableQualifiedReadMethodGeneric<ClassType> ThisType;
254
257 typedef bool(_classType::*ActionType)(const mtsGenericObject & argument, mtsGenericObject & result) const;
258
259private:
262
263protected:
267
270
271public:
274
281 BaseType(),
282 Action(action),
283 ClassInstantiation(classInstantiation)
284 {}
285
288
289 /* documented in base class */
296
297 /* documented in base class */
298 void ToStream(std::ostream & outputStream) const {
299 if (this->ClassInstantiation) {
300 outputStream << "generic method based callable qualified read object using class/object \""
301 << mtsObjectName(this->ClassInstantiation) << "\"";
302 } else {
303 outputStream << "invalid generic method based callable object";
304 }
305 }
306};
307
308#endif // _mtsCallableQualifiedReadMethod_h
@ IS_DERIVED
Definition cmnTypeTraits.h:648
mtsCallableQualifiedReadBase(void)
Definition mtsCallableQualifiedReadBase.h:45
static mtsExecutionResult CallMethod(ClassType *classInstantiation, ActionType action, const mtsGenericObject &argument, mtsGenericObject &result)
Definition mtsCallableQualifiedReadMethod.h:125
static mtsExecutionResult CallMethod(ClassType *classInstantiation, ActionType action, const mtsGenericObject &argument, mtsGenericObject &result)
Definition mtsCallableQualifiedReadMethod.h:93
static mtsExecutionResult CallMethod(ClassType *classInstantiation, ActionType action, const mtsGenericObject &argument, mtsGenericObject &result)
Definition mtsCallableQualifiedReadMethod.h:160
Definition mtsCallableQualifiedReadMethod.h:70
static mtsExecutionResult CallMethod(ClassType *classInstantiation, ActionType action, const mtsGenericObject &argument, mtsGenericObject &result)
Definition mtsCallableQualifiedReadMethod.h:72
mtsCallableQualifiedReadMethodGeneric(void)
Definition mtsCallableQualifiedReadMethod.h:273
ActionType Action
Definition mtsCallableQualifiedReadMethod.h:266
mtsExecutionResult Execute(const mtsGenericObject &argument, mtsGenericObject &result)
Definition mtsCallableQualifiedReadMethod.h:290
mtsCallableQualifiedReadBase BaseType
Definition mtsCallableQualifiedReadMethod.h:247
mtsCallableQualifiedReadMethodGeneric(ActionType action, ClassType *classInstantiation)
Definition mtsCallableQualifiedReadMethod.h:280
virtual ~mtsCallableQualifiedReadMethodGeneric()
Definition mtsCallableQualifiedReadMethod.h:287
ClassType * ClassInstantiation
Definition mtsCallableQualifiedReadMethod.h:269
void ToStream(std::ostream &outputStream) const
Definition mtsCallableQualifiedReadMethod.h:298
_classType ClassType
Definition mtsCallableQualifiedReadMethod.h:250
bool(ClassType::*) ActionType(const mtsGenericObject &argument, mtsGenericObject &result) const
Definition mtsCallableQualifiedReadMethod.h:257
mtsCallableQualifiedReadMethodGeneric< ClassType > ThisType
Definition mtsCallableQualifiedReadMethod.h:253
mtsCallableQualifiedReadMethod(void)
Definition mtsCallableQualifiedReadMethod.h:206
mtsCallableQualifiedReadMethod< ClassType, ArgumentType, ResultType > ThisType
Definition mtsCallableQualifiedReadMethod.h:51
ActionType Action
Definition mtsCallableQualifiedReadMethod.h:64
mtsCallableQualifiedReadMethod(ActionType action, ClassType *classInstantiation)
Definition mtsCallableQualifiedReadMethod.h:213
mtsCallableQualifiedReadBase BaseType
Definition mtsCallableQualifiedReadMethod.h:43
_classType ClassType
Definition mtsCallableQualifiedReadMethod.h:48
virtual ~mtsCallableQualifiedReadMethod()
Definition mtsCallableQualifiedReadMethod.h:220
_resultType ResultType
Definition mtsCallableQualifiedReadMethod.h:45
mtsExecutionResult Execute(const mtsGenericObject &argument, mtsGenericObject &result)
Definition mtsCallableQualifiedReadMethod.h:223
bool(ClassType::*) ActionType(const ArgumentType &argument, ResultType &result) const
Definition mtsCallableQualifiedReadMethod.h:55
void ToStream(std::ostream &outputStream) const
Definition mtsCallableQualifiedReadMethod.h:230
ClassType * ClassInstantiation
Definition mtsCallableQualifiedReadMethod.h:67
_argumentType ArgumentType
Definition mtsCallableQualifiedReadMethod.h:44
Definition mtsExecutionResult.h:34
@ METHOD_OR_FUNCTION_FAILED
Definition mtsExecutionResult.h:44
@ INVALID_INPUT_TYPE
Definition mtsExecutionResult.h:44
@ COMMAND_SUCCEEDED
Definition mtsExecutionResult.h:44
Base class for data object in cisstMultiTask.
Definition mtsGenericObject.h:52
static T * CastArg(mtsGenericObject &arg)
Definition mtsGenericObjectProxy.h:700
#define CMN_LOG_INIT_ERROR
Definition cmnLogger.h:162
#define CMN_UNUSED(argument)
Definition cmnPortability.h:497
Defines a base class for a callable object with a qualifer and a placeholder to retrieve data.
std::string mtsObjectName(const mtsComponent *object)
Definition mtsComponent.h:588