Skip to content

Commit 5df2f69

Browse files
committed
inching forward on inverse attrs
1 parent 31bf315 commit 5df2f69

7 files changed

Lines changed: 84 additions & 20 deletions

File tree

src/cllazyfile/lazyInstMgr.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,16 @@ unsigned long lazyInstMgr::getNumTypes() const {
9292
}
9393

9494
void lazyInstMgr::openFile( std::string fname ) {
95-
_files.push_back( new lazyFileReader( fname, this, _files.size() ) );
95+
//don't want to hold a lock for the entire time we're reading the file.
96+
//create a place in the vector and remember its location, then free lock
97+
///FIXME begin atomic op
98+
size_t i = _files.size();
99+
_files.push_back( (lazyFileReader * ) 0 );
100+
///FIXME end atomic op
101+
lazyFileReader * lfr = new lazyFileReader( fname, this, i );
102+
_files[i] = lfr;
103+
/// TODO resolve inverse attr references
104+
//between instances, or eDesc --> inst????
96105
}
97106

98107
SDAI_Application_instance * lazyInstMgr::loadInstance( instanceID id, bool reSeek ) {

src/cllazyfile/lazyRefs.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
// note - doing this well will require major changes, since each inst automatically loads every instance that it references
4848
//TODO what about complex instances? scanning each on disk could be a bitch; should the compositional types be scanned during lazy loading?
4949

50+
//TODO/FIXME in generated code, store ia data in map and eliminate data members that are currently used. modify accessors to use map.
5051
class lazyRefs {
5152
public:
5253
typedef std::set< instanceID > referentInstances_t;
@@ -76,7 +77,7 @@ class lazyRefs {
7677
potentialReferentInsts( edL );
7778
//3d - load each inst
7879
/*invAttrListNode * invNode*/
79-
iAstruct * ias = invAttr( _inst, ia /*, iaList*/ );
80+
iAstruct * ias = invAttr( _inst, ia );
8081
referentInstances_t::iterator insts = _referentInstances.begin();
8182
for( ; insts != _referentInstances.end(); ++insts ) {
8283
loadInstIFFreferent( *insts, ias, ia );
@@ -85,13 +86,21 @@ class lazyRefs {
8586
}
8687

8788
void loadInstIFFreferent( instanceID inst, iAstruct * ias, const Inverse_attribute * ia ) {
89+
std::cout << "liir for inst #" << _inst->STEPfile_id << ", referent #" << inst << ", ia " << ia->Name() << "(" << (void*) ia;
90+
std::cout << "), ias " << (void *) ias << std::endl;
8891
bool prevLoaded = _lim->isLoaded( inst );
8992
SDAI_Application_instance * rinst = _lim->loadInstance( inst );
9093
bool ref = refersToCurrentInst( ia, rinst );
9194
if( ref ) {
9295
if( ia->inverted_attr_()->IsAggrType() ) {
96+
if( !ias->a ) {
97+
ias->a = new EntityAggregate;
98+
_inst->setInvAttr( ia, *ias );
99+
assert( invAttr( _inst, ia )->a == ias->a );
100+
}
93101
EntityAggregate * ea = ias->a;
94-
assert( ea && "is it possible for this to be null here? if so, must create & assign");
102+
// assert( ias->a && "is it possible for this to be null here? if so, must create & assign");
103+
//FIXME InitIAttrs has been called, but this is null. what to do? init here? if not, where???
95104
//TODO check if duplicate
96105
ea->AddNode( new EntityNode( rinst ) );
97106
} else {
@@ -183,12 +192,14 @@ END_ENTITY; -- 10303-42: geometry_schema
183192
}
184193
iai = map.begin();
185194
//FIXME treat as unrecoverable?
195+
//need to call inst->InitIAttrs();
186196
std::cerr << "Error! inverse attr " << ia->Name() << " (" << ia << ") not found in iAMap for entity " << inst->getEDesc()->Name() << ". Map contents:" << std::endl;
187197
for( ; iai != map.end(); ++iai ) {
188198
std::cerr << iai->first->Name() << ": " << (void*)(iai->second.a) << ", ";
189199
}
190200
std::cerr << std::endl;
191-
return NULL;
201+
abort();
202+
// // return NULL;
192203
}
193204

194205
/** 3c. compare the type of each item in R with types in A

src/cllazyfile/sectionReader.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ SDAI_Application_instance * sectionReader::getRealInstance( const Registry * reg
314314
_file.unget();
315315
sev = inst->STEPread( instance, 0, _lazyFile->getInstMgr()->getAdapter(), _file, sName, true, false );
316316
//TODO do something with 'sev'
317+
inst->InitIAttrs();
317318
}
318319
return inst;
319320
}

src/clstepcore/sdaiApplication_instance.cc

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ void SDAI_Application_instance::InitIAttrs() {
8888
superInvAttrIter siai( eDesc );
8989
while( !siai.empty() ) {
9090
ia = siai.next();
91+
assert( ia );
9192
iAMap.insert( iAMap_t::value_type( ia, s ) );
9293
}
9394
}
@@ -923,30 +924,41 @@ int SDAI_Application_instance::AttributeCount() {
923924
return attributes.list_length();
924925
}
925926

926-
/// used in getInvAttr() and setInvAttr() to verify that the struct and attr are both entityAggregate or both not
927-
bool validIAS( const Inverse_attribute * const ia, const iAstruct ias ) {
928-
if( ( ias.a && ias.i ) || ( !ias.a && !ias.i ) ) {
929-
return false;
930-
}
931-
// //TODO determine if ia should be an instance or an entityAggregate... how?!
932-
// std::cerr << "TODO: implement " << __PRETTY_FUNCTION__ << "!" << std::endl;
933-
if( ia->inverted_attr_()->IsAggrType() == ( ias.a != 0 ) ) {
934-
return true;
935-
}
936-
return false;
937-
}
927+
// /// used in getInvAttr() and setInvAttr() to verify that the struct and attr are both entityAggregate or both not
928+
// bool validIAS( const Inverse_attribute * const ia, const iAstruct ias ) {
929+
// // //TODO determine if ia should be an instance or an entityAggregate... how?!
930+
// //don't think IsAggrType() is the correct test...
931+
// // std::cerr << "TODO: implement " << __PRETTY_FUNCTION__ << "!" << std::endl;
932+
// if( ia->inverted_attr_()->IsAggrType() == ( dynamic_cast<EntityAggregate * const >( ias.a ) != 0 ) ) {
933+
// return true;
934+
// }
935+
// return false;
936+
// }
938937

939938
const iAstruct SDAI_Application_instance::getInvAttr( const Inverse_attribute * const ia ) const {
940939
iAstruct ias;
941940
iAMap_t::const_iterator it = iAMap.find( ia );
942941
if( it != iAMap.end() ) {
943942
ias = (*it).second;
944-
assert( validIAS( ia, ias ) && "Exactly one member of iAstruct must be non-null, and this must match the type of the Inverse_Attribute." );
943+
// assert( validIAS( ia, ias ) && "Exactly one member of iAstruct must be non-null, and this must match the type of the Inverse_Attribute." );
945944
}
946945
return ias;
947946
}
948947

948+
const SDAI_Application_instance::iAMap_t::value_type SDAI_Application_instance::getInvAttr( const char * name ) const {
949+
iAMap_t::const_iterator it = iAMap.begin();
950+
for( ; it != iAMap.end(); ++it ) {
951+
if( 0 == strcmp( it->first->Name(), name) ) {
952+
return *it;
953+
}
954+
}
955+
iAstruct z;
956+
z.a = NULL;
957+
iAMap_t::value_type nil( NULL, z );
958+
return nil;
959+
}
960+
949961
void SDAI_Application_instance::setInvAttr( const Inverse_attribute * const ia, const iAstruct ias ) {
950-
assert( validIAS( ia, ias ) && "Exactly one member of iAstruct must be non-null, and this must match the type of the Inverse_Attribute." );
962+
// assert( validIAS( ia, ias ) && "Exactly one member of iAstruct must be non-null, and this must match the type of the Inverse_Attribute." );
951963
iAMap.insert( iAMap_t::value_type( ia, ias ) );
952964
}

src/clstepcore/sdaiApplication_instance.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ class SC_CORE_EXPORT SDAI_Application_instance : public SDAI_DAObject_SDAI {
117117
}
118118
// ACCESS inverse attributes
119119
const iAstruct getInvAttr( const Inverse_attribute * const ia ) const;
120+
const iAMap_t::value_type getInvAttr( const char * name ) const;
120121
void setInvAttr( const Inverse_attribute * const ia, const iAstruct ias );
121122
const iAMap_t & getInvAttrs() const {
122123
return iAMap;

src/clstepcore/superInvAttrIter.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ class superInvAttrIter {
1818
bool isempty; ///< if true, don't try to access invIter - it is not initialized
1919
public:
2020
/// WARNING this will not iterate over the ia's in the first ed, only in its supertypes! change that?
21-
superInvAttrIter( const EntityDescriptor * ed ): sit( ed ), nextInv( 0 ), isempty( false ) {
21+
superInvAttrIter( const EntityDescriptor * ed ): sit( ed ), invIter(0), nextInv( 0 ), isempty( false ) {
22+
reset();
23+
}
24+
void reset( const EntityDescriptor * ed = 0 ) {
25+
sit.reset( ed );
2226
if( invIter ) {
2327
delete invIter;
2428
invIter = 0;
@@ -46,7 +50,7 @@ class superInvAttrIter {
4650
if( isempty ) {
4751
return true;
4852
}
49-
return ( sit.empty() && !nextInv );
53+
return ( !sit.hasNext() && !nextInv );
5054
}
5155
const Inverse_attribute * next() {
5256
if( isempty ) {

test/cpp/schema_specific/inverse_attr3.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ extern void SchemaInit( class Registry & );
1515
#include <errordesc.h>
1616
#include <algorithm>
1717
#include <string>
18+
#include <superInvAttrIter.h>
19+
1820
#ifdef HAVE_UNISTD_H
1921
# include <unistd.h>
2022
#endif
@@ -44,7 +46,31 @@ int main( int argc, char * argv[] ) {
4446
}
4547
cout << "instance #" << instance->StepFileId() << endl;
4648

49+
// superInvAttrIter it( instance->getEDesc() );
50+
// // const Inverse_attributeList * l = &( instance->getEDesc()->InverseAttr() );
51+
// // InverseAItr iai(l);
52+
// const Inverse_attribute * ia;
53+
// bool found = false;
54+
// while( !found && ( ia = it.next() ) ) {
55+
// if( !strcmp( ia->Name(), "isdefinedby" ) ) {
56+
// found = true;
57+
// }
58+
// }
59+
// if( found ) {
60+
SDAI_Application_instance::iAMap_t::value_type v = instance->getInvAttr("isdefinedby");
61+
iAstruct attr = v.second; //instance->getInvAttr(ia);
62+
if( attr.a && attr.a->EntryCount() ) {
63+
cout << "Map: found " << attr.a->EntryCount() << " inverse references." << endl;
64+
} else {
65+
cout << "Map: found no inverse references. ias " << (void *) &(v.second) << ", ia " << (void*) v.first << endl;
66+
}
67+
// }
68+
4769
EntityAggregate * aggr = instance->isdefinedby_(); //should be filled in when the file is loaded? not sure how to do it using STEPfile...
70+
//fails because isdefinedby_ uses old data member rather than map lookup
71+
if( attr.a != aggr ) {
72+
cout << "Error! got different EntityAggregate's when using map vs method" << endl;
73+
}
4874
if( aggr && aggr->EntryCount() ) {
4975
cout << "Found " << aggr->EntryCount() << " inverse references." << endl;
5076
exit( EXIT_SUCCESS );

0 commit comments

Comments
 (0)