cgma
|
00001 //------------------------------------------------------------------------- 00002 // Filename : FacetAttribSet.cpp 00003 // 00004 // Purpose : Common attribute functionality for MBG 00005 // 00006 // Special Notes : 00007 // 00008 // Creator : Jason Kraftcheck 00009 // 00010 // Creation Date : 03/01/03 00011 //------------------------------------------------------------------------- 00012 00013 #include "FacetAttribSet.hpp" 00014 #include "FacetAttrib.hpp" 00015 #include "CubitSimpleAttrib.hpp" 00016 #include "CubitFileIOWrapper.hpp" 00017 00018 void FacetAttribSet::append_attribute( const CubitSimpleAttrib& csa ) 00019 { 00020 FacetAttrib* new_attrib = new FacetAttrib(csa); 00021 new_attrib->listNext = listHead; 00022 listHead = new_attrib; 00023 } 00024 00025 void FacetAttribSet::remove_attribute( const CubitSimpleAttrib& csa ) 00026 { 00027 if( !listHead ) 00028 return; 00029 00030 FacetAttrib* attrib = 0; 00031 if ( listHead->equals(csa) ) 00032 { 00033 attrib = listHead; 00034 listHead = listHead->listNext; 00035 delete attrib; 00036 return; 00037 } 00038 00039 for ( FacetAttrib* prev = listHead; prev->listNext; prev = prev->listNext ) 00040 { 00041 if( prev->listNext->equals(csa) ) 00042 { 00043 attrib = prev->listNext; 00044 prev->listNext = attrib->listNext; 00045 delete attrib; 00046 return; 00047 } 00048 } 00049 } 00050 00051 void FacetAttribSet::remove_all_attributes() 00052 { 00053 while( listHead ) 00054 { 00055 FacetAttrib* dead = listHead; 00056 listHead = dead->listNext; 00057 delete dead; 00058 } 00059 } 00060 00061 CubitStatus FacetAttribSet::get_attributes( DLIList<CubitSimpleAttrib>& list ) const 00062 { 00063 for( FacetAttrib* attrib = listHead; attrib; attrib = attrib->listNext ) 00064 list.append( attrib->get_CSA() ); 00065 return CUBIT_SUCCESS; 00066 } 00067 00068 CubitStatus FacetAttribSet::get_attributes( const CubitString& name, 00069 DLIList<CubitSimpleAttrib>& list ) const 00070 { 00071 for( FacetAttrib* attrib = listHead; attrib; attrib = attrib->listNext ) 00072 if( attrib->name() == name ) 00073 list.append( attrib->get_CSA() ); 00074 return CUBIT_SUCCESS; 00075 } 00076 00077 CubitStatus FacetAttribSet::save_attributes( FILE* file_ptr ) const 00078 { 00079 FacetAttrib *curr_attrib; 00080 CubitStatus status = CUBIT_SUCCESS; 00081 00082 //save # attribs 00083 unsigned int size = attribute_count(); 00084 NCubitFile::CIOWrapper wrapper( file_ptr ); 00085 wrapper.Write( &size, 1 ); 00086 00087 //save each attrib 00088 for( curr_attrib = listHead; curr_attrib; curr_attrib = curr_attrib->listNext ) 00089 if( !curr_attrib->save(file_ptr) ) 00090 status = CUBIT_FAILURE; 00091 00092 return status; 00093 } 00094 00095 CubitStatus FacetAttribSet::restore_attributes( FILE* file_ptr, unsigned endian ) 00096 { 00097 FacetAttrib *curr_attrib; 00098 00099 //Read # attribs 00100 unsigned int size; 00101 NCubitFile::CIOWrapper wrapper( endian, file_ptr ); 00102 wrapper.Read( &size, 1 ); 00103 00104 for (unsigned i = 0; i < size; i++) 00105 { 00106 curr_attrib = FacetAttrib::restore( file_ptr, endian); 00107 if (!curr_attrib) 00108 { 00109 // file corrupt? don't try to read any more 00110 return CUBIT_FAILURE; 00111 } 00112 00113 curr_attrib->listNext = listHead; 00114 listHead = curr_attrib; 00115 } 00116 00117 return CUBIT_SUCCESS; 00118 } 00119 00120 00121 int FacetAttribSet::attribute_count() const 00122 { 00123 int count = 0; 00124 for( FacetAttrib* attrib = listHead; attrib; attrib = attrib->listNext ) 00125 count++; 00126 return count; 00127 } 00128