diff --git a/vcg/complex/trimesh/allocate.h b/vcg/complex/trimesh/allocate.h index 2a345259..6f548897 100644 --- a/vcg/complex/trimesh/allocate.h +++ b/vcg/complex/trimesh/allocate.h @@ -1026,6 +1026,7 @@ public: typedef typename std::map::iterator BindersIterator; + typedef typename std::map::const_iterator CBindersIterator; typedef std::pair TypeBound; typedef std::map NameTypeScope; @@ -1048,7 +1049,7 @@ public: std::string _name; }; - bool CheckNameIsBound(NameTypeScope binders,std::string name){ return (binders.find(name)!=binders.end()); } + static bool CheckNameIsBound(const NameTypeScope & binders,std::string name){ return (binders.find(name)!=binders.end()); } template static void AddNameTypeBound(NameTypeScope & binders,std::string name){ @@ -1062,45 +1063,47 @@ public: } } - static void RemoveTypeBind(NameTypeScope binders,std::string name){ + static void RemoveTypeBound( NameTypeScope& binders,std::string name){ BindersIterator bi = binders.find(name); - if(bi!=binders.end()) binders.erase(bi); + if(bi!=binders.end()) {delete(*bi).second; binders.erase(bi);} } - static void AddPerVertexAttribute(NameTypeScope binders, MeshType & m, std::string name){ + /* return the name of all the attributes of a given type */ + template + static std::vector NamesWithType(const NameTypeScope & binders){ + std::vector res; + CBindersIterator bi; + for(bi = binders.begin(); bi != binders.end(); ++bi) + if (typeid(TYPE).name() == ((*bi).second->TypeID())) + res.push_back( (*bi).second->Name()); + return res; + } + + static void AddPerVertexAttribute(const 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); } - static void AddPerEdgeAttribute(NameTypeScope binders, MeshType & m, std::string name){ + static void AddPerEdgeAttribute(const 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); } - static void AddPerFaceAttribute( NameTypeScope binders,MeshType & m, std::string name){ + static void AddPerFaceAttribute(const 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); + static void AddPerMeshAttribute( const NameTypeScope & binders,MeshType & m, std::string name){ + CBindersIterator 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){ - TYPE t; - BindersIterator bi; - for(bi = binders.begin(); bi != binders.end(); ++bi) - if (typdeid(t).name() == ((*bi).second->TypeID())) - return (*bi).second->Name(); - return std::string(""); - } + }; // end class