|
| 1 | +#include "STEPaggrEntity.h" |
| 2 | + |
| 3 | +/** \file STEPaggrEntity.cc |
| 4 | + * implement classes EntityAggregate, EntityNode |
| 5 | + */ |
| 6 | + |
| 7 | + |
| 8 | +EntityAggregate::EntityAggregate() { |
| 9 | +} |
| 10 | + |
| 11 | +EntityAggregate::~EntityAggregate() { |
| 12 | +} |
| 13 | + |
| 14 | + |
| 15 | +/// if exchangeFileFormat == 1 then delims are required. |
| 16 | +Severity EntityAggregate::ReadValue( istream & in, ErrorDescriptor * err, |
| 17 | + const TypeDescriptor * elem_type, InstMgrBase * insts, |
| 18 | + int addFileId, int assignVal, |
| 19 | + int exchangeFileFormat, const char * ) { |
| 20 | + ErrorDescriptor errdesc; |
| 21 | + char errmsg[BUFSIZ]; |
| 22 | + int value_cnt = 0; |
| 23 | + std::string buf; |
| 24 | + |
| 25 | + if( assignVal ) { |
| 26 | + Empty(); // read new values and discard existing ones |
| 27 | + } |
| 28 | + |
| 29 | + char c; |
| 30 | + |
| 31 | + in >> ws; // skip white space |
| 32 | + |
| 33 | + c = in.peek(); // does not advance input |
| 34 | + |
| 35 | + if( in.eof() || ( c == '$' ) ) { |
| 36 | + _null = 1; |
| 37 | + err->GreaterSeverity( SEVERITY_INCOMPLETE ); |
| 38 | + return SEVERITY_INCOMPLETE; |
| 39 | + } |
| 40 | + |
| 41 | + if( c == '(' ) { |
| 42 | + in.get( c ); |
| 43 | + } else if( exchangeFileFormat ) { |
| 44 | + // error did not find opening delim |
| 45 | + // give up because you do not know where to stop reading. |
| 46 | + err->GreaterSeverity( SEVERITY_INPUT_ERROR ); |
| 47 | + return SEVERITY_INPUT_ERROR; |
| 48 | + } else if( !in.good() ) { |
| 49 | + // this should actually have been caught by skipping white space above |
| 50 | + err->GreaterSeverity( SEVERITY_INCOMPLETE ); |
| 51 | + return SEVERITY_INCOMPLETE; |
| 52 | + } |
| 53 | + |
| 54 | + EntityNode * item = 0; |
| 55 | + |
| 56 | + in >> ws; |
| 57 | + // take a peek to see if there are any elements before committing to an |
| 58 | + // element |
| 59 | + c = in.peek(); // does not advance input |
| 60 | + if( c == ')' ) { |
| 61 | + in.get( c ); |
| 62 | + } |
| 63 | + // if not assigning values only need one node. So only one node is created. |
| 64 | + // It is used to read the values |
| 65 | + else if( !assignVal ) { |
| 66 | + item = new EntityNode(); |
| 67 | + } |
| 68 | + |
| 69 | + while( in.good() && ( c != ')' ) ) { |
| 70 | + value_cnt++; |
| 71 | + if( assignVal ) { // create a new node each time through the loop |
| 72 | + item = new EntityNode(); |
| 73 | + } |
| 74 | + |
| 75 | + errdesc.ClearErrorMsg(); |
| 76 | + |
| 77 | + if( exchangeFileFormat ) { |
| 78 | + item->STEPread( in, &errdesc, elem_type, insts, addFileId ); |
| 79 | + } else { |
| 80 | + item->StrToVal( in, &errdesc, elem_type, insts, addFileId ); |
| 81 | + } |
| 82 | + |
| 83 | + // read up to the next delimiter and set errors if garbage is |
| 84 | + // found before specified delims (i.e. comma and quote) |
| 85 | + CheckRemainingInput( in, &errdesc, elem_type->AttrTypeName( buf ), ",)" ); |
| 86 | + |
| 87 | + if( errdesc.severity() < SEVERITY_INCOMPLETE ) { |
| 88 | + sprintf( errmsg, " index: %d\n", value_cnt ); |
| 89 | + errdesc.PrependToDetailMsg( errmsg ); |
| 90 | + err->AppendFromErrorArg( &errdesc ); |
| 91 | + } |
| 92 | + if( assignVal ) { |
| 93 | + AddNode( item ); |
| 94 | + } |
| 95 | + |
| 96 | + in >> ws; // skip white space (although should already be skipped) |
| 97 | + in.get( c ); // read delim |
| 98 | + |
| 99 | + // CheckRemainingInput should have left the input right at the delim |
| 100 | + // so that it would be read in in.get() above. Since it did not find |
| 101 | + // the delim this does not know how to find it either! |
| 102 | + if( ( c != ',' ) && ( c != ')' ) ) { |
| 103 | + // cannot recover so give up and let STEPattribute recover |
| 104 | + err->GreaterSeverity( SEVERITY_INPUT_ERROR ); |
| 105 | + return SEVERITY_INPUT_ERROR; |
| 106 | + } |
| 107 | + } |
| 108 | + if( c == ')' ) { |
| 109 | + _null = 0; |
| 110 | + } else { // expectation for end paren delim has not been met |
| 111 | + err->GreaterSeverity( SEVERITY_INPUT_ERROR ); |
| 112 | + err->AppendToUserMsg( "Missing close paren for aggregate value" ); |
| 113 | + return SEVERITY_INPUT_ERROR; |
| 114 | + } |
| 115 | + return err->severity(); |
| 116 | +} |
| 117 | + |
| 118 | + |
| 119 | +STEPaggregate & EntityAggregate::ShallowCopy( const STEPaggregate & a ) { |
| 120 | + const EntityNode * tmp = ( const EntityNode * ) a.GetHead(); |
| 121 | + while( tmp ) { |
| 122 | + AddNode( new EntityNode( tmp -> node ) ); |
| 123 | + tmp = ( const EntityNode * ) tmp -> NextNode(); |
| 124 | + } |
| 125 | + if( head ) { |
| 126 | + _null = 0; |
| 127 | + } else { |
| 128 | + _null = 1; |
| 129 | + } |
| 130 | + |
| 131 | + return *this; |
| 132 | +} |
| 133 | + |
| 134 | + |
| 135 | +SingleLinkNode * EntityAggregate::NewNode() { |
| 136 | + return new EntityNode(); |
| 137 | +} |
| 138 | + |
| 139 | +EntityNode::EntityNode() { |
| 140 | +} |
| 141 | + |
| 142 | +EntityNode::~EntityNode() { |
| 143 | +} |
| 144 | + |
| 145 | +EntityNode::EntityNode( SDAI_Application_instance * e ) : node( e ) { |
| 146 | +} |
| 147 | + |
| 148 | +SingleLinkNode * EntityNode::NewNode() { |
| 149 | + return new EntityNode(); |
| 150 | +} |
| 151 | +/////////////////////////////////////////////////////////////////////////////// |
| 152 | + |
| 153 | +Severity EntityNode::StrToVal( const char * s, ErrorDescriptor * err, |
| 154 | + const TypeDescriptor * elem_type, |
| 155 | + InstMgrBase * insts, int addFileId ) { |
| 156 | + SDAI_Application_instance * se = ReadEntityRef( s, err, ",)", insts, |
| 157 | + addFileId ); |
| 158 | + if( se != S_ENTITY_NULL ) { |
| 159 | + ErrorDescriptor error; |
| 160 | + if( EntityValidLevel( se, elem_type, &error ) == SEVERITY_NULL ) { |
| 161 | + node = se; |
| 162 | + } else { |
| 163 | + node = S_ENTITY_NULL; |
| 164 | + err->AppendToDetailMsg( error.DetailMsg() ); |
| 165 | + err->AppendToUserMsg( error.UserMsg() ); |
| 166 | + err->GreaterSeverity( error.severity() ); |
| 167 | + } |
| 168 | + } else { |
| 169 | + node = S_ENTITY_NULL; |
| 170 | + } |
| 171 | + return err->severity(); |
| 172 | +} |
| 173 | + |
| 174 | +Severity EntityNode::StrToVal( istream & in, ErrorDescriptor * err, |
| 175 | + const TypeDescriptor * elem_type, |
| 176 | + InstMgrBase * insts, int addFileId ) { |
| 177 | + return STEPread( in, err, elem_type, insts, addFileId ); |
| 178 | +} |
| 179 | + |
| 180 | +Severity EntityNode::STEPread( const char * s, ErrorDescriptor * err, |
| 181 | + const TypeDescriptor * elem_type, |
| 182 | + InstMgrBase * insts, int addFileId ) { |
| 183 | + istringstream in( ( char * )s ); |
| 184 | + return STEPread( in, err, elem_type, insts, addFileId ); |
| 185 | +} |
| 186 | + |
| 187 | +Severity EntityNode::STEPread( istream & in, ErrorDescriptor * err, |
| 188 | + const TypeDescriptor * elem_type, |
| 189 | + InstMgrBase * insts, int addFileId ) { |
| 190 | + SDAI_Application_instance * se = ReadEntityRef( in, err, ",)", insts, |
| 191 | + addFileId ); |
| 192 | + if( se != S_ENTITY_NULL ) { |
| 193 | + ErrorDescriptor error; |
| 194 | + if( EntityValidLevel( se, elem_type, &error ) == SEVERITY_NULL ) { |
| 195 | + node = se; |
| 196 | + } else { |
| 197 | + node = S_ENTITY_NULL; |
| 198 | + err->AppendToDetailMsg( error.DetailMsg() ); |
| 199 | + err->AppendToUserMsg( error.UserMsg() ); |
| 200 | + err->GreaterSeverity( error.severity() ); |
| 201 | + } |
| 202 | + } else { |
| 203 | + node = S_ENTITY_NULL; |
| 204 | + } |
| 205 | + return err->severity(); |
| 206 | +} |
| 207 | + |
| 208 | +const char * EntityNode::asStr( std::string & s ) { |
| 209 | + s.clear(); |
| 210 | + if( !node || ( node == S_ENTITY_NULL ) ) { // nothing |
| 211 | + return ""; |
| 212 | + } else { // otherwise return entity id |
| 213 | + char tmp [64]; |
| 214 | + sprintf( tmp, "#%d", node->STEPfile_id ); |
| 215 | + s = tmp; |
| 216 | + } |
| 217 | + return const_cast<char *>( s.c_str() ); |
| 218 | +} |
| 219 | + |
| 220 | +const char * EntityNode::STEPwrite( std::string & s, const char * ) { |
| 221 | + if( !node || ( node == S_ENTITY_NULL ) ) { // nothing |
| 222 | + s = "$"; |
| 223 | + return const_cast<char *>( s.c_str() ); |
| 224 | + } |
| 225 | + asStr( s ); |
| 226 | + return const_cast<char *>( s.c_str() ); |
| 227 | +} |
| 228 | + |
| 229 | +void EntityNode::STEPwrite( ostream & out ) { |
| 230 | + if( !node || ( node == S_ENTITY_NULL ) ) { // nothing |
| 231 | + out << "$"; |
| 232 | + } |
| 233 | + std::string s; |
| 234 | + out << asStr( s ); |
| 235 | +} |
| 236 | + |
| 237 | + |
0 commit comments