33 #ifndef __H__UG_BRIDGE__CLASS_NAME_PROVIDER_IMPL__
34 #define __H__UG_BRIDGE__CLASS_NAME_PROVIDER_IMPL__
49 template <
typename TClass>
51 set_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);
104 template <
typename TClass>
105 template <
typename TParent1>
107 set_name(
const std::string&
name,
const std::string& group,
bool newName)
110 set_name(
name, group, newName);
116 template <
typename TClass>
117 template <
typename TParent1,
typename TParent2>
119 set_name(
const std::string&
name,
const std::string& group,
bool newName)
122 set_name(
name, group, newName);
129 template <
typename TClass>
133 if(m_bForwardDeclared)
135 "Class '"<<parent<<
"' must not be foreward declared to use is_a");
141 if(parent ==
name())
return true;
151 template <
typename TClass>
155 if(m_ClassNameNode.empty()) set_foreward_declared();
158 return m_ClassNameNode.name();
161 template <
typename TClass>
165 if(m_ClassNameNode.empty()) set_foreward_declared();
175 template <
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;
188 template <
typename TClass>
191 template <
typename TClass>
194 template <
typename TClass>
197 template <
typename TClass>
204 template <
typename TBase,
typename TDerived>
209 TDerived* pDeriv =
reinterpret_cast<TDerived*
>(DerivVoidPtr);
212 TBase* pBase =
static_cast<TBase*
>(pDeriv);
215 return reinterpret_cast<void*
>(pBase);
218 template <
typename TBase,
typename TDerived>
221 const ClassNameNode* pBaseNode =
223 const ClassNameNode* pDerivNode =
226 std::pair<const ClassNameNode*, const ClassNameNode*>
227 namePair(pBaseNode, pDerivNode);
229 m_mmCast[namePair] = &StaticVoidCast<TBase, TDerived>;
232 template <
typename T>
234 cast_to(
void* ptr,
const ClassNameNode*& node)
243 return reinterpret_cast<T*
>(ptr);
246 template <
typename T>
248 cast_to(
const void* ptr,
const ClassNameNode*& node)
257 return reinterpret_cast<const T*
>(ptr);
260 template <
typename T>
268 void* rawPtr = spDerivVoid.
get();
280 template <
typename T>
288 const void* rawPtr = spDerivVoid.
get();
location name
Definition: checkpoint_util.lua:128
Definition: smart_pointer.h:650
ConstSmartPtr< T, TFreePolicy > cast_reinterpret() const
Returns a SmartPtr with the specified type and shared reference counting.
Definition: smart_pointer.h:763
const void * get() const
Definition: smart_pointer.h:789
void set_impl(const void *ptr)
sets the void* to a different location correspoding to a cast to a new type T
Definition: smart_pointer.h:772
Definition: smart_pointer.h:296
Definition: smart_pointer.h:51
Definition: smart_pointer.h:525
void set_impl(void *ptr)
sets the void* to a different location correspoding to a cast to a new type T
Definition: smart_pointer.h:608
void * get()
Definition: smart_pointer.h:625
SmartPtr< T, TFreePolicy > cast_reinterpret() const
Returns a SmartPtr with the specified type and shared reference counting.
Definition: smart_pointer.h:599
Definition: smart_pointer.h:108
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
static void add_cast_func()
add a cast function to the registry: Casts: Derived -> Base
static std::map< std::pair< const ClassNameNode *, const ClassNameNode * >, CastFunc > m_mmCast
Definition: class_name_provider.h:236
node for class names
Definition: class_name_provider.h:65
provides the name for a class
Definition: class_name_provider.h:102
static void set_foreward_declared()
sets a temporary name to the class
Definition: class_name_provider_impl.h:176
static const std::string & name()
name of this class
Definition: class_name_provider_impl.h:152
static const ClassNameNode & class_name_node()
return the class name node in the class hierarchy
Definition: class_name_provider.h:136
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
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 * StaticVoidCast(void *DerivVoidPtr)
static cast function for two classes
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