SCL
1.0
Standard Control Library : Control, dynamics, physics, and simulation
|
Functions | |
template<typename Idx , typename ArgumentTuple , typename Data = bool> | |
bool | call (const Idx &arg_callback_name, ArgumentTuple &args) |
template<typename CallbackClass , typename Idx , typename ArgumentTuple , typename Data = bool> | |
bool | add (const Idx &arg_callback_name) |
template<typename CallbackClass , typename Idx , typename ArgumentTuple , typename Data > | |
bool | add (const Idx &arg_callback_name, Data *arg_data) |
template<typename Idx > | |
bool | list (std::vector< Idx > &idxlist) |
Use this namespace to create and call callback functions
Example usage:
// 1. Defining a callback function class
// NOTE: You can also use typename Data to // customize different objects of this class and then // register them. class CCallbackFunc : public sutil::CCallbackBase<std::string, std::vector<std::string> > { typedef sutil::CCallbackBase<std::string, std::vector<std::string> > base; public: virtual void call(std::vector<std::string>& args) {//Do something with the argument std::vector<std::string>::iterator it,ite; for(it = args.begin(), ite = args.end(); it!=ite; ++it) { std::cout<<"\nPassed arg : "<<*it; }
//And/or copy the result into it std::string x; std::cin>>x; args.push_back(x); }
virtual base* createObject() { return dynamic_cast<base*>(new CCallbackFunc()); } };
//2. Register the function std::string name("BoboFunc"); std::vector<std::string> args;
flag = sutil::callbacks::add<CCallbackFunc, std::string, std::vector<std::string> >(name);
//3. Call the function sutil::callbacks::call<std::string,std::vector<std::string> >(callback_name,args);
bool sutil::callbacks::add | ( | const Idx & | arg_callback_name | ) |
Why do we allow specifying Data? Ans: Well a class might automatically and uniquely initialize the Data in the constructor
bool sutil::callbacks::call | ( | const Idx & | arg_callback_name, |
ArgumentTuple & | args | ||
) |
This function returns an indexed callback (if the callback has already been registered with the singleton)
bool sutil::callbacks::list | ( | std::vector< Idx > & | idxlist | ) |
Return a list of the registered callbacks (a vector of indices)