48 #ifndef _MIRA_TCLASS_H_ 49 #define _MIRA_TCLASS_H_ 74 template<
typename CLASS>
84 TClass( std::string
const& identifier,
85 std::string
const& name,
118 CLASS*
newInstance( std::string
const& childIdentifier )
const;
126 int paramCount, ... )
const;
141 std::va_list ap )
const;
160 template<
typename CLASS>
162 std::string
const& name,
bool libLoaded ) :
163 Class( identifier, name, libLoaded )
166 CLASS::addMetaInfo( mMetaInfo );
169 template<
typename CLASS>
172 return typeId<CLASS>();
175 template<
typename CLASS>
178 return typeName<CLASS>();
181 template<
typename CLASS>
184 return std::is_abstract<CLASS>::value;
188 template<
typename CLASS>
195 boost::mpl::eval_if<std::is_abstract<CLASS>,
196 boost::mpl::identity<ClassFactoryAbstractClassBuilder>,
199 boost::mpl::identity< ClassFactoryDefaultConstClassBuilder >,
200 boost::mpl::identity< ClassFactoryNoDefaultConstClassBuilder > >
203 return ClassType::template invoke<CLASS>( );
206 template<
typename CLASS>
210 va_start(ap, paramCount);
211 return newVAInstance( paramCount, ap);
214 template<
typename CLASS>
220 if( childIdentifier == getIdentifier() )
221 return newInstance();
223 if ( mDerivedChildren.find( childIdentifier ) ==
224 mDerivedChildren.end() ) {
225 MIRA_THROW( XFactoryUnknown,
"Unknown class identifier (" 226 + childIdentifier +
") calling newInstance on " + getIdentifier()
229 Object* tObject = mDerivedChildren.find( childIdentifier )->second.newInstance();
231 MIRA_THROW( XFactoryLogical,
"Class creation failed (" + childIdentifier
232 +
") calling newInstance on " + getIdentifier() +
"!" );
235 return mira_factoryDynamicCast<CLASS>( tObject );
238 template<
typename CLASS>
240 int paramCount, ... )
const 243 va_start(ap, paramCount);
245 return newVAInstance( childIdentifier, paramCount, ap );
248 template<
typename CLASS>
251 std::va_list ap )
const 255 if(childIdentifier==getIdentifier())
256 return newVAInstance(paramCount, ap);
258 if ( mDerivedChildren.find( childIdentifier ) ==
259 mDerivedChildren.end() ) {
260 MIRA_THROW( XFactoryUnknown,
"Unknown class identifier (" 261 + childIdentifier +
") calling newInstance on " + getIdentifier()
265 Object* tObject = mDerivedChildren.find( childIdentifier )->second
266 .newVAInstance(paramCount, ap);
268 MIRA_THROW( XFactoryLogical,
"Class creation failed (" + childIdentifier
269 +
") calling newInstance on " + getIdentifier() +
"!" );
274 template<
typename CLASS>
279 typedef typename boost::mpl::eval_if<std::is_abstract<CLASS>,
280 boost::mpl::identity<ClassFactoryAbstractClassBuilder>,
281 boost::mpl::identity<ClassFactoryDefaultConstClassBuilder>
286 return newInstance();
288 return ClassType::template invoke<1,CLASS>( ap);
290 return ClassType::template invoke<2,CLASS>( ap);
292 return ClassType::template invoke<3,CLASS>( ap);
294 return ClassType::template invoke<4,CLASS>( ap);
296 MIRA_THROW( XFactoryLogical,
"Invalid number of arguments for " 297 "constructor (" + std::to_string((uint64)paramCount) +
" arguments for " 298 + getIdentifier() +
")!");
Macro for iterating over all elements in a container.
$Definition of the Class which supports some kind of class reflection and acts like a class factory$...
What should i say, the class factory.
Definition: Factory.h:88
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
virtual int getTypeId() const
Return unique id for the class.
Definition: TClass.h:170
std::string Typename
Definition: Typename.h:60
Class object which supports some kind of class reflection.
Definition: Class.h:97
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
CLASS * newInstance() const
Return a new instance of the class associated with the class object.
Definition: TClass.h:189
PropertyHint type(const std::string &t)
Sets the attribute "type" to the specified value.
Definition: PropertyHint.h:295
The object class acts as a generic base class for classes which should be used with the classFactory...
Definition: Object.h:144
virtual bool isAbstract() const
Return true if the associated class is abstract.
Definition: TClass.h:182
MIRA_MEMBER_DETECTOR(mNoPublicDefaultConstructor)
Object * newVAInstance(std::string const &childIdentifier, int paramCount, std::va_list ap) const
Return a new instance of the child class with the given identifier.
Definition: TClass.h:249
The TClass object is the implementation of the class class for classes which are available since the ...
Definition: TClass.h:75
Macros for checking the existence of class members.
virtual Typename getTypename() const
Returns the platform independent C++ typename of the class.
Definition: TClass.h:176