MeshKit
1.0
|
00001 #ifndef MESHKIT_LOCAL_TAG_HPP 00002 #define MESHKIT_LOCAL_TAG_HPP 00003 00004 #include "meshkit/iMesh.hpp" 00005 #include "meshkit/MKCore.hpp" 00006 #include "meshkit/Error.hpp" 00007 #include <string> 00008 #include <sstream> 00009 00010 namespace MeshKit 00011 { 00012 class LocalTag 00013 { 00014 public: 00015 explicit LocalTag(MKCore *mkCore, int size = 1, 00016 iMesh::TagValueType type = iBase_ENTITY_HANDLE) 00017 : imesh_(mkCore->imesh_instance()->instance()) 00018 { 00019 #ifdef MOAB 00020 init("", size, type); 00021 #else 00022 init("local_tag", size, type); 00023 #endif 00024 } 00025 00026 LocalTag(MKCore *mkCore, const std::string &name, int size = 1, 00027 iMesh::TagValueType type = iBase_ENTITY_HANDLE) 00028 : imesh_(mkCore->imesh_instance()->instance()) 00029 { 00030 init(name, size, type); 00031 } 00032 00033 ~LocalTag() 00034 { 00035 imesh_.destroyTag(tag_handle_, true); 00036 } 00037 00038 operator iMesh::TagHandle() 00039 { 00040 return tag_handle_; 00041 } 00042 00043 private: 00044 void init(const std::string &name, int size, iMesh::TagValueType type) 00045 { 00046 iMesh::Error err; 00047 err = imesh_.createTag(name.c_str(), size, type, tag_handle_); 00048 00049 for (int i=0; err == iBase_TAG_ALREADY_EXISTS; i++) { 00050 std::ostringstream os; 00051 os << name << i; 00052 std::string tag_name = os.str(); 00053 err = imesh_.createTag(tag_name.c_str(), size, type, tag_handle_); 00054 } 00055 00056 IBERRCHK(err, "FIXME"); 00057 } 00058 00059 iMesh imesh_; 00060 iMesh::TagHandle tag_handle_; 00061 }; 00062 } 00063 00064 #endif