21 #ifndef AGXCONTROL_ACTION_IMPLEMENTATION_H 22 #define AGXCONTROL_ACTION_IMPLEMENTATION_H 24 #include <agx/config.h> 38 class CallbackActionImplementation;
39 template<
typename T>
class Callback1ActionImplementation;
40 template<
typename R,
typename T>
class CallbackR1ActionImplementation;
41 template<
typename T1,
typename T2>
class Callback2ActionImplementation;
74 virtual void visit(agxControl::ActionImplementationVisitor* operation,
agx::Real time);
80 virtual void visit(agxControl::ActionImplementationVisitor* operation, ActionImplementation*
end,
agx::Real time);
85 virtual ~ActionImplementation() {};
88 ActionImplementation() {}
104 virtual void dispatchVisit(agxControl::ActionImplementationVisitor* operation, agxControl::CallbackActionImplementation*
begin,
agx::Real time);
105 virtual void dispatchVisit(agxControl::ActionImplementationVisitor* operation, agxControl::Callback1ActionImplementation<agx::Real>*
begin,
agx::Real time);
106 virtual void dispatchVisit(agxControl::ActionImplementationVisitor* operation, agxControl::CallbackR1ActionImplementation<void, agx::Real>*
begin,
agx::Real time);
107 virtual void dispatchVisit(agxControl::ActionImplementationVisitor* operation, agxControl::Callback2ActionImplementation<agx::Real, agx::Int>*
begin,
agx::Real time);
110 static std::string m_className;
121 VoidActionImplementation(
agx::Real time);
123 virtual ~VoidActionImplementation() {}
130 class AGXPHYSICS_EXPORT CallbackActionImplementation :
public ActionImplementation
133 typedef std::function<void (agx::Real)> Callback;
135 template<
typename ClassT>
136 CallbackActionImplementation(
agx::Real time,
void (ClassT::*
function)(
agx::Real), ClassT*
object);
139 using ActionImplementation::trigger;
141 virtual void visit(agxControl::ActionImplementationVisitor* operation,
agx::Real time);
142 using ActionImplementation::visit;
145 virtual ~CallbackActionImplementation() {}
160 class Callback1ActionImplementation :
public ActionImplementation
163 typedef std::function<void (T)> Callback;
171 template<
typename ClassT>
172 Callback1ActionImplementation(
agx::Real time,
void(ClassT::*
function)(T), ClassT*
object,
const T& value );
174 template<
typename ClassT>
175 Callback1ActionImplementation(
agx::Real time,
void(ClassT::*
function)(
const T&), ClassT*
object,
const T& value );
178 void setValue(
const T& newValue);
181 const T& getValue()
const;
185 using ActionImplementation::trigger;
187 virtual void visit(agxControl::ActionImplementationVisitor* operation,
agx::Real time);
188 virtual void visit(agxControl::ActionImplementationVisitor* operation, ActionImplementation*
end,
agx::Real time);
189 virtual void dispatchVisit(agxControl::ActionImplementationVisitor* operation, agxControl::Callback1ActionImplementation<agx::Real>*
begin,
agx::Real time);
191 using ActionImplementation::visit;
192 using ActionImplementation::dispatchVisit;
198 agxStream::StorageAgent* getStorageAgent()
const {
return agxStream::StorageManager::instance()->find( getConstructClassId() ); }
199 static const char* getConstructClassId();
200 friend class agxStream::DefStorageAgent<Callback1ActionImplementation>;
201 const char* getClassName()
const;
208 Callback1ActionImplementation();
211 virtual ~Callback1ActionImplementation() {}
222 template<
typename R,
typename T>
223 class CallbackR1ActionImplementation :
public ActionImplementation
226 typedef std::function<R (T)> Callback;
229 template<
typename ClassT>
230 CallbackR1ActionImplementation(
agx::Real time, R (ClassT::*
function)(T), ClassT*
object,
const T& value );
232 void setValue(
const T& newValue);
233 const T& getValue()
const;
236 using ActionImplementation::trigger;
238 virtual void visit(agxControl::ActionImplementationVisitor* operation,
agx::Real time);
239 virtual void visit(agxControl::ActionImplementationVisitor *operation, ActionImplementation*
end,
agx::Real time);
240 virtual void dispatchVisit(agxControl::ActionImplementationVisitor* operation, agxControl::CallbackR1ActionImplementation<void, agx::Real>*
begin,
agx::Real time);
242 using ActionImplementation::visit;
243 using ActionImplementation::dispatchVisit;
249 agxStream::StorageAgent* getStorageAgent()
const {
return agxStream::StorageManager::instance()->find( getConstructClassId() ); }
250 static const char* getConstructClassId();
251 friend class agxStream::DefStorageAgent<CallbackR1ActionImplementation>;
252 const char* getClassName()
const;
259 CallbackR1ActionImplementation();
262 virtual ~CallbackR1ActionImplementation() {}
273 template<
typename T1,
typename T2>
274 class Callback2ActionImplementation :
public ActionImplementation
277 typedef std::function<void (T1, T2)> Callback;
279 template<
typename ClassT>
280 Callback2ActionImplementation(
agx::Real,
void (ClassT::*
function)(T1, T2), ClassT*
object,
const T1& value1,
const T2& value2);
282 void setValue1(
const T1& newValue);
283 void setValue2(
const T2& newValue);
285 const T1& getValue1()
const;
286 const T2& getValue2()
const;
289 using ActionImplementation::trigger;
291 virtual void visit(agxControl::ActionImplementationVisitor* operation,
agx::Real time);
292 virtual void visit(agxControl::ActionImplementationVisitor *operation, ActionImplementation*
end,
agx::Real time);
293 virtual void dispatchVisit(agxControl::ActionImplementationVisitor* operation, agxControl::Callback2ActionImplementation<agx::Real, agx::Int>*
begin,
agx::Real time);
295 using ActionImplementation::visit;
296 using ActionImplementation::dispatchVisit;
299 agxStream::StorageAgent* getStorageAgent()
const {
return agxStream::StorageManager::instance()->find( getConstructClassId() ); }
300 static const char* getConstructClassId();
301 friend class agxStream::DefStorageAgent<Callback2ActionImplementation>;
302 const char* getClassName()
const;
309 Callback2ActionImplementation();
312 virtual ~Callback2ActionImplementation() {}
325 template<
typename ClassT>
326 CallbackActionImplementation::CallbackActionImplementation(
329 ActionImplementation(time), m_callback(
std::bind(function, object,
std::placeholders:: _1))
337 Callback1ActionImplementation<T>::Callback1ActionImplementation():
338 ActionImplementation(
agx::
Real(-1.0)), m_value(T())
343 template<
typename T>
template<
typename ClassT>
344 Callback1ActionImplementation<T>::Callback1ActionImplementation(
345 agx::Real time,
void (ClassT::*
function)(T), ClassT*
object,
const T& value
347 ActionImplementation(time), m_callback(
std::bind(function, object,
std::placeholders:: _1)), m_value(value)
351 template<
typename T>
template<
typename ClassT>
352 Callback1ActionImplementation<T>::Callback1ActionImplementation(
353 agx::Real time,
void (ClassT::*
function)(
const T&), ClassT*
object,
const T& value
355 ActionImplementation(time), m_callback(
std::bind(function, object,
std::placeholders:: _1)), m_value(value)
360 inline void Callback1ActionImplementation<T>::setValue(
const T& newValue)
367 inline const T& Callback1ActionImplementation<T>::getValue()
const 374 inline void Callback1ActionImplementation<T>::trigger(
agx::Real )
381 inline void Callback1ActionImplementation<T>::visit(agxControl::ActionImplementationVisitor* operation,
agx::Real time)
383 operation->update(
this, time);
387 inline void Callback1ActionImplementation<T>::visit(
388 agxControl::ActionImplementationVisitor* , ActionImplementation* ,
agx::Real )
390 agxAbort1(
"Action: Asked to visit Callback1Actions with unsupported template parameters.");
394 inline void Callback1ActionImplementation<agx::Real>::visit(
395 agxControl::ActionImplementationVisitor* operation, ActionImplementation*
end,
agx::Real time)
397 end->dispatchVisit(operation,
this, time);
401 inline void Callback1ActionImplementation<T>::dispatchVisit(agxControl::ActionImplementationVisitor* ,
402 agxControl::Callback1ActionImplementation<agx::Real>* ,
agx::Real )
404 agxAbort1(
"Action: Asked to dispatch visit Callback1Actions with unsupported template parameters.");
409 inline void Callback1ActionImplementation<agx::Real>::dispatchVisit(agxControl::ActionImplementationVisitor* operation,
410 agxControl::Callback1ActionImplementation<agx::Real> *
begin,
agx::Real time)
412 operation->update(begin,
this, time);
418 this->ActionImplementation::store(out);
426 this->ActionImplementation::restore(in);
436 template<
typename R,
typename T>
437 CallbackR1ActionImplementation<R,T>::CallbackR1ActionImplementation():
438 ActionImplementation(
agx::
Real(-1.0)), m_value(T(0))
443 template<
typename R,
typename T>
template<
typename ClassT>
444 CallbackR1ActionImplementation<R,T>::CallbackR1ActionImplementation(
445 agx::Real time, R (ClassT::*
function)(T), ClassT*
object,
const T &value
447 ActionImplementation(time), m_callback(
std::bind(function, object,
std::placeholders:: _1)), m_value(value)
452 template<
typename R,
typename T>
453 inline void CallbackR1ActionImplementation<R, T>::setValue(
const T& newValue)
459 template<
typename R,
typename T>
460 inline const T& CallbackR1ActionImplementation<R, T>::getValue()
const 466 template<
typename R,
typename T>
467 inline void CallbackR1ActionImplementation<R, T>::trigger(
agx::Real )
473 template<
typename R,
typename T>
474 inline void CallbackR1ActionImplementation<R,T>::visit(agxControl::ActionImplementationVisitor* operation,
agx::Real time)
476 operation->update(
this, time);
480 template<
typename R,
typename T>
481 inline void CallbackR1ActionImplementation<R, T>::visit(
482 agxControl::ActionImplementationVisitor* , ActionImplementation* ,
agx::Real )
484 agxAbort1(
"Action: Asked to visit CallbackR1Actions with unsupported template parameters.");
488 inline void CallbackR1ActionImplementation<void, agx::Real>::visit(
489 agxControl::ActionImplementationVisitor* operation, ActionImplementation* end,
agx::Real time)
491 end->dispatchVisit(operation,
this, time);
494 template<
typename R,
typename T>
495 inline void CallbackR1ActionImplementation<R, T>::dispatchVisit(agxControl::ActionImplementationVisitor* ,
496 agxControl::CallbackR1ActionImplementation<void, agx::Real>* ,
agx::Real )
498 agxAbort1(
"Action: Asked to mix CallbackR1Actions with unsupported template parameters.");
502 inline void CallbackR1ActionImplementation<void, agx::Real>::dispatchVisit(
503 agxControl::ActionImplementationVisitor* operation,
504 agxControl::CallbackR1ActionImplementation<void, agx::Real> *begin,
agx::Real time)
506 operation->update(begin,
this, time);
509 template<
typename R,
typename T>
512 this->ActionImplementation::store(out);
517 template<
typename R,
typename T>
520 this->ActionImplementation::restore(in);
528 template<
typename T1,
typename T2>
529 Callback2ActionImplementation<T1, T2>::Callback2ActionImplementation():
530 ActionImplementation(
agx::
Real(-1.0)), m_value1(T1(0)), m_value2(T2(0))
534 template<
typename T1,
typename T2>
template<
typename ClassT>
535 Callback2ActionImplementation<T1, T2>::Callback2ActionImplementation(
536 agx::Real time,
void (ClassT::*
function)(T1, T2), ClassT *
object,
const T1 &value1,
const T2 &value2
538 ActionImplementation(time), m_callback(
std::bind(function, object,
std::placeholders:: _1,
std::placeholders:: _2)),
539 m_value1(value1), m_value2(value2)
544 template<
typename T1,
typename T2>
545 inline void Callback2ActionImplementation<T1, T2>::setValue1(
const T1& newValue)
551 template<
typename T1,
typename T2>
552 inline void Callback2ActionImplementation<T1, T2>::setValue2(
const T2& newValue)
558 template<
typename T1,
typename T2>
559 inline const T1& Callback2ActionImplementation<T1, T2>::getValue1()
const 565 template<
typename T1,
typename T2>
566 inline const T2& Callback2ActionImplementation<T1, T2>::getValue2()
const 572 template<
typename T1,
typename T2>
573 inline void Callback2ActionImplementation<T1, T2>::trigger(
agx::Real )
575 m_callback(m_value1, m_value2);
579 template<
typename T1,
typename T2>
580 inline void Callback2ActionImplementation<T1, T2>::visit(agxControl::ActionImplementationVisitor* operation,
agx::Real time)
582 operation->update(
this, time);
585 template<
typename T1,
typename T2>
586 inline void Callback2ActionImplementation<T1, T2>::visit(
587 agxControl::ActionImplementationVisitor* , ActionImplementation* ,
agx::Real )
589 agxAbort1(
"Action: Asked to visit Callback2Actions with unsupported template parameters.");
593 inline void Callback2ActionImplementation<agx::Real, agx::Int>::visit(
594 agxControl::ActionImplementationVisitor* operation, ActionImplementation* end,
agx::Real time)
596 end->dispatchVisit(operation,
this, time);
599 template<
typename T1,
typename T2>
600 inline void Callback2ActionImplementation<T1, T2>::dispatchVisit(agxControl::ActionImplementationVisitor* ,
601 agxControl::Callback2ActionImplementation<agx::Real, agx::Int>* ,
agx::Real )
603 agxAbort1(
"Action: Asked to mix Callbac2Actions with unsupported template parameters.");
607 inline void Callback2ActionImplementation<agx::Real, agx::Int>::dispatchVisit(
608 agxControl::ActionImplementationVisitor*operation,
609 agxControl::Callback2ActionImplementation<agx::Real, agx::Int> *begin,
612 operation->update(begin,
this, time);
616 template<
typename T1,
typename T2>
619 this->ActionImplementation::store(out);
625 template<
typename T1,
typename T2>
628 this->ActionImplementation::restore(in);
637 template<
typename T>
inline std::string templateToFormatName() {
return std::string(
"UnknownFormat: \'") +
typeid(T).name() +
"\'"; }
638 template<> std::string
inline templateToFormatName<bool>() {
return std::string(
"Bool:8bit"); }
639 template<> std::string
inline templateToFormatName<agx::Int32>() {
return std::string(
"Int:32bit"); }
640 template<> std::string
inline templateToFormatName<agx::Int64>() {
return std::string(
"Int:64bit"); }
641 template<> std::string
inline templateToFormatName<agx::Vec3f>() {
return std::string(
"Vec3:32bit"); }
642 template<> std::string
inline templateToFormatName<agx::Vec3d>() {
return std::string(
"Vec3:64bit"); }
645 inline const char* Callback1ActionImplementation<T>::getConstructClassId()
649 m_className =
"agxControl::Callback1ActionImplementation";
650 m_className = m_className + std::string(
"<") + templateToFormatName<T>() +
">";
651 return m_className.c_str();
655 inline const char* Callback1ActionImplementation<agx::Real>::getConstructClassId()
657 return "agxControl::Callback1ActionImplementation<Real>";
661 inline const char* Callback1ActionImplementation<T>::getClassName()
const 665 m_className =
"agxControl::Callback1ActionImplementation";
666 m_className = m_className + std::string(
"<") + templateToFormatName<T>() +
">";
667 return m_className.c_str();
671 inline const char* Callback1ActionImplementation<agx::Real>::getClassName()
const 673 return "agxControl::Callback1ActionImplementation<Real>";
677 template<
typename R,
typename T>
678 inline const char* CallbackR1ActionImplementation<R, T>::getConstructClassId()
682 m_className =
"agxControl::CallbackR1ActionImplementation<R, T>";
683 m_className = m_className.substr(0, m_className.length() - 6);
684 m_className += std::string(
"<") + templateToFormatName<R>() +
", " + templateToFormatName<T>() +
">";
685 return m_className.c_str();
689 inline const char* CallbackR1ActionImplementation<agx::Real, agx::Real>::getConstructClassId()
691 return "agxControl::CallbackR1ActionImplementation<Real, Real>";
694 template<
typename R,
typename T>
695 inline const char* CallbackR1ActionImplementation<R, T>::getClassName()
const 698 m_className =
"agxControl::CallbackR1ActionImplementation<R, T>";
699 m_className = m_className.substr(0, m_className.length() - 6);
700 m_className += std::string(
"<") + templateToFormatName<R>() +
", " + templateToFormatName<T>() +
">";
701 return m_className.c_str();
705 inline const char* CallbackR1ActionImplementation<agx::Real, agx::Real>::getClassName()
const 707 return "agxControl::CallbackR1ActionImplementation<Real, Real>";
711 template<
typename T1,
typename T2>
712 inline const char* Callback2ActionImplementation<T1, T2>::getConstructClassId()
715 m_className =
"agxControl::Callback2ActionImplementation<T1, T2>";
716 m_className = m_className.substr(0, m_className.length() - 8);
717 m_className += std::string(
"<") + templateToFormatName<T1>() +
", " + templateToFormatName<T2>() +
">";
718 return m_className.c_str();
722 inline const char* Callback2ActionImplementation<agx::Real, agx::Real>::getConstructClassId()
724 return "agxControl::Callback2ActionImplementation<Real, Real>";
728 inline const char* Callback2ActionImplementation<agx::Real, agx::Int32>::getConstructClassId()
730 return "agxControl::Callback2ActionImplementation<Real, Int32>";
734 inline const char* Callback2ActionImplementation<agx::Real, agx::Int64>::getConstructClassId()
736 return "agxControl::Callback2ActionImplementation<Real, Int64>";
739 template<
typename T1,
typename T2>
740 inline const char* Callback2ActionImplementation<T1, T2>::getClassName()
const 743 m_className =
"agxControl::Callback2ActionImplementation<T1, T2>";
744 m_className = m_className.substr(0, m_className.length() - 8);
745 m_className += std::string(
"<") + templateToFormatName<T1>() +
", " + templateToFormatName<T2>() +
">";
746 return m_className.c_str();
750 inline const char* Callback2ActionImplementation<agx::Real, agx::Real>::getClassName()
const 752 return "agxControl::Callback2ActionImplementation<Real, Real>";
756 inline const char* Callback2ActionImplementation<agx::Real, agx::Int32>::getClassName()
const 758 return "agxControl::Callback2ActionImplementation<Real, Int32>";
762 inline const char* Callback2ActionImplementation<agx::Real, agx::Int64>::getClassName()
const 764 return "agxControl::Callback2ActionImplementation<Real, Int64>";
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive...
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
Base class providing referencing counted objects.
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
LinearProbingHashSetImplementation< KeyT, HashT >::iterator begin(LinearProbingHashSetImplementation< KeyT, HashT > &set)
This namespace contains general operation and action classes which can be used to control a agxSDK::S...
AGXTERRAIN_EXPORT agx::Real & currentTime()
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Class for writing serialized data in binary format to a stream.
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)