[cgma-dev] r3275 - cgm/trunk/itaps

jvporter at wisc.edu jvporter at wisc.edu
Tue Nov 3 13:51:30 CST 2009


Author: jvporter
Date: 2009-11-03 13:51:30 -0600 (Tue, 03 Nov 2009)
New Revision: 3275

Modified:
   cgm/trunk/itaps/CATag.cpp
   cgm/trunk/itaps/iGeom.h
   cgm/trunk/itaps/iGeom_CGMA.cc
Log:
* Make iterators work the same way they do in iMesh (has_data now 
  returns 0 when the iterator was *already* at the end)
* Set *err when getTagHandle fails
* Allow creation of a tag with the same name as one that was previously 
  deleted


Modified: cgm/trunk/itaps/CATag.cpp
===================================================================
--- cgm/trunk/itaps/CATag.cpp	2009-11-03 19:22:32 UTC (rev 3274)
+++ cgm/trunk/itaps/CATag.cpp	2009-11-03 19:51:30 UTC (rev 3275)
@@ -257,24 +257,35 @@
                                           /*out*/ long *tag_handle)
 {
   std::string tmp_name(tag_name);
+  TagInfo tmp_info = {tag_length, tmp_name, tag_type, NULL, true};
+
   std::map<std::string,long>::iterator mit = tagNameMap.find(tmp_name);
   if (mit != tagNameMap.end()) {
+    // we found a tag with this name; is it still active?
+    bool active = (mit->second > 0 ? tagInfo[mit->second] :
+                   presetTagInfo[-mit->second]).isActive;
     *tag_handle = mit->second;
-    iGeom_setLastError( iBase_TAG_ALREADY_EXISTS );
-    return iBase_TAG_ALREADY_EXISTS;
+    if (active) {
+      iGeom_setLastError( iBase_TAG_ALREADY_EXISTS );
+      return iBase_TAG_ALREADY_EXISTS;
+    }
+
+    tagInfo[*tag_handle] = tmp_info;
   }
-    
-  TagInfo tmp_info = {tag_length, std::string(tag_name), tag_type, NULL, true};
-  tagInfo.push_back(tmp_info);
-  *tag_handle = tagInfo.size() - 1;
+  else {
+    // create a new tag entirely
+    tagInfo.push_back(tmp_info);
+    *tag_handle = tagInfo.size() - 1;
+
+    // put the name and handle into the map too
+    tagNameMap[std::string(tag_name)] = *tag_handle;
+  }
+
   if (default_value != NULL) {
     tagInfo[*tag_handle].defaultValue = (char *) malloc(tag_length);
     memcpy(tagInfo[*tag_handle].defaultValue, default_value, tag_length);
   }
 
-    // put the name and handle into the map too
-  tagNameMap[std::string(tag_name)] = *tag_handle;
-
   RETURN(iBase_SUCCESS);
 }
 
@@ -315,14 +326,16 @@
   std::map<std::string,long>::iterator it =
     tagNameMap.find(std::string(tag_name));
   if (it != tagNameMap.end()) {
+    bool active = (it->second > 0 ? tagInfo[it->second] :
+                   presetTagInfo[-it->second]).isActive;
+    if (active) {
       iGeom_clearLastError();
-      return (*it).second;
+      return it->second;
+    }
   }
-  
-  else {
-    iGeom_setLastError( iBase_TAG_NOT_FOUND );
-    return 0;
-  }
+
+  iGeom_setLastError( iBase_TAG_NOT_FOUND );
+  return 0;
 }
 
 int CGMTagManager::getTagType (/*in*/ const long tag_handle) 

Modified: cgm/trunk/itaps/iGeom.h
===================================================================
--- cgm/trunk/itaps/iGeom.h	2009-11-03 19:22:32 UTC (rev 3274)
+++ cgm/trunk/itaps/iGeom.h	2009-11-03 19:51:30 UTC (rev 3275)
@@ -1965,8 +1965,9 @@
      * \param entity_iterator Iterator being queried
      * \param entity_handle Pointer to an entity handle corresponding to the
      *        current value of iterator
-     * \param has_data Pointer to flag; if returned non-zero, next iterator
-     *        has an entity
+     * \param has_data Pointer to a flag indicating if the value returned
+     *        in entity_handle is valid. A non-zero value indicates the value
+     *        is valid. A zero value indicates the value is NOT valid.
      * \param *err Pointer to error type returned from function
      */
   void iGeom_getNextEntIter( iGeom_Instance,
@@ -1989,8 +1990,10 @@
      *        entity_handles array
      * \param *entity_handles_size Pointer to occupied size of entity_handles 
      *        array
-     * \param has_data Pointer to flag; if returned non-zero, next iterator
-     *        has a non-zero number of entities
+     * \param has_data Pointer to a flag indicating if the value(s) returned
+     *        in entity_handles are valid. A non-zero value indicates the 
+     *        value(s) are valid. A zero value indicates the value(s) are NOT
+     *        valid.
      * \param *err Pointer to error type returned from function
      */
   void iGeom_getNextEntArrIter( iGeom_Instance,

Modified: cgm/trunk/itaps/iGeom_CGMA.cc
===================================================================
--- cgm/trunk/itaps/iGeom_CGMA.cc	2009-11-03 19:22:32 UTC (rev 3274)
+++ cgm/trunk/itaps/iGeom_CGMA.cc	2009-11-03 19:51:30 UTC (rev 3275)
@@ -524,7 +524,8 @@
  * Get the next entity for this iterator.
  * @param gentity_iterator Iterator being iterated over
  * @param gentity_handle Next gentity
- * @return If true, there are more gentities, if false, this is the last one
+ * @return If true, there were more gentities, if false, the iterator was
+ *         already at the end.
  */
 void
 iGeom_getNextEntIter (iGeom_Instance instance,
@@ -536,8 +537,12 @@
 {
   CGMAIterator* iterator = reinterpret_cast<CGMAIterator*>(gentity_iterator);
   RefEntity** out_handle = reinterpret_cast<RefEntity**>(gentity_handle);
-  *has_data = 1;
-  iterator->next( out_handle, *has_data );
+  *has_data = !iterator->at_end();
+  if (*has_data) {
+    int count = 1;
+    iterator->next( out_handle, count );
+  }
+  RETURN(iBase_SUCCESS);
 }
 
 
@@ -553,8 +558,10 @@
 {
   CGMAIterator* iterator = reinterpret_cast<CGMAIterator*>(entArr_iterator);
   CHECK_SIZE(*entity_handles, iBase_EntityHandle, iterator->size());
-  iterator->next( (RefEntity**)*entity_handles, *entity_handles_size );
-  *has_data = iterator->at_end();
+  *has_data = !iterator->at_end();
+  if (has_data)
+    iterator->next( (RefEntity**)*entity_handles, *entity_handles_size );
+  RETURN(iBase_SUCCESS);
 }
 
 
@@ -1300,7 +1307,8 @@
   std::string tag_name_buf( tag_name, tag_name_len );
   tag_name = tag_name_buf.c_str();
   *tag_handle = reinterpret_cast<iBase_TagHandle>(static_cast<size_t>(TM->getTagHandle( tag_name )));
-  RETURN(iBase_SUCCESS);
+
+  *err = iGeom_getLastErrorType();
 }
 
 void



More information about the cgma-dev mailing list