MeshKit
1.0
|
00001 #include "MeshOpSet.hpp" 00002 #include "meshkit/MeshOpProxy.hpp" 00003 #include "meshkit/Error.hpp" 00004 #include <string> 00005 00006 namespace MeshKit { 00007 00008 MeshOpSet::MeshOpSet() {} 00009 00010 MeshOpSet& MeshOpSet::instance() 00011 { 00012 static MeshOpSet singleton; 00013 return singleton; 00014 } 00015 00016 void MeshOpSet::register_mesh_op( MeshOpProxy* proxy ) 00017 { 00018 // Check if a MeshOp with the same name is already registered 00019 iterator other = mesh_op_no_throw( proxy->name() ); 00020 if (other != allMeshOps.end()) { 00021 if (*other == proxy) 00022 return; 00023 else 00024 throw Error(MK_MULTIPLE_FOUND,"Conflicting MeshOp name: \"%s\"", proxy->name()); 00025 } 00026 00027 // Try to detect unterminated output entity lists 00028 const moab::EntityType* types = proxy->output_types(); 00029 for (int i = 0; types[i] != moab::MBMAXTYPE; ++i) 00030 if (i >= moab::MBMAXTYPE) 00031 throw Error(MK_BAD_INPUT,"Unterminated output type list for MeshOp: \"%s\"", proxy->name()); 00032 00033 // Add to list of all MeshOps 00034 allMeshOps.push_back(proxy); 00035 00036 // Add to list for each dimension that it can mesh 00037 for (int i = 0; i < 4; ++i) 00038 if (proxy->can_mesh(static_cast<iBase_EntityType>(i))) 00039 dimMeshOps[i].push_back(proxy); 00040 } 00041 00042 MeshOpSet::iterator MeshOpSet::mesh_op_no_throw( const char* op_name ) const 00043 { 00044 std::string search(op_name); 00045 for (iterator i = allMeshOps.begin(); i != allMeshOps.end(); ++i) 00046 if (search == (*i)->name()) 00047 return i; 00048 return allMeshOps.end(); 00049 } 00050 00051 MeshOpProxy* MeshOpSet::mesh_op( const char* op_name ) const 00052 { 00053 iterator i = mesh_op_no_throw( op_name ); 00054 if (i == allMeshOps.end()) 00055 throw Error(MK_NOT_FOUND,"Invalid MeshOp name: \"%s\"", op_name); 00056 return *i; 00057 } 00058 00059 unsigned MeshOpSet::index( const char* op_name ) const 00060 { 00061 iterator i = mesh_op_no_throw( op_name ); 00062 if (i == allMeshOps.end()) 00063 throw Error(MK_NOT_FOUND,"Invalid MeshOp name: \"%s\"", op_name); 00064 return i - allMeshOps.begin(); 00065 } 00066 00067 MeshOpProxy* MeshOpSet::mesh_op( unsigned index ) const 00068 { 00069 if (index >= allMeshOps.size()) 00070 new Error(MK_NOT_FOUND,"Invalid MeshOp index: %u", index); 00071 00072 return allMeshOps[index]; 00073 } 00074 00075 } // namespace MeshKit