Skip to content

Commit ec5171f

Browse files
committed
move EntityAggregate and co out of STEPaggregate.*
1 parent c962b1d commit ec5171f

File tree

5 files changed

+324
-317
lines changed

5 files changed

+324
-317
lines changed

src/clstepcore/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ set(LIBSTEPCORE_SRCS
4242
SingleLinkList.cc
4343
STEPaggregate.cc
4444
STEPaggrBinary.cc
45+
STEPaggrEntity.cc
4546
STEPaggrEnum.cc
4647
STEPaggrInt.cc
4748
STEPaggrReal.cc
@@ -100,6 +101,7 @@ set(SC_CLSTEPCORE_HDRS
100101
SingleLinkList.h
101102
STEPaggregate.h
102103
STEPaggrBinary.h
104+
STEPaggrEntity.h
103105
STEPaggrEnum.h
104106
STEPaggrInt.h
105107
STEPaggrReal.h

src/clstepcore/STEPaggrEntity.cc

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
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+

src/clstepcore/STEPaggrEntity.h

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#ifndef STEPAGGRENTITY_H
2+
#define STEPAGGRENTITY_H
3+
4+
/** \file STEPaggrEntity.h
5+
* classes EntityAggregate, EntityNode
6+
*/
7+
8+
#include "STEPaggregate.h"
9+
#include <sc_export.h>
10+
11+
class SC_CORE_EXPORT EntityAggregate : public STEPaggregate {
12+
public:
13+
virtual Severity ReadValue( istream & in, ErrorDescriptor * err,
14+
const TypeDescriptor * elem_type,
15+
InstMgrBase * insts, int addFileId = 0,
16+
int assignVal = 1, int ExchangeFileFormat = 1,
17+
const char * currSch = 0 );
18+
19+
virtual SingleLinkNode * NewNode();
20+
virtual STEPaggregate & ShallowCopy( const STEPaggregate & );
21+
22+
EntityAggregate();
23+
virtual ~EntityAggregate();
24+
};
25+
typedef EntityAggregate * EntityAggregateH;
26+
typedef EntityAggregate * EntityAggregate_ptr;
27+
typedef const EntityAggregate * EntityAggregate_ptr_c;
28+
typedef EntityAggregate_ptr EntityAggregate_var;
29+
30+
class SC_CORE_EXPORT EntityNode : public STEPnode {
31+
public:
32+
SDAI_Application_instance * node;
33+
34+
// INPUT
35+
virtual Severity StrToVal( const char * s, ErrorDescriptor * err,
36+
const TypeDescriptor * elem_type,
37+
InstMgrBase * insts, int addFileId = 0 );
38+
virtual Severity StrToVal( istream & in, ErrorDescriptor * err,
39+
const TypeDescriptor * elem_type,
40+
InstMgrBase * insts, int addFileId = 0 );
41+
42+
virtual Severity STEPread( const char * s, ErrorDescriptor * err,
43+
const TypeDescriptor * elem_type,
44+
InstMgrBase * insts, int addFileId = 0 );
45+
virtual Severity STEPread( istream & in, ErrorDescriptor * err,
46+
const TypeDescriptor * elem_type,
47+
InstMgrBase * insts, int addFileId = 0 );
48+
// OUTPUT
49+
virtual const char * asStr( std::string & s );
50+
virtual const char * STEPwrite( std::string & s, const char * = 0 );
51+
virtual void STEPwrite( ostream & out = cout );
52+
53+
// CONSTRUCTORS
54+
EntityNode( SDAI_Application_instance * e );
55+
EntityNode();
56+
~EntityNode();
57+
58+
virtual SingleLinkNode * NewNode();
59+
60+
// Calling these funtions is an error.
61+
Severity StrToVal( const char * s, ErrorDescriptor * err ) {
62+
cerr << "Internal error: " << __FILE__ << __LINE__
63+
<< "\n" << _POC_ "\n";
64+
return StrToVal( s, err, 0, 0, 0 );
65+
}
66+
Severity StrToVal( istream & in, ErrorDescriptor * err ) {
67+
cerr << "Internal error: " << __FILE__ << __LINE__
68+
<< "\n" << _POC_ "\n";
69+
return StrToVal( in, err, 0, 0, 0 );
70+
}
71+
72+
Severity STEPread( const char * s, ErrorDescriptor * err ) {
73+
cerr << "Internal error: " << __FILE__ << __LINE__
74+
<< "\n" << _POC_ "\n";
75+
return STEPread( s, err, 0, 0, 0 );
76+
}
77+
Severity STEPread( istream & in, ErrorDescriptor * err ) {
78+
cerr << "Internal error: " << __FILE__ << __LINE__
79+
<< "\n" << _POC_ "\n";
80+
return STEPread( in, err, 0, 0, 0 );
81+
}
82+
};
83+
84+
#endif //STEPAGGRENTITY_H

0 commit comments

Comments
 (0)