From bda10aba6e96a89a3bfc2210d668ebc1ca91ed34 Mon Sep 17 00:00:00 2001 From: ganovelli Date: Tue, 23 Mar 2010 09:25:13 +0000 Subject: [PATCH] NameTypeBound wsorking (still to refine) --- vcg/complex/trimesh/allocate.h | 43 ++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/vcg/complex/trimesh/allocate.h b/vcg/complex/trimesh/allocate.h index a5382d13..2a345259 100644 --- a/vcg/complex/trimesh/allocate.h +++ b/vcg/complex/trimesh/allocate.h @@ -986,7 +986,7 @@ public: template static - void FixPaddedPerMeshAttribute ( MeshType & /*m*/,PointerToAttribute & pa){ + void FixPaddedPerMeshAttribute ( MeshType & m,PointerToAttribute & pa){ // create the container of the right type Attribute * _handle = new Attribute(); @@ -1016,6 +1016,12 @@ public: struct NameTypeBound_Base{ virtual std::string Name() = 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;} 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 (m,_name);} - void AddPerFaceAttribute(MeshType & m) {Allocator::template AddPerFaceAttribute (m,_name);} - void AddPerEdgeAttribute(MeshType & m) {Allocator::template AddPerEdgeAttribute (m,_name);} + void AddPerVertexAttribute(MeshType & m){Allocator::AddPerVertexAttribute (m,_name);} + void AddPerFaceAttribute(MeshType & m) {Allocator::AddPerFaceAttribute (m,_name);} + void AddPerEdgeAttribute(MeshType & m) {Allocator::AddPerEdgeAttribute (m,_name);} + void AddPerMeshAttribute(MeshType & m) {Allocator::AddPerMeshAttribute (m,_name);} private: 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()); } - // add a bound name-type to the passed scope template - 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 BindersIterator bi = binders.find(name); 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{ - NameTypeBound * newbound = new NameTypeBound(); + NameTypeBound * newbound = new NameTypeBound(name); binders.insert( TypeBound(name,newbound)); } } - // remove a previously added name-type bound to the passed scope - void RemoveTypeBind(NameTypeScope binders,std::string name){ + static void RemoveTypeBind(NameTypeScope binders,std::string name){ BindersIterator bi = binders.find(name); if(bi!=binders.end()) binders.erase(bi); } - // add a PerVertexAttribute without knowing its type - void AddPerVertexAttribute(NameTypeScope binders, MeshType & m, std::string name){ + static void AddPerVertexAttribute(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->AddPerVertexAttribute(m); } - // add a PerEdgeAttribute without knowing its type - void AddPerEdgeAttribute(NameTypeScope binders, MeshType & m, std::string name){ + static void AddPerEdgeAttribute(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->AddPerEdgeAttribute(m); } - // add a PerFaceAttribute without knowing its type - void AddPerFaceAttribute( NameTypeScope binders,MeshType & m, std::string name){ + static void AddPerFaceAttribute( 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->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 */ template std::string NameOf(NameTypeScope binders){