Skip to content

Commit 5e1ad8f

Browse files
committed
Remove Raw() and getEDesc(), restore C asStr()
This commit removes the Raw and getEDesc methods in favor of the simplicity of just making ptr and eDesc public. Add back in previous version of asStr() that returns a C string. aDesc is also made public. These changes are motivated by BRL-CAD's use of stepcode.
1 parent 380618f commit 5e1ad8f

10 files changed

Lines changed: 129 additions & 41 deletions

File tree

src/cllazyfile/lazyRefs.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ class SC_LAZYFILE_EXPORT lazyRefs {
115115
if( !ai ) {
116116
ias.i = rinst;
117117
_inst->setInvAttr( ia, ias );
118-
} else if( ai->GetFileId() != (int)inst ) {
119-
std::cerr << "ERROR: two instances (" << rinst << ", #" << rinst->GetFileId() << "=" << rinst->getEDesc()->Name();
120-
std::cerr << " and " << ai << ", #" << ai->GetFileId() <<"=" << ai->getEDesc()->Name() << ") refer to inst ";
118+
} else if( ai->GetFileId() != ( int )inst ) {
119+
std::cerr << "ERROR: two instances (" << rinst << ", #" << rinst->GetFileId() << "=" << rinst->eDesc->Name();
120+
std::cerr << " and " << ai << ", #" << ai->GetFileId() << "=" << ai->eDesc->Name() << ") refer to inst ";
121121
std::cerr << _inst->GetFileId() << ", but its inverse attribute is not an aggregation type!" << std::endl;
122122
// TODO _error->GreaterSeverity( SEVERITY_INPUT_ERROR );
123123
}
@@ -184,7 +184,7 @@ class SC_LAZYFILE_EXPORT lazyRefs {
184184
}
185185
++iai;
186186
}
187-
std::cerr << "Error! inverse attr " << ia->Name() << " (" << ia << ") not found in iAMap for entity " << inst->getEDesc()->Name() << std::endl;
187+
std::cerr << "Error! inverse attr " << ia->Name() << " (" << ia << ") not found in iAMap for entity " << inst->eDesc->Name() << std::endl;
188188
abort();
189189
iAstruct nil = {nullptr};
190190
return nil;
@@ -279,7 +279,7 @@ class SC_LAZYFILE_EXPORT lazyRefs {
279279

280280

281281
// 1. find inverse attrs with recursion
282-
getInverseAttrs( ai->getEDesc(), _iaList );
282+
getInverseAttrs( ai->eDesc, _iaList );
283283

284284
//2. find reverse refs, map id to type (stop if there are no inverse attrs or no refs)
285285
if( _iaList.size() == 0 || !mapRefsToTypes() ) {

src/cllazyfile/lazy_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ void dumpComplexInst( STEPcomplex * c ) {
111111
STEPcomplex * complex = c->head;
112112
while( complex ) {
113113
if( complex->IsComplex() ) {
114-
std::cout << "Complex component " << complex->getEDesc()->Name() << " at depth " << depth << " with attr list size ";
114+
std::cout << "Complex component " << complex->eDesc->Name() << " at depth " << depth << " with attr list size ";
115115
std::cout << complex->_attr_data_list.size() << std::endl;
116116
// dumpComplexInst( complex, depth + 1 );
117117
} else {
118118
//probably won't ever get here...
119119
SDAI_Application_instance * ai = dynamic_cast< SDAI_Application_instance * >( complex );
120120
if( ai ) {
121-
std::cout << "non-complex component at depth " << depth << ", " << ai->getEDesc()->Name() << std::endl;
121+
std::cout << "non-complex component at depth " << depth << ", " << ai->eDesc->Name() << std::endl;
122122
} else {
123123
std::cout << "unknown component at depth " << depth << ": " << complex << std::endl;
124124
}

src/cllazyfile/sectionReader.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ SDAI_Application_instance * sectionReader::getRealInstance( const Registry * reg
306306
if( !comment.empty() ) {
307307
inst->AddP21Comment( comment );
308308
}
309-
assert( inst->getEDesc() );
309+
assert( inst->eDesc );
310310
_file.seekg( begin );
311311
findNormalString( "(" );
312312
_file.seekg( _file.tellg() - std::streampos(1) );

src/clstepcore/Registry.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ SDAI_Application_instance * Registry::ObjCreate( const char * nm, const char * s
260260
se->Error().severity( SEVERITY_WARNING );
261261
se->Error().UserMsg( "ENTITY requires external mapping" );
262262
}
263-
se->setEDesc( entd );
263+
se->eDesc = entd;
264264
return se;
265265
} else {
266266
return ENTITY_NULL;

src/clstepcore/STEPattribute.cc

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,100 @@ Severity STEPattribute::STEPread( istream & in, InstMgrBase * instances, int add
382382
}
383383
}
384384

385+
/*****************************************************************//**
386+
** \fn asStr
387+
** \param currSch - used for select type writes. See commenting in SDAI_Select::STEPwrite().
388+
** \returns the value of the attribute
389+
** Status: complete 3/91
390+
*********************************************************************/
391+
const char * STEPattribute::asStr( std::string & str, const char * currSch ) const {
392+
ostringstream ss;
393+
394+
str.clear();
395+
396+
// The attribute has been derived by a subtype's attribute
397+
if( IsDerived() ) {
398+
str = "*";
399+
return const_cast<char *>( str.c_str() );
400+
}
401+
402+
// The attribute has been redefined by the attribute pointed
403+
// to by _redefAttr so write the redefined value.
404+
if( _redefAttr ) {
405+
return _redefAttr->asStr( str, currSch );
406+
}
407+
408+
if( is_null() ) {
409+
str = "";
410+
return const_cast<char *>( str.c_str() );
411+
}
412+
413+
switch( NonRefType() ) {
414+
case INTEGER_TYPE:
415+
ss << *( ptr.i );
416+
str += ss.str();
417+
break;
418+
419+
case NUMBER_TYPE:
420+
case REAL_TYPE:
421+
422+
ss.precision( ( int ) Real_Num_Precision );
423+
ss << *( ptr.r );
424+
str += ss.str();
425+
break;
426+
427+
case ENTITY_TYPE:
428+
// print instance id only if not empty pointer
429+
// and has value assigned
430+
if( ( *( ptr.c ) == S_ENTITY_NULL ) || ( *( ptr.c ) == 0 ) ) {
431+
break;
432+
} else {
433+
( *( ptr.c ) )->STEPwrite_reference( str );
434+
}
435+
break;
436+
437+
case BINARY_TYPE:
438+
if( !( ( ptr.b )->empty() ) ) {
439+
( ptr.b ) -> STEPwrite( str );
440+
}
441+
break;
442+
443+
case STRING_TYPE:
444+
if( !( ( ptr.S )->empty() ) ) {
445+
return ( ptr.S ) -> asStr( str );
446+
}
447+
break;
448+
449+
case AGGREGATE_TYPE:
450+
case ARRAY_TYPE: // DAS
451+
case BAG_TYPE: // DAS
452+
case SET_TYPE: // DAS
453+
case LIST_TYPE: // DAS
454+
return ptr.a->asStr( str ) ;
455+
456+
case ENUM_TYPE:
457+
case BOOLEAN_TYPE:
458+
case LOGICAL_TYPE:
459+
return ptr.e -> asStr( str );
460+
461+
case SELECT_TYPE:
462+
ptr.sh -> STEPwrite( str, currSch );
463+
return const_cast<char *>( str.c_str() );
464+
465+
case REFERENCE_TYPE:
466+
case GENERIC_TYPE:
467+
cerr << "Internal error: " << __FILE__ << __LINE__
468+
<< "\n" << _POC_ "\n";
469+
return 0;
470+
471+
case UNKNOWN_TYPE:
472+
default:
473+
return ( ptr.u -> asStr( str ) );
474+
}
475+
return const_cast<char *>( str.c_str() );
476+
}
477+
478+
385479
/*****************************************************************//**
386480
** \fn asStr
387481
** \param currSch - used for select type writes. See commenting in SDAI_Select::STEPwrite().

src/clstepcore/STEPattribute.h

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,15 @@ extern SC_CORE_EXPORT void PushPastAggr1Dim( istream & in, std::string & s, Erro
7575
class SC_CORE_EXPORT STEPattribute {
7676
friend ostream & operator<< ( ostream &, STEPattribute & );
7777
friend class SDAI_Application_instance;
78-
protected:
79-
bool _derive;
80-
bool _mustDeletePtr; ///if a member uses new to create an object in ptr
81-
ErrorDescriptor _error;
82-
STEPattribute * _redefAttr;
83-
const AttrDescriptor * aDesc;
84-
int refCount;
8578

79+
public:
8680
/** \union ptr
87-
** You know which of these to use based on the return value of
88-
** NonRefType() - see below. BASE_TYPE is defined in baseType.h
89-
** This variable points to an appropriate member variable in the entity
90-
** class in the generated schema class library (the entity class is
91-
** inherited from SDAI_Application_instance)
92-
*/
81+
** You know which of these to use based on the return value of
82+
** NonRefType() - see below. BASE_TYPE is defined in baseType.h
83+
** This variable points to an appropriate member variable in the entity
84+
** class in the generated schema class library (the entity class is
85+
** inherited from SDAI_Application_instance)
86+
*/
9387
union attrUnion {
9488
SDAI_String * S; // STRING_TYPE
9589
SDAI_Integer * i; // INTEGER_TYPE (Integer is a long int)
@@ -103,6 +97,18 @@ class SC_CORE_EXPORT STEPattribute {
10397
void * p;
10498
} ptr;
10599

100+
101+
protected:
102+
bool _derive;
103+
bool _mustDeletePtr; ///if a member uses new to create an object in ptr
104+
ErrorDescriptor _error;
105+
STEPattribute * _redefAttr;
106+
public:
107+
const AttrDescriptor * aDesc;
108+
109+
protected:
110+
int refCount;
111+
106112
char SkipBadAttr( istream & in, char * StopChars );
107113
void AddErrorInfo();
108114
void STEPwriteError( ostream& out, unsigned int line, const char* desc );
@@ -137,6 +143,7 @@ class SC_CORE_EXPORT STEPattribute {
137143

138144
/// return the attr value as a string
139145
string asStr( const char * currSch = 0 ) const;
146+
const char * asStr( std::string &, const char * = 0 ) const;
140147

141148
/// put the attr value in ostream
142149
void STEPwrite( ostream & out = cout, const char * currSch = 0 );
@@ -167,11 +174,6 @@ class SC_CORE_EXPORT STEPattribute {
167174
SCLundefined * Undefined();
168175
///@}
169176

170-
/// allows direct access to the union containing attr data (dangerous!)
171-
attrUnion * Raw() {
172-
return & ptr;
173-
}
174-
175177
/**
176178
* These functions allow setting the attribute value.
177179
* Attr type is verified using an assertion.

src/clstepcore/sdaiApplication_instance.cc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,6 @@ void SDAI_Application_instance::AppendMultInstance( SDAI_Application_instance *
170170
}
171171
}
172172

173-
const EntityDescriptor* SDAI_Application_instance::getEDesc() const {
174-
return eDesc;
175-
}
176-
177173
// BUG implement this -- FIXME function is never used
178174
SDAI_Application_instance * SDAI_Application_instance::GetMiEntity( char * entName ) {
179175
std::string s1, s2;
@@ -788,9 +784,9 @@ Severity EntityValidLevel( SDAI_Application_instance * se,
788784
// DAVE: Can an entity be used in an Express TYPE so that this
789785
// EntityDescriptor would have type REFERENCE_TYPE -- it looks like NO
790786

791-
else if( se->getEDesc() ) {
787+
else if( se->eDesc ) {
792788
// is se a descendant of ed?
793-
if( se->getEDesc()->IsA( ed ) ) {
789+
if( se->eDesc->IsA( ed ) ) {
794790
return SEVERITY_NULL;
795791
} else {
796792
if( se->IsComplex() ) {

src/clstepcore/sdaiApplication_instance.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class SC_CORE_EXPORT SDAI_Application_instance : public SDAI_DAObject_SDAI {
3636

3737
public:
3838
typedef std::map< const Inverse_attribute * const, iAstruct> iAMap_t;
39-
protected:
4039
const EntityDescriptor * eDesc;
40+
protected:
4141
#ifdef _MSC_VER
4242
#pragma warning( push )
4343
#pragma warning( disable: 4251 )
@@ -89,10 +89,6 @@ class SC_CORE_EXPORT SDAI_Application_instance : public SDAI_DAObject_SDAI {
8989
/// initialize inverse attribute list
9090
void InitIAttrs();
9191

92-
void setEDesc( const EntityDescriptor * const ed ) {
93-
eDesc = ed;
94-
}
95-
const EntityDescriptor * getEDesc() const;
9692
void StepFileId( int fid ) {
9793
STEPfile_id = fid;
9894
}

src/exp2cxx/selects.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,7 @@ void TYPEselect_lib_part21( const Type type, FILE * f ) {
14931493
" _%s = ReadEntityRef(in, &_error, \",)\", instances, addFileId);\n", dm );
14941494
fprintf( f,
14951495
" if( _%s && ( _%s != S_ENTITY_NULL) &&\n "
1496-
" ( CurrentUnderlyingType()->CanBe( _%s->getEDesc() ) ) ) {\n"
1496+
" ( CurrentUnderlyingType()->CanBe( _%s->eDesc ) ) ) {\n"
14971497
" return severity();\n", dm, dm, dm );
14981498
fprintf( f,
14991499
" } else {\n "
@@ -1680,7 +1680,7 @@ void SELlib_print_protected( const Type type, FILE * f ) {
16801680
if( TYPEis_select( t ) ) {
16811681
fprintf( f,
16821682
" // %s\n" /* item name */
1683-
" if( %s->CanBe( se->getEDesc() ) ) {\n"
1683+
" if( %s->CanBe( se->eDesc ) ) {\n"
16841684
" _%s.AssignEntity (se);\n" /* underlying data member */
16851685
" return SetUnderlyingType (%s);\n" /* td */
16861686
" }\n",

test/cpp/schema_specific/inverse_attr1.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ bool findInverseAttrs1( InverseAItr iai, InstMgr & instList ) {
4343
EntityNode * en = ( EntityNode * ) relObj->GetHead();
4444
SdaiObject * obj = ( SdaiObject * ) en->node;
4545
cout << "file id " << obj->StepFileId() << "; name "
46-
<< instList.GetApplication_instance( obj->StepFileId() - 1 )->getEDesc()->Name() << endl;
46+
<< instList.GetApplication_instance( obj->StepFileId() - 1 )->eDesc->Name() << endl;
4747
}
4848
ent_id = i;
4949
}

0 commit comments

Comments
 (0)