Loading...
Searching...
No Matches
embeddable.h
Go to the documentation of this file.
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#ifndef BALL_CONCEPT_EMBEDDABLE_H
#define BALL_CONCEPT_EMBEDDABLE_H
#ifndef BALL_COMMON_H
# include <BALL/common.h>
#endif
#ifndef BALL_DATATYPE_STRINGHASHMAP_H
# include <BALL/DATATYPE/stringHashMap.h>
#endif
#ifndef BALL_DATATYPE_HASHMAP_H
# include <BALL/DATATYPE/hashMap.h>
#endif
#include <typeinfo>
namespace BALL
{
#define BALL_EMBEDDABLE(TYPE,BASE)\
virtual void registerThis() \
{ \
if (typeid(*this) != typeid(TYPE))\
{\
Log.error() << "Warning: derived class " << typeid(*this).name() << " was derived from BALL::Embeddable, but the macro\n"\
<< "BALL_EMBEDDABLE(...) was not specified in the class declaration!" << std::endl;\
}\
Embeddable::registerInstance_(typeid(TYPE), this);\
Embeddable::registerInstance_(typeid(BASE), this);\
}\
\
static TYPE* getInstance(Position index) \
{ \
Embeddable* ptr = Embeddable::getInstance_(typeid(TYPE), index);\
if (ptr != 0)\
{\
return dynamic_cast<TYPE*>(ptr); \
}\
else\
{\
return 0;\
}\
}\
static TYPE* getInstance(const String& identifier) \
{\
Embeddable* ptr = Embeddable::getInstance_(typeid(TYPE), identifier);\
if (ptr != 0)\
{\
return dynamic_cast<TYPE*>(ptr); \
}\
else\
{\
return 0;\
}\
}\
static Size countInstances() { return (Embeddable::countInstances_(typeid(TYPE))); };
class BALL_EXPORT Embeddable
{
public:
typedef std::vector<Embeddable*> EmbeddableVector;
Embeddable(const String& identifier = "<Embeddable>")
;
Embeddable(const Embeddable& embeddable)
;
virtual ~Embeddable()
;
void setIdentifier(const String& identifier)
;
const String& getIdentifier() const
;
void unregisterThis()
;
virtual void registerThis()
;
virtual void dump(std::ostream& s = std::cout, Size depth = 0) const
;
protected:
static void registerInstance_(const std::type_info& type, const Embeddable* instance)
;
static void unregisterInstance_(const Embeddable* instance)
;
static Size countInstances_(const std::type_info& type)
;
static Embeddable* getInstance_(const std::type_info& type, Position index)
;
static Embeddable* getInstance_(const std::type_info& type, const String& identifier)
;
private:
String identifier_;
static StringHashMap<EmbeddableVector> instance_vectors_;
static HashMap<Embeddable*, string> instance_to_type_map_;
};
} // namespace BALL
#endif // BALL_CONCEPT_EMBEDDABLE_H
BALL_EXPORT
#define BALL_EXPORT
Definition COMMON/global.h:50
BALL::Embeddable::Embeddable
Embeddable(const Embeddable &embeddable)
BALL::Embeddable::registerThis
virtual void registerThis()
BALL::Embeddable::setIdentifier
void setIdentifier(const String &identifier)
BALL::Embeddable::Embeddable
Embeddable(const String &identifier="<Embeddable>")
BALL::Embeddable::countInstances_
static Size countInstances_(const std::type_info &type)
BALL::Embeddable::getInstance_
static Embeddable * getInstance_(const std::type_info &type, Position index)
BALL::Embeddable::~Embeddable
virtual ~Embeddable()
BALL::Embeddable::unregisterThis
void unregisterThis()
BALL::Embeddable::EmbeddableVector
std::vector< Embeddable * > EmbeddableVector
Definition embeddable.h:88
BALL::Embeddable::getInstance_
static Embeddable * getInstance_(const std::type_info &type, const String &identifier)
BALL::Embeddable::getIdentifier
const String & getIdentifier() const
BALL::Embeddable::dump
virtual void dump(std::ostream &s=std::cout, Size depth=0) const
BALL::Embeddable::unregisterInstance_
static void unregisterInstance_(const Embeddable *instance)
BALL::Embeddable::registerInstance_
static void registerInstance_(const std::type_info &type, const Embeddable *instance)
BALL::HashMap
HashMap class based on the STL map (containing serveral convenience functions).
Definition hashMap.h:74
BALL::StringHashMap
Definition stringHashMap.h:42
BALL::String
Definition string.h:57
common.h
hashMap.h
BALL
Definition constants.h:13
BALL::Size
BALL_SIZE_TYPE Size
Definition COMMON/global.h:114
BALL::Position
BALL_SIZE_TYPE Position
Definition COMMON/global.h:140
stringHashMap.h