lasso
FBGeomAssocPairSide.cpp
Go to the documentation of this file.
00001 #include "FBGeomAssocPairSide.hpp"
00002 
00003 #include <cstring>
00004 #include <sstream>
00005 #include <string>
00006 
00007 #include "Lasso.hpp"
00008 #include "iRel_Lasso.hpp"
00009 
00010 #define PROCESS_ERROR do {                                \
00011     if (iBase_SUCCESS != result) {                        \
00012       char this_descr[120];                               \
00013       FBiGeom_getDescription(instance_, this_descr, 120); \
00014       ERRORR(result, this_descr);                         \
00015     }                                                     \
00016   } while(false)
00017 
00018 // Redefine LASSOI
00019 #undef LASSOI
00020 #define LASSOI lasso_instance(relation)
00021 
00022 static const char *GLOBAL_ID_TAG_NAME = "GLOBAL_ID";
00023 static const char *RELATION_TAG_NAME = "__FBGEOM_ASSOCIATION";
00024 
00025 FBGeomAssocPairSide::FBGeomAssocPairSide(iRel_Instance relation,
00026                                          iBase_Instance instance, int id) :
00027   relation(relation),
00028   instance_(reinterpret_cast<FBiGeom_Instance>(instance)),
00029   id(id)
00030 {
00031   int result;
00032 
00033   create_relation_side();
00034 
00035   FBiGeom_getTagHandle(instance_, GLOBAL_ID_TAG_NAME, &gid_tag, &result,
00036                        strlen(GLOBAL_ID_TAG_NAME));
00037   if (result == iBase_TAG_NOT_FOUND) {
00038     FBiGeom_createTag(instance_, GLOBAL_ID_TAG_NAME, 1, iBase_INTEGER,
00039                       &gid_tag, &result, strlen(GLOBAL_ID_TAG_NAME));
00040   }
00041 }
00042 
00043 FBGeomAssocPairSide::~FBGeomAssocPairSide()
00044 {
00045   destroy_relation_side();
00046 }
00047 
00048 iBase_Instance FBGeomAssocPairSide::instance() const
00049 {
00050   return instance_;
00051 }
00052 
00053 iRel_IfaceType FBGeomAssocPairSide::type() const
00054 {
00055   return iRel_FBIGEOM_IFACE;
00056 }
00057 
00058 int FBGeomAssocPairSide::create_relation_side()
00059 {
00060   int result;
00061   std::stringstream ss;
00062   ss << RELATION_TAG_NAME << id;
00063   std::string rel_tag_name(ss.str());
00064 
00065   FBiGeom_getTagHandle(instance_, rel_tag_name.c_str(), &relation_tag, &result,
00066                        rel_tag_name.size());
00067   if (result == iBase_TAG_NOT_FOUND) {
00068     FBiGeom_createTag(instance_, rel_tag_name.c_str(), 1, iBase_ENTITY_HANDLE,
00069                       &relation_tag, &result, rel_tag_name.size());
00070   }
00071 
00072   PROCESS_ERROR;
00073   RETURNR(iBase_SUCCESS);
00074 }
00075 
00076 int FBGeomAssocPairSide::destroy_relation_side()
00077 {
00078   if (relation_tag) {
00079     int result;
00080 
00081     FBiGeom_destroyTag(instance_, relation_tag, true, &result);
00082     relation_tag = NULL;
00083 
00084     PROCESS_ERROR;
00085   }
00086   RETURNR(iBase_SUCCESS);
00087 }
00088 
00089 int FBGeomAssocPairSide::get_all_entities(int dimension,
00090                                           iBase_EntityHandle **entities,
00091                                           int *entities_alloc,
00092                                           int *entities_size)
00093 {
00094   int this_type = (dimension == -1 ? iBase_ALL_TYPES : dimension);
00095   int result;
00096 
00097   FBiGeom_getEntities(instance_, 0, this_type, entities, entities_alloc,
00098                       entities_size, &result);
00099   PROCESS_ERROR;
00100   RETURNR(iBase_SUCCESS);
00101 }
00102 
00103 int FBGeomAssocPairSide::get_all_sets(iBase_EntitySetHandle **sets,
00104                                       int *sets_alloc, int *sets_size)
00105 {
00106   int result;
00107 
00108   FBiGeom_getEntSets(instance_, 0, 0, sets, sets_alloc, sets_size, &result);
00109   PROCESS_ERROR;
00110   RETURNR(iBase_SUCCESS);
00111 }
00112 
00113 int FBGeomAssocPairSide::get_entities(int dimension,
00114                                       iBase_EntitySetHandle set_handle,
00115                                       iBase_EntityHandle **entities,
00116                                       int *entities_alloc,
00117                                       int *entities_size)
00118 {
00119   int this_type = (dimension == -1 ? iBase_ALL_TYPES : dimension);
00120   int result;
00121 
00122   FBiGeom_getEntities(instance_, set_handle, this_type, entities,
00123                       entities_alloc, entities_size, &result);
00124   PROCESS_ERROR;
00125   RETURNR(iBase_SUCCESS);
00126 }
00127 
00128 int FBGeomAssocPairSide::get_ents_dims(iBase_EntityHandle *entities,
00129                                      int entities_size,
00130                                      int **ent_types,
00131                                      int *ent_types_alloc,
00132                                      int *ent_types_size)
00133 {
00134   int result;
00135 
00136   FBiGeom_getArrType(instance_, entities, entities_size, ent_types,
00137                      ent_types_alloc, ent_types_size, &result);
00138   PROCESS_ERROR;
00139   RETURNR(iBase_SUCCESS);
00140 }
00141 
00142 int FBGeomAssocPairSide::get_related_ents(iBase_EntityHandle **entities,
00143                                           int *entities_alloc,
00144                                           int *entities_size)
00145 {
00146   RETURNR(iBase_FAILURE);
00147 }
00148 
00149 int FBGeomAssocPairSide::get_related_sets(iBase_EntitySetHandle **sets,
00150                                           int *sets_alloc, int *sets_size)
00151 {
00152   RETURNR(iBase_FAILURE);
00153 }
00154 
00155 int FBGeomAssocPairSide::get_relation_side(iBase_EntityHandle *entities,
00156                                            int num_entities, void *values)
00157 {
00158   int values_alloc = num_entities * sizeof(iBase_EntityHandle);
00159   int values_size;
00160   int result;
00161 
00162   FBiGeom_getArrData(instance_, entities, num_entities, relation_tag,
00163                      &values, &values_alloc, &values_size, &result);
00164   PROCESS_ERROR;
00165   RETURNR(iBase_SUCCESS);
00166 }
00167 
00168 int FBGeomAssocPairSide::get_relation_side(iBase_EntitySetHandle *sets, 
00169                                            int num_sets, void *values)
00170 {
00171   char *data = static_cast<char*>(values);
00172   int values_alloc = sizeof(iBase_EntityHandle);
00173   int values_size;
00174   int result;
00175 
00176   for (int i = 0; i < num_sets; i++) {
00177     FBiGeom_getEntSetData(instance_, sets[i], relation_tag,
00178                           reinterpret_cast<void**>(&data),
00179                           &values_alloc, &values_size, &result);
00180     data += values_size;
00181     PROCESS_ERROR;
00182   }
00183   RETURNR(iBase_SUCCESS);
00184 }
00185 
00186 int FBGeomAssocPairSide::set_relation_side(iBase_EntityHandle *entities,
00187                                            int num_entities, const void *values)
00188 {
00189   int result;
00190 
00191   FBiGeom_setArrData(instance_, entities, num_entities, relation_tag,
00192                      static_cast<const char*>(values),
00193                      num_entities*sizeof(iBase_EntityHandle), &result);
00194   PROCESS_ERROR;
00195   RETURNR(iBase_SUCCESS);
00196 }
00197 
00198 int FBGeomAssocPairSide::set_relation_side(iBase_EntitySetHandle *sets,
00199                                            int num_sets, const void *values)
00200 {
00201   const char *data = static_cast<const char*>(values);
00202   int size = sizeof(iBase_EntityHandle);
00203   int result;
00204 
00205   for (int i = 0; i < num_sets; i++) {
00206     FBiGeom_setEntSetData(instance_, sets[i], relation_tag, data, size,
00207                           &result);
00208     data += size;
00209     PROCESS_ERROR;
00210   }
00211   RETURNR(iBase_SUCCESS);
00212 }
00213 
00214 int FBGeomAssocPairSide::rmv_relation_side(iBase_EntityHandle *entities,
00215                                          int num_entities)
00216 {
00217   int result;
00218 
00219   FBiGeom_rmvArrTag(instance_, entities, num_entities, relation_tag, &result);
00220   PROCESS_ERROR;
00221   RETURNR(iBase_SUCCESS);
00222 }
00223 
00224 int FBGeomAssocPairSide::rmv_relation_side(iBase_EntitySetHandle *sets,
00225                                            int num_sets)
00226 {
00227   int result;
00228 
00229   for (int i = 0; i < num_sets; i++) {
00230     FBiGeom_rmvEntSetTag(instance_, sets[i], relation_tag, &result);
00231     PROCESS_ERROR;
00232   }
00233 
00234   RETURNR(iBase_SUCCESS);
00235 }
00236 
00237 int FBGeomAssocPairSide::get_iterator(iBase_EntitySetHandle set,
00238                                       iBase_EntityIterator *iter)
00239 {
00240   int result;
00241   FBiGeom_initEntIter(instance_, set, iBase_ALL_TYPES, iter, &result);
00242   RETURNR(iBase_SUCCESS);
00243 }
00244 
00245 int FBGeomAssocPairSide::get_gids(iBase_EntityHandle *entities,
00246                                   int num_entities, int *values)
00247 {
00248   int values_alloc = num_entities * sizeof(int);
00249   int values_size;
00250   int result;
00251 
00252   FBiGeom_getArrData(instance_, entities, num_entities, gid_tag,
00253                      reinterpret_cast<void**>(&values), &values_alloc,
00254                      &values_size, &result);
00255   PROCESS_ERROR;
00256   RETURNR(iBase_SUCCESS);
00257 }
00258 
00259 int FBGeomAssocPairSide::get_gids(iBase_EntitySetHandle *sets, int num_sets,
00260                                   int *values)
00261 {
00262   char *data = reinterpret_cast<char*>(values);
00263   int values_alloc = sizeof(int);
00264   int values_size;
00265   int result;
00266 
00267   for (int i = 0; i < num_sets; i++) {
00268     FBiGeom_getEntSetData(instance_, sets[i], gid_tag,
00269                           reinterpret_cast<void**>(&data),
00270                           &values_alloc, &values_size, &result);
00271     data += values_size;
00272     PROCESS_ERROR;
00273   }
00274   RETURNR(iBase_SUCCESS);
00275 }
00276 
00277 int FBGeomAssocPairSide::get_dims(iBase_EntityHandle *entities,
00278                                   int num_entities, int *values)
00279 {
00280   RETURNR(iBase_FAILURE);
00281 }
00282 
00283 int FBGeomAssocPairSide::get_dims(iBase_EntitySetHandle *sets, int num_sets,
00284                                   int *values)
00285 {
00286   RETURNR(iBase_FAILURE);
00287 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines