NameTypeBound wsorking (still to refine)
This commit is contained in:
parent
b6cb2fc881
commit
bda10aba6e
|
@ -986,7 +986,7 @@ public:
|
||||||
|
|
||||||
template <class ATTR_TYPE>
|
template <class ATTR_TYPE>
|
||||||
static
|
static
|
||||||
void FixPaddedPerMeshAttribute ( MeshType & /*m*/,PointerToAttribute & pa){
|
void FixPaddedPerMeshAttribute ( MeshType & m,PointerToAttribute & pa){
|
||||||
|
|
||||||
// create the container of the right type
|
// create the container of the right type
|
||||||
Attribute<ATTR_TYPE> * _handle = new Attribute<ATTR_TYPE>();
|
Attribute<ATTR_TYPE> * _handle = new Attribute<ATTR_TYPE>();
|
||||||
|
@ -1016,6 +1016,12 @@ public:
|
||||||
struct NameTypeBound_Base{
|
struct NameTypeBound_Base{
|
||||||
virtual std::string Name() = 0;
|
virtual std::string Name() = 0;
|
||||||
virtual std::string TypeID() = 0;
|
virtual std::string TypeID() = 0;
|
||||||
|
|
||||||
|
virtual void AddPerVertexAttribute(MeshType & m) = 0;
|
||||||
|
virtual void AddPerFaceAttribute(MeshType & m) = 0;
|
||||||
|
virtual void AddPerEdgeAttribute(MeshType & m) = 0;
|
||||||
|
virtual void AddPerMeshAttribute(MeshType & m) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1032,58 +1038,59 @@ public:
|
||||||
std::string Name() {return _name;}
|
std::string Name() {return _name;}
|
||||||
bool operator ==(const NameTypeBound & o ) const {return Name()==o.Name();}
|
bool operator ==(const NameTypeBound & o ) const {return Name()==o.Name();}
|
||||||
|
|
||||||
std::string TypeID(){ return typeid(TYPE).name();}
|
std::string TypeID(){ return typeid(TYPE).name();}
|
||||||
|
|
||||||
void AddPerVertexAttribute(MeshType & m){Allocator::template AddPerVertexAttribute<TYPE> (m,_name);}
|
void AddPerVertexAttribute(MeshType & m){Allocator::AddPerVertexAttribute<TYPE> (m,_name);}
|
||||||
void AddPerFaceAttribute(MeshType & m) {Allocator::template AddPerFaceAttribute<TYPE> (m,_name);}
|
void AddPerFaceAttribute(MeshType & m) {Allocator::AddPerFaceAttribute<TYPE> (m,_name);}
|
||||||
void AddPerEdgeAttribute(MeshType & m) {Allocator::template AddPerEdgeAttribute<TYPE> (m,_name);}
|
void AddPerEdgeAttribute(MeshType & m) {Allocator::AddPerEdgeAttribute<TYPE> (m,_name);}
|
||||||
|
void AddPerMeshAttribute(MeshType & m) {Allocator::AddPerMeshAttribute<TYPE> (m,_name);}
|
||||||
private:
|
private:
|
||||||
std::string _name;
|
std::string _name;
|
||||||
};
|
};
|
||||||
|
|
||||||
// check if a given name has already been bound to a type in the scope passed
|
|
||||||
bool CheckNameIsBound(NameTypeScope binders,std::string name){ return (binders.find(name)!=binders.end()); }
|
bool CheckNameIsBound(NameTypeScope binders,std::string name){ return (binders.find(name)!=binders.end()); }
|
||||||
|
|
||||||
// add a bound name-type to the passed scope
|
|
||||||
template <class TYPE>
|
template <class TYPE>
|
||||||
static void AddNameTypeBound(NameTypeScope binders,std::string name){
|
static void AddNameTypeBound(NameTypeScope & binders,std::string name){
|
||||||
assert(!name.empty()); // you cannot bound a type to an empty string
|
assert(!name.empty()); // you cannot bound a type to an empty string
|
||||||
BindersIterator bi = binders.find(name);
|
BindersIterator bi = binders.find(name);
|
||||||
if(bi!=binders.end())
|
if(bi!=binders.end())
|
||||||
assert(typeid(TYPE).name() == ((*bi).second)->TypeID()); // the name was previously bound to a dirrefent type
|
assert(typeid(TYPE).name() == ((*bi).second)->TypeID()); // the name was previously bound to a dirrefent type
|
||||||
else{
|
else{
|
||||||
NameTypeBound<TYPE> * newbound = new NameTypeBound<TYPE>();
|
NameTypeBound<TYPE> * newbound = new NameTypeBound<TYPE>(name);
|
||||||
binders.insert( TypeBound(name,newbound));
|
binders.insert( TypeBound(name,newbound));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove a previously added name-type bound to the passed scope
|
static void RemoveTypeBind(NameTypeScope binders,std::string name){
|
||||||
void RemoveTypeBind(NameTypeScope binders,std::string name){
|
|
||||||
BindersIterator bi = binders.find(name);
|
BindersIterator bi = binders.find(name);
|
||||||
if(bi!=binders.end()) binders.erase(bi);
|
if(bi!=binders.end()) binders.erase(bi);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add a PerVertexAttribute without knowing its type
|
static void AddPerVertexAttribute(NameTypeScope binders, MeshType & m, std::string name){
|
||||||
void AddPerVertexAttribute(NameTypeScope binders, MeshType & m, std::string name){
|
|
||||||
BindersIterator bi = binders.find(name);
|
BindersIterator bi = binders.find(name);
|
||||||
assert(bi != binders.end() ); // the name MUST have been already bound to a type
|
assert(bi != binders.end() ); // the name MUST have been already bound to a type
|
||||||
(*bi).second->AddPerVertexAttribute(m);
|
(*bi).second->AddPerVertexAttribute(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add a PerEdgeAttribute without knowing its type
|
static void AddPerEdgeAttribute(NameTypeScope binders, MeshType & m, std::string name){
|
||||||
void AddPerEdgeAttribute(NameTypeScope binders, MeshType & m, std::string name){
|
|
||||||
BindersIterator bi = binders.find(name);
|
BindersIterator bi = binders.find(name);
|
||||||
assert(bi != binders.end() ); // the name MUST have been already bound to a type
|
assert(bi != binders.end() ); // the name MUST have been already bound to a type
|
||||||
(*bi).second->AddPerEdgeAttribute(m);
|
(*bi).second->AddPerEdgeAttribute(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
// add a PerFaceAttribute without knowing its type
|
static void AddPerFaceAttribute( NameTypeScope binders,MeshType & m, std::string name){
|
||||||
void AddPerFaceAttribute( NameTypeScope binders,MeshType & m, std::string name){
|
|
||||||
BindersIterator bi = binders.find(name);
|
BindersIterator bi = binders.find(name);
|
||||||
assert(bi != binders.end() ); // the name MUST have been already bound to a type
|
assert(bi != binders.end() ); // the name MUST have been already bound to a type
|
||||||
(*bi).second->AddPerFaceAttribute(m);
|
(*bi).second->AddPerFaceAttribute(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void AddPerMeshAttribute( NameTypeScope binders,MeshType & m, std::string name){
|
||||||
|
BindersIterator bi = binders.find(name);
|
||||||
|
assert(bi != binders.end() ); // the name MUST have been already bound to a type
|
||||||
|
(*bi).second->AddPerMeshAttribute(m);
|
||||||
|
}
|
||||||
|
|
||||||
/* return the name of a previouly bound type */
|
/* return the name of a previouly bound type */
|
||||||
template <typename TYPE>
|
template <typename TYPE>
|
||||||
std::string NameOf(NameTypeScope binders){
|
std::string NameOf(NameTypeScope binders){
|
||||||
|
|
Loading…
Reference in New Issue