#include <ExpectedType.h>
Public Types | |
typedef boost::shared_ptr < const ExpectedType > | Ptr |
Public Member Functions | |
template<typename T > | |
bool | is () const |
Check if an actual type equals this expected type. | |
bool | operator!= (const ExpectedType &other) const |
Directly compare two ExpectedType objects. | |
bool | operator== (const ExpectedType &other) const |
Directly compare two ExpectedType objects. | |
virtual | ~ExpectedType () |
Protected Member Functions | |
virtual bool | equals (const ExpectedType *other) const =0 |
An object bearing information about the type expected from some operation. If a complex function call will return an object of a certain type depending on runtime circumstances, it may not always be desirable, or even possible, to start the operation, wait for the returned object, and perform a dynamic_cast to see what it is. Instead, the class can provide another function which tells you which datatype to expect given the parameters you would pass to the complex function. This can be used as follows:
class Foo : public BaseClass { ... }; class Bar : public BaseClass { ... }; ExpectedType::Ptr et = complex_op.expectedReturnType(params); if (et->is<Foo>()) std::cout << "Operation will return a Foo object\n"; if (et->is<Bar>()) std::cout << "Operation will return a Bar object\n"; BaseClass::Ptr result = complex_op.execute(params); // Wait some time... std::cout << result << "\n"; // Prints stuff for Foo or Bar, depending on result
Definition at line 58 of file ExpectedType.h.
typedef boost::shared_ptr<const ExpectedType> icl_core::ExpectedType::Ptr |
Definition at line 61 of file ExpectedType.h.
virtual icl_core::ExpectedType::~ExpectedType | ( | ) | [inline, virtual] |
Definition at line 63 of file ExpectedType.h.
virtual bool icl_core::ExpectedType::equals | ( | const ExpectedType * | other | ) | const [protected, pure virtual] |
Implemented in icl_core::ExpectedTypeIs< T >.
bool icl_core::ExpectedType::is | ( | ) | const [inline] |
Check if an actual type equals this expected type.
Definition at line 66 of file ExpectedType.h.
bool icl_core::ExpectedType::operator!= | ( | const ExpectedType & | other | ) | const [inline] |
Directly compare two ExpectedType objects.
Definition at line 75 of file ExpectedType.h.
bool icl_core::ExpectedType::operator== | ( | const ExpectedType & | other | ) | const [inline] |
Directly compare two ExpectedType objects.
Definition at line 69 of file ExpectedType.h.