33#ifndef __H__UG_BRIDGE__CLASS_NAME_PROVIDER_IMPL__
34#define __H__UG_BRIDGE__CLASS_NAME_PROVIDER_IMPL__
49template <
typename TClass>
51set_name(
const std::string& nameIn,
const std::string& group,
bool newName)
54 if(newName ==
true && m_bForwardDeclared==
false && !m_ClassNameNode.empty())
58 "Trying to register class with name '"<<nameIn
59 <<
"', that has already been named. This is not allowed.");
66 if(nameIn.c_str()[0] ==
'[')
70 size_t found = nameIn.find_first_not_of(
"abcdefghijklmnopqrstuvwxyz"
71 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
74 if (found!=std::string::npos)
76 UG_ERR_LOG(
"Non-allowed character '"<<nameIn[found]<<
"' "<<
77 "contained at position "<<
int(found)<<
" in registered Class Name "
78 "'"<<nameIn<<
"'.\nClass names must match the regular expression: "
79 "[a-zA-Z_][a-zA-Z_0-9]*, \ni.e. only alphabetic characters, numbers "
80 " and '_' are allowed; no numbers at the beginning.\n");
85 found = nameIn.find_first_of(
"0123456789");
86 if (found!=std::string::npos && found == 0)
88 UG_ERR_LOG(
"Class Name "<<nameIn<<
" starts with a number.\nThis is "
89 " not allowed. Please change naming.\n");
95 m_ClassNameNode.set_name(nameIn);
98 m_bForwardDeclared =
false;
101 m_group = std::string(group);
104template <
typename TClass>
105template <
typename TParent1>
107set_name(
const std::string&
name,
const std::string& group,
bool newName)
116template <
typename TClass>
117template <
typename TParent1,
typename TParent2>
119set_name(
const std::string&
name,
const std::string& group,
bool newName)
122 set_name(
name, group, newName);
129template <
typename TClass>
133 if(m_bForwardDeclared)
135 "Class '"<<parent<<
"' must not be foreward declared to use is_a");
141 if(parent ==
name())
return true;
151template <
typename TClass>
155 if(m_ClassNameNode.empty()) set_foreward_declared();
158 return m_ClassNameNode.name();
161template <
typename TClass>
165 if(m_ClassNameNode.empty()) set_foreward_declared();
175template <
typename TClass>
179 std::string
name(
"[[");
180 name.append( TypeName<TClass>() );
181 name.append(
" (undeclared) ]]");
184 m_ClassNameNode.set_name(
name);
185 m_bForwardDeclared =
true;
188template <
typename TClass>
191template <
typename TClass>
194template <
typename TClass>
197template <
typename TClass>
204template <
typename TBase,
typename TDerived>
209 TDerived* pDeriv =
reinterpret_cast<TDerived*
>(DerivVoidPtr);
212 TBase* pBase =
static_cast<TBase*
>(pDeriv);
215 return reinterpret_cast<void*
>(pBase);
218template <
typename TBase,
typename TDerived>
226 std::pair<const ClassNameNode*, const ClassNameNode*>
227 namePair(pBaseNode, pDerivNode);
229 m_mmCast[namePair] = &StaticVoidCast<TBase, TDerived>;
243 return reinterpret_cast<T*
>(ptr);
257 return reinterpret_cast<const T*
>(ptr);
268 void* rawPtr = spDerivVoid.
get();
288 const void* rawPtr = spDerivVoid.
get();
location name
Definition checkpoint_util.lua:128
Definition smart_pointer.h:296
const T * get() const
Definition smart_pointer.h:409
ConstSmartPtr< TDest, FreePolicy > cast_reinterpret() const
performs a static cast
Definition smart_pointer.h:440
Definition smart_pointer.h:51
Definition smart_pointer.h:108
T * get()
returns encapsulated pointer
Definition smart_pointer.h:197
SmartPtr< TDest, FreePolicy > cast_reinterpret() const
performs a reinterpret cast
Definition smart_pointer.h:232
static void * cast_to_base_class(void *pDerivVoid, const ClassNameNode *&node, const std::string &baseName)
cast a pointer to the desired base class
Definition class_name_provider.cpp:139
static T * cast_to(void *pDerivVoid, const ClassNameNode *&node)
casts a void pointer to a concrete class
Definition class_name_provider_impl.h:234
static std::map< std::pair< const ClassNameNode *, const ClassNameNode * >, CastFunc > m_mmCast
Definition class_name_provider.h:236
static void add_cast_func()
add a cast function to the registry: Casts: Derived -> Base
Definition class_name_provider_impl.h:219
node for class names
Definition class_name_provider.h:65
provides the name for a class
Definition class_name_provider.h:102
static const ClassNameNode & class_name_node()
return the class name node in the class hierarchy
Definition class_name_provider.h:136
static void set_foreward_declared()
sets a temporary name to the class
Definition class_name_provider_impl.h:176
static void set_name(const std::string &nameIn, const std::string &group, bool newName=false)
set name of class and copy parent names
Definition class_name_provider_impl.h:107
static const std::string & name()
name of this class
Definition class_name_provider_impl.h:152
static bool is_a(const std::string &parent, bool strict=false)
Definition class_name_provider_impl.h:130
static void set_name(const std::string &nameIn, const std::string &group, bool newName=false)
set name of class and copy parent names
Definition class_name_provider_impl.h:51
static const std::vector< const char * > & names()
returns vector of all names including parent class names
Definition class_name_provider_impl.h:162
void * StaticVoidCast(void *DerivVoidPtr)
static cast function for two classes
Definition class_name_provider_impl.h:205
bool ClassNameTreeContains(const ClassNameNode &node, const std::string &name)
returns if a name is contained in the name tree at node or in base classes
Definition class_name_provider.cpp:104
void ExtractClassNameVec(std::vector< const char * > &names, const ClassNameNode &node, bool clearVec)
returns the vector containing all names in the name tree for node and its base classes
Definition class_name_provider.cpp:90
#define UG_ERR_LOG(msg)
Definition log.h:383
void baseName(std::string &nameOut, const std::string &nameIn)
Definition vtkoutput.cpp:209
#define UG_THROW_REGISTRY_MSG(msg)
Definition error.h:81
#define UG_THROW_REGISTRY_ERROR(cls, msg)
Definition error.h:76