Changeset 3275 for cgm/trunk

Show
Ignore:
Timestamp:
11/03/09 13:51:30 (3 weeks ago)
Author:
jvporter
Message:

* 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

Location:
cgm/trunk/itaps
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • cgm/trunk/itaps/CATag.cpp

    r3166 r3275  
    258258{ 
    259259  std::string tmp_name(tag_name); 
     260  TagInfo tmp_info = {tag_length, tmp_name, tag_type, NULL, true}; 
     261 
    260262  std::map<std::string,long>::iterator mit = tagNameMap.find(tmp_name); 
    261263  if (mit != tagNameMap.end()) { 
     264    // we found a tag with this name; is it still active? 
     265    bool active = (mit->second > 0 ? tagInfo[mit->second] : 
     266                   presetTagInfo[-mit->second]).isActive; 
    262267    *tag_handle = mit->second; 
    263     iGeom_setLastError( iBase_TAG_ALREADY_EXISTS ); 
    264     return iBase_TAG_ALREADY_EXISTS; 
    265   } 
    266      
    267   TagInfo tmp_info = {tag_length, std::string(tag_name), tag_type, NULL, true}; 
    268   tagInfo.push_back(tmp_info); 
    269   *tag_handle = tagInfo.size() - 1; 
     268    if (active) { 
     269      iGeom_setLastError( iBase_TAG_ALREADY_EXISTS ); 
     270      return iBase_TAG_ALREADY_EXISTS; 
     271    } 
     272 
     273    tagInfo[*tag_handle] = tmp_info; 
     274  } 
     275  else { 
     276    // create a new tag entirely 
     277    tagInfo.push_back(tmp_info); 
     278    *tag_handle = tagInfo.size() - 1; 
     279 
     280    // put the name and handle into the map too 
     281    tagNameMap[std::string(tag_name)] = *tag_handle; 
     282  } 
     283 
    270284  if (default_value != NULL) { 
    271285    tagInfo[*tag_handle].defaultValue = (char *) malloc(tag_length); 
    272286    memcpy(tagInfo[*tag_handle].defaultValue, default_value, tag_length); 
    273287  } 
    274  
    275     // put the name and handle into the map too 
    276   tagNameMap[std::string(tag_name)] = *tag_handle; 
    277288 
    278289  RETURN(iBase_SUCCESS); 
     
    316327    tagNameMap.find(std::string(tag_name)); 
    317328  if (it != tagNameMap.end()) { 
     329    bool active = (it->second > 0 ? tagInfo[it->second] : 
     330                   presetTagInfo[-it->second]).isActive; 
     331    if (active) { 
    318332      iGeom_clearLastError(); 
    319       return (*it).second; 
    320   } 
    321    
    322   else { 
    323     iGeom_setLastError( iBase_TAG_NOT_FOUND ); 
    324     return 0; 
    325   } 
     333      return it->second; 
     334    } 
     335  } 
     336 
     337  iGeom_setLastError( iBase_TAG_NOT_FOUND ); 
     338  return 0; 
    326339} 
    327340 
  • cgm/trunk/itaps/iGeom.h

    r3163 r3275  
    19661966     * \param entity_handle Pointer to an entity handle corresponding to the 
    19671967     *        current value of iterator 
    1968      * \param has_data Pointer to flag; if returned non-zero, next iterator 
    1969      *        has an entity 
     1968     * \param has_data Pointer to a flag indicating if the value returned 
     1969     *        in entity_handle is valid. A non-zero value indicates the value 
     1970     *        is valid. A zero value indicates the value is NOT valid. 
    19701971     * \param *err Pointer to error type returned from function 
    19711972     */ 
     
    19901991     * \param *entity_handles_size Pointer to occupied size of entity_handles  
    19911992     *        array 
    1992      * \param has_data Pointer to flag; if returned non-zero, next iterator 
    1993      *        has a non-zero number of entities 
     1993     * \param has_data Pointer to a flag indicating if the value(s) returned 
     1994     *        in entity_handles are valid. A non-zero value indicates the  
     1995     *        value(s) are valid. A zero value indicates the value(s) are NOT 
     1996     *        valid. 
    19941997     * \param *err Pointer to error type returned from function 
    19951998     */ 
  • cgm/trunk/itaps/iGeom_CGMA.cc

    r3270 r3275  
    525525 * @param gentity_iterator Iterator being iterated over 
    526526 * @param gentity_handle Next gentity 
    527  * @return If true, there are more gentities, if false, this is the last one 
     527 * @return If true, there were more gentities, if false, the iterator was 
     528 *         already at the end. 
    528529 */ 
    529530void 
     
    537538  CGMAIterator* iterator = reinterpret_cast<CGMAIterator*>(gentity_iterator); 
    538539  RefEntity** out_handle = reinterpret_cast<RefEntity**>(gentity_handle); 
    539   *has_data = 1; 
    540   iterator->next( out_handle, *has_data ); 
     540  *has_data = !iterator->at_end(); 
     541  if (*has_data) { 
     542    int count = 1; 
     543    iterator->next( out_handle, count ); 
     544  } 
     545  RETURN(iBase_SUCCESS); 
    541546} 
    542547 
     
    554559  CGMAIterator* iterator = reinterpret_cast<CGMAIterator*>(entArr_iterator); 
    555560  CHECK_SIZE(*entity_handles, iBase_EntityHandle, iterator->size()); 
    556   iterator->next( (RefEntity**)*entity_handles, *entity_handles_size ); 
    557   *has_data = iterator->at_end(); 
     561  *has_data = !iterator->at_end(); 
     562  if (has_data) 
     563    iterator->next( (RefEntity**)*entity_handles, *entity_handles_size ); 
     564  RETURN(iBase_SUCCESS); 
    558565} 
    559566 
     
    13011308  tag_name = tag_name_buf.c_str(); 
    13021309  *tag_handle = reinterpret_cast<iBase_TagHandle>(static_cast<size_t>(TM->getTagHandle( tag_name ))); 
    1303   RETURN(iBase_SUCCESS); 
     1310 
     1311  *err = iGeom_getLastErrorType(); 
    13041312} 
    13051313