48 #ifndef _MIRA_CLASS_H_ 49 #define _MIRA_CLASS_H_ 56 #include <boost/shared_ptr.hpp> 78 template <
typename CLASS>
101 template<
typename CLASS>
112 virtual std::string
const& getIdentifier()
const;
120 virtual std::string
const& getName()
const;
127 virtual int getTypeId()
const = 0;
132 virtual Typename getTypename()
const = 0;
138 std::map<std::string, std::string>
const& getMetaInfo()
const;
145 std::string
const& getMetaInfo(
const std::string& meta)
const;
154 virtual Object* newInstance()
const = 0;
163 template <
class CLASS>
164 CLASS* newInstance()
const;
176 virtual Object* newInstance(
int paramCount, ... )
const = 0;
185 virtual Object* newInstance( std::string
const& childIdentifier )
const = 0;
194 template <
class CLASS>
195 CLASS* newInstance( std::string
const& childIdentifier )
const;
207 virtual Object* newInstance( std::string
const& childIdentifier,
208 int paramCount, ... )
const = 0;
213 bool isClassRegistered( std::string
const& classIdentifier )
const;
220 void eraseChild(
Class const*
const iClass );
227 void eraseParent(
Class const*
const iClass );
234 std::string
const& classIdentifier )
const;
240 std::vector<ClassProxy> getClassByMeta( std::string
const& metaKey,
241 std::string
const& metaValue )
const;
251 std::vector<ClassProxy> getClassByMeta( T funcPtr )
const;
256 std::map<std::string, ClassProxy> getDerivedClasses()
const;
261 std::map<std::string, ClassProxy> getDirectParents()
const;
266 bool isBaseOf(
Class const*
const derived )
const;
276 bool isBaseOf( std::string
const& identifier )
const;
281 bool isDerivedFrom(
Class const*
const base )
const;
291 bool isDirectlyDerivedFrom(
Class const*
const base )
const;
296 bool isDirectlyDerivedFrom(
ClassProxy base )
const;
302 bool isDeclaredAbstract()
const;
307 virtual bool isAbstract()
const = 0;
314 bool isLibraryLoaded()
const;
324 template<
typename Reflector>
333 template<
typename Reflector>
340 return this == &other;
347 return this != &other;
362 virtual Object* newVAInstance(
int paramCount, std::va_list )
const = 0;
367 Class( std::string
const& identifier,
368 std::string
const& name,
369 std::map<std::string, std::string>
const& metaInfo,
375 Class ( std::string
const& identifier, std::string
const& name,
406 template<
typename CLASS>
421 if ( !mClass || !*mClass || !other.
mClass || !*other.
mClass )
422 MIRA_THROW( XFactoryLogical,
"ClassProxy invalid!" );
423 return **other.
mClass == **mClass;
427 if ( !mClass || !*mClass || !other.
mClass || !*other.
mClass )
428 MIRA_THROW( XFactoryLogical,
"ClassProxy invalid!" );
429 return **other.
mClass != **mClass;
433 if ( !mClass || !*mClass || !other.
mClass || !*other.
mClass )
434 MIRA_THROW( XFactoryLogical,
"ClassProxy invalid!" );
435 return **mClass < **other.
mClass;
442 std::string
const& getIdentifier()
const;
448 std::string
const& getName()
const;
454 int getTypeId()
const;
466 std::map<std::string, std::string>
const& getMetaInfo()
const;
472 std::string
const& getMetaInfo(
const std::string& meta)
const;
478 Object* newInstance()
const;
484 template <
class CLASS>
487 boost::recursive_mutex::scoped_lock lock( *mThreadMutex );
488 return (*mClass)->newInstance<CLASS>();
495 Object* newInstance(
int paramCount, ... )
const;
501 Object* newInstance( std::string
const& childIdentifier )
const;
507 template <
class CLASS>
510 boost::recursive_mutex::scoped_lock lock( *mThreadMutex );
511 return (*mClass)->newInstance<CLASS>( childIdentifier );
518 Object* newInstance( std::string
const& childIdentifier,
519 int paramCount, ... )
const;
525 bool isClassRegistered( std::string
const& classIdentifier )
const;
532 void eraseChild(
Class const*
const iClass );
539 void eraseParent(
Class const*
const iClass );
545 ClassProxy getClassByIdentifier(std::string
const& classIdentifier )
const;
551 std::vector<ClassProxy> getClassByMeta(std::string
const& metaKey,
552 std::string
const& metaValue )
const;
561 boost::recursive_mutex::scoped_lock lock( *mThreadMutex );
562 return (*mClass)->getClassByMeta( funcPtr );
569 std::map<std::string, ClassProxy > getDerivedClasses()
const;
575 std::map<std::string, ClassProxy > getDirectParents()
const;
581 bool isBaseOf(
Class const*
const derived )
const;
593 bool isBaseOf( std::string
const& identifier )
const;
599 bool isDerivedFrom(
Class const*
const base )
const;
611 bool isDirectlyDerivedFrom(
Class const*
const base )
const;
617 bool isDirectlyDerivedFrom(
ClassProxy base )
const;
622 bool isAbstract()
const;
629 bool isLibraryLoaded()
const;
632 Object* newVAInstance(
int paramCount, std::va_list list )
const;
634 ClassProxy( boost::shared_ptr<Class>* iClass );
635 void setClass( boost::shared_ptr<Class>* iClass );
652 struct ClassFactoryAbstractClassBuilder {
654 template<
typename CLASS>
655 static CLASS* invoke( ) {
656 MIRA_THROW( XFactoryLogical,
"Cannot create abstract class (" 657 + CLASS::CLASS().getIdentifier() +
")!" );
661 template<
int N,
typename CLASS>
662 static CLASS* invoke( std::va_list ) {
663 MIRA_THROW( XFactoryLogical,
"Cannot create abstract class (" 664 + CLASS::CLASS().getIdentifier() +
")!" );
678 struct ClassFactoryNoDefaultConstClassBuilder {
679 template<
typename CLASS>
680 static CLASS* invoke( ) {
681 MIRA_THROW( XFactoryLogical,
"No public default constructor available for class" 682 "creation (" + CLASS::CLASS().getIdentifier() +
")!" );
698 struct ClassFactoryDefaultConstClassBuilder {
700 template<
typename CLASS>
701 static CLASS* invoke( ) {
705 template<
int N,
typename CLASS>
706 static CLASS* invoke( std::va_list ) {
707 MIRA_THROW( XFactoryLogical,
"Desired parameter constructor not registered (" 708 + CLASS::CLASS().getIdentifier() +
")!" );
719 template <
class CLASS>
722 Object* tBase = newInstance();
723 return mira_factoryDynamicCast<CLASS>( tBase );
726 template <
class CLASS>
729 Object* tBase = newInstance( childIdentifier );
730 return mira_factoryDynamicCast<CLASS>( tBase );
736 std::vector<ClassProxy> tReturn;
738 std::map<std::string, ClassProxy >::const_iterator tIt = mDerivedChildren.begin();
739 for( ; tIt != mDerivedChildren.end(); tIt++ ) {
740 if ( funcPtr( tIt->second.getMetaInfo() ) ) {
741 tReturn.push_back( tIt->second );
750 template<
typename Reflector>
753 r.member(
"Identifier" , mIdentifier,
"" );
754 r.member(
"Name" , mName,
"" );
755 r.member(
"Lib" , mLib,
"" );
756 r.member(
"Meta" , mMetaInfo,
"" );
757 bool tAbstract = isAbstract();
758 r.member(
"Abstract", tAbstract,
"" );
761 template<
typename Reflector>
764 r.member(
"Identifier" , mIdentifier,
"" );
765 r.member(
"Name" , mName,
"" );
766 r.member(
"Lib" , mLib,
"" );
767 r.member(
"Meta" , mMetaInfo,
"" );
774 template <
typename CLASS>
777 CLASS* tClass =
dynamic_cast<CLASS*
> ( base );
779 std::string tName =
"NULL";
784 MIRA_THROW( XFactoryBadCast,
"You try to cast created object to incompatible" 785 " base class (" + tName +
")!");
Macro for iterating over all elements in a container.
void reflectWrite(Reflector &r, Buffer< T, Allocator > &c)
Specialization of the non-intrusive reflect for Buffer.
Definition: Buffer.h:581
#define MIRA_DEFINE_EXCEPTION(Ex, Base)
Macro for easily defining a new compatible exception class.
Definition: Exception.h:170
void reflectWrite(Reflector &r)
Implementation of class member reflection.
Definition: Class.h:762
CLASS * mira_factoryDynamicCast(Object *base)
Auxiliary function which throws an XFactoryBadCast exception if the cast fails and deletes the object...
Definition: Class.h:775
What should i say, the class factory.
Definition: Factory.h:88
The class proxy assures that the pointer to the class object is always valid.
Definition: Class.h:400
bool operator<(const ImgIteratorBase &a, const ImgIteratorBase &b)
Definition: ImgIterator.h:231
ClassProxy ClassPtr
Definition: Class.h:74
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
std::string Typename
Definition: Typename.h:60
#define MIRA_SPLIT_REFLECT_MEMBER
Macro that insert a class member reflect() method just splitting reflection into a reflectRead() and ...
Definition: SplitReflect.h:209
Class object which supports some kind of class reflection.
Definition: Class.h:97
std::vector< ClassProxy > getClassByMeta(T funcPtr) const
Return vector of Class objects returning true for the given.
Definition: Class.h:559
Get compiler and platform independent typenames.
Provides MIRA_SPLIT_REFLECT macros.
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
MIRA_SPLIT_REFLECT_MEMBER void reflectRead(Reflector &r)
Implementation of class member reflection.
std::string mName
class name
Definition: Class.h:388
bool operator==(Class const &other) const
Returns true, if the two classes are identical.
Definition: Class.h:339
bool operator!=(Class const &other) const
Returns true, if the two classes are not identical.
Definition: Class.h:346
Includes, defines and functions for threads.
boost::recursive_mutex * mThreadMutex
Definition: Class.h:639
bool mLibLoaded
is associated lib loaded?
Definition: Class.h:391
std::string mLib
lib name
Definition: Class.h:389
The object class acts as a generic base class for classes which should be used with the classFactory...
Definition: Object.h:144
bool operator==(const ImgIteratorBase &a, const ImgIteratorBase &b)
Definition: ImgIterator.h:225
The VacantClass object is the implementation of the Class class for classes which are NOT available s...
Definition: VacantClass.h:68
std::map< std::string, std::string > mMetaInfo
meta info of class
Definition: Class.h:390
virtual std::string const & getIdentifier() const
Return identifier for the class.
std::vector< ClassProxy > getClassByMeta(std::string const &metaKey, std::string const &metaValue) const
Return vector of ClassProxy objects matching the meta criterion.
Base class for exceptions.
Definition: Exception.h:199
Class const & getClass() const
call the virtual internalGetClass().
Definition: Object.h:159
virtual Object * newInstance() const =0
Return a new instance of the class associated with the class object.
CLASS * newInstance(std::string const &childIdentifier) const
Return a new instance of the child class with the given identifier.
Definition: Class.h:508
std::map< std::string, ClassProxy > mDerivedChildren
map of children
Definition: Class.h:385
void reflectRead(Reflector &r, Buffer< T, Allocator > &c)
Specialization of the non-intrusive reflect for Buffer.
Definition: Buffer.h:565
ClassProxy(ClassProxy const &other)
Definition: Class.h:414
The TClass object is the implementation of the class class for classes which are available since the ...
Definition: TClass.h:75
$Defines object class as base class for classFactory compatible classes$.
boost::shared_ptr< Class > * mClass
Definition: Class.h:638
bool operator!=(const ImgIteratorBase &a, const ImgIteratorBase &b)
Definition: ImgIterator.h:228
CLASS * newInstance() const
Return a new instance of the class associated with the class object.
Definition: Class.h:485
std::string mIdentifier
class identifier
Definition: Class.h:387
Provides method for generating a unique id for any type.
std::map< std::string, ClassProxy > mDirectParents
map of parents
Definition: Class.h:386
ClassProxy()
Definition: Class.h:410