factorized a bit the attribute classes in TriMesh;

added to IsValidHandle the check that pointer to data is not null.
Explanation:
a handle may be not valid for two reasons:
1) the attribute has been destroyed with a DeletePer*Attribute
2) the handle has been declared but not initialized.
The change is to cover the case 2)
This commit is contained in:
ganovelli 2009-06-04 16:08:15 +00:00
parent 69004410e3
commit 66ec7652dc
1 changed files with 20 additions and 33 deletions

View File

@ -252,52 +252,39 @@ class TriMesh: public TriMeshEdgeHolder<VertContainerType,FaceContainerType,Edge
std::set< HandlesWrapper > face_attr; std::set< HandlesWrapper > face_attr;
std::set< HandlesWrapper > mesh_attr; std::set< HandlesWrapper > mesh_attr;
template <class ATTR_TYPE>
class PerVertexAttributeHandle{ template <class ATTR_TYPE, class CONT>
class AttributeHandle{
public: public:
PerVertexAttributeHandle(){_handle=(SimpleTempData<VertContainer,ATTR_TYPE> *)NULL;} AttributeHandle(){_handle=(SimpleTempData<CONT,ATTR_TYPE> *)NULL;}
PerVertexAttributeHandle( void *ah,const int & n):_handle ( (SimpleTempData<VertContainer,ATTR_TYPE> *)ah ),n_attr(n){} AttributeHandle( void *ah,const int & n):_handle ( (SimpleTempData<CONT,ATTR_TYPE> *)ah ),n_attr(n){}
PerVertexAttributeHandle operator = ( const PerVertexAttributeHandle & pva){ AttributeHandle operator = ( const CONT & pva){
_handle = (SimpleTempData<VertContainer,ATTR_TYPE> *)pva._handle; _handle = (SimpleTempData<CONT,ATTR_TYPE> *)pva._handle;
n_attr = pva.n_attr; n_attr = pva.n_attr;
return (*this); return (*this);
} }
SimpleTempData<VertContainer,ATTR_TYPE> * _handle; SimpleTempData<CONT,ATTR_TYPE> * _handle;
int n_attr; // its attribute number int n_attr; // its attribute number
template <class RefType> template <class RefType>
ATTR_TYPE & operator [](const RefType & i){return (*_handle)[i];} ATTR_TYPE & operator [](const RefType & i){return (*_handle)[i];}
}; };
template <class ATTR_TYPE> template <class ATTR_TYPE>
class PerFaceAttributeHandle{ class PerVertexAttributeHandle: public AttributeHandle<ATTR_TYPE,VertContainer>{
public: PerVertexAttributeHandle():AttributeHandle<ATTR_TYPE,VertContainer>(){}
PerFaceAttributeHandle(){_handle=NULL;} public: PerVertexAttributeHandle( void *ah,const int & n):AttributeHandle(ah,n){};
PerFaceAttributeHandle(void *ah,const int & n):_handle ( (SimpleTempData<FaceContainer,ATTR_TYPE> *)ah ),n_attr(n){}
PerFaceAttributeHandle operator = ( const PerFaceAttributeHandle & pva){
_handle = (SimpleTempData<FaceContainer,ATTR_TYPE> *)pva._handle;
n_attr = pva.n_attr;
return (*this);
}
SimpleTempData<FaceContainer,ATTR_TYPE> * _handle;
int n_attr; // its attribute number
template <class RefType>
ATTR_TYPE & operator [](const RefType & i){return (*_handle)[i];}
}; };
template <class ATTR_TYPE> template <class ATTR_TYPE>
class PerEdgeAttributeHandle{ class PerFaceAttributeHandle: public AttributeHandle<ATTR_TYPE,FaceContainer>{
public: PerFaceAttributeHandle():AttributeHandle<ATTR_TYPE,FaceContainer>(){}
PerEdgeAttributeHandle(){_handle=NULL;} public: PerFaceAttributeHandle( void *ah,const int & n):AttributeHandle(ah,n){};
PerEdgeAttributeHandle(void *ah,const int & n):_handle ( (SimpleTempData<EdgeContainer,ATTR_TYPE> *)ah ),n_attr(n){} };
PerEdgeAttributeHandle operator = ( const PerEdgeAttributeHandle & pva){
_handle = (SimpleTempData<EdgeContainer,ATTR_TYPE> *)pva._handle; template <class ATTR_TYPE>
n_attr = pva.n_attr; class PerEdgeAttributeHandle: public AttributeHandle<ATTR_TYPE,EdgeContainer>{
return (*this); PerEdgeAttributeHandle():AttributeHandle<ATTR_TYPE,EdgeContainer>(){}
} public: PerEdgeAttributeHandle( void *ah,const int & n):AttributeHandle(ah,n){};
SimpleTempData<EdgeContainer,ATTR_TYPE> * _handle;
int n_attr; // its attribute number
template <class RefType>
ATTR_TYPE & operator [](const RefType & i){return (*(SimpleTempData<EdgeContainer,ATTR_TYPE>*)_handle)[i];}
}; };
template <class ATTR_TYPE> template <class ATTR_TYPE>