Merge pull request #476 from starseeker/upstream/redefined-attribute-serialization

stepcore: serialize redefined attributes before derived markers
This commit is contained in:
Clifford Yapp
2026-08-01 23:09:53 -04:00
committed by GitHub
3 changed files with 51 additions and 21 deletions
+21 -18
View File
@@ -392,18 +392,19 @@ const char * STEPattribute::asStr( std::string & str, const char * currSch ) con
str.clear();
// The attribute has been redefined by the attribute pointed
// to by _redefAttr so write the narrowed value in the inherited
// physical-file slot. STEPread and StrToVal use this same precedence.
if( _redefAttr ) {
return _redefAttr->asStr( str, currSch );
}
// The attribute has been derived by a subtype's attribute
if( IsDerived() ) {
str = "*";
return const_cast<char *>( str.c_str() );
}
// The attribute has been redefined by the attribute pointed
// to by _redefAttr so write the redefined value.
if( _redefAttr ) {
return _redefAttr->asStr( str, currSch );
}
if( is_null() ) {
str = "";
return const_cast<char *>( str.c_str() );
@@ -485,18 +486,19 @@ std::string STEPattribute::asStr( const char * currSch ) const {
ostringstream ss;
std::string str;
// The attribute has been redefined by the attribute pointed
// to by _redefAttr so write the narrowed value in the inherited
// physical-file slot. STEPread and StrToVal use this same precedence.
if( _redefAttr ) {
return _redefAttr->asStr( currSch );
}
// The attribute has been derived by a subtype's attribute
if( IsDerived() ) {
str = "*";
return str;
}
// The attribute has been redefined by the attribute pointed
// to by _redefAttr so write the redefined value.
if( _redefAttr ) {
return _redefAttr->asStr( currSch );
}
if( is_null() ) {
return str;
}
@@ -587,17 +589,18 @@ void STEPattribute::STEPwriteError( ostream & out, unsigned int line, const char
*
*/
void STEPattribute::STEPwrite( ostream & out, const char * currSch ) {
// The attribute has been redefined by the attribute pointed
// to by _redefAttr so write the narrowed value in the inherited
// physical-file slot. STEPread and StrToVal use this same precedence.
if( _redefAttr ) {
_redefAttr->STEPwrite( out, currSch );
return;
}
// The attribute has been derived by a subtype's attribute
if( IsDerived() ) {
out << "*";
return;
}
// The attribute has been redefined by the attribute pointed
// to by _redefAttr so write the redefined value.
if( _redefAttr ) {
_redefAttr->STEPwrite( out );
return;
}
if( is_null() ) {
out << "$";
@@ -565,9 +565,6 @@ Severity SDAI_Application_instance::STEPread( int id, int idIncr,
if( c == ')' ) { // assume you are at the end so read last char
in >> c;
}
cout << "Entity #" << STEPfile_id
<< " skipping redefined attribute "
<< attributes[i].aDesc->Name() << endl << endl << flush;
}
// increment counter to read following attr since these attrs
// aren't written or read => there won't be a delimiter either
@@ -39,6 +39,35 @@ bool testEqu( const STEPattribute & a1, const STEPattribute & a2, bool invert, c
return pass;
}
bool testRedefinedDerivedWrite( const AttrDescriptor & ad ) {
SDAI_Integer inherited_value = 123L;
SDAI_Integer narrowed_value = 456L;
STEPattribute inherited( ad, & inherited_value );
STEPattribute narrowed( ad, & narrowed_value );
// A redeclared explicit attribute occupies its inherited physical-file
// slot, which is also marked derived in the generated supertype class.
inherited.Derive();
inherited.RedefiningAttr( & narrowed );
bool pass = true;
std::string value;
inherited.asStr( value );
if( inherited.asStr() != "456" || value != "456" ) {
std::cerr << "redefined derived attribute asStr() failed" << std::endl;
pass = false;
}
std::ostringstream output;
inherited.STEPwrite( output );
if( output.str() != "456" ) {
std::cerr << "redefined derived attribute STEPwrite() failed" << std::endl;
pass = false;
}
return pass;
}
int main( int /*argc*/, char ** /*argv*/ ) {
bool pass = true;
EntityDescriptor ed( "ename", 0, LFalse, LFalse );
@@ -64,6 +93,7 @@ int main( int /*argc*/, char ** /*argv*/ ) {
STEPattribute aii( adi, & s2int );
pass &= testEqu( ai, aii, true, "ints !=" );
pass &= testRedefinedDerivedWrite( adi );
if( pass ) {
exit( EXIT_SUCCESS );