高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】stl-like Iterators
stl-like iterators
stl-like iterators
to maintain readability in our code base and make it easy for others to use dwgdirect iterators, i'm trying to write an stl-like iterator class to serve as a wrapper for oddbsymboltableiterator (and eventually for oddbobjectiterator). i have created a class (myiter), which contains an oddbsymboltableiteratorptr member variable. in the copy constructor, i want to create a copy of the oddbsymboltableiterator. to do this, i am using the following code:
code:
myiter( const myiter& _rhs ) //copy constructor
{
...
//mlibiterptr is an oddbsymboltableiteratorptr
odrxobjectptr pclone = _rhs.mlibiterptr->clone();
mlibiterptr.attach( pclone.get() );
}
however, i am getting a crash somewhere in the call to 'clone()'. i realize that 'clone()' is a virtual function implemented in odrxobject (the parent class of oddbsymboltableiterator), but not implemented in oddbsymboltableiterator itself. can i clone a dwgdirect iterator?
i'm open to suggestions if there are other ways to go about wrapping up iterators.
that's really interesting, thogh i'm not sure which of the stl algorhytms would be usefull for processing the symbol tables and entities (except for_each), but anyway, this can shorten certain parts of code.
what about _rhs.mlibiterptr->isa()->create()? and then move the newly created iterator by its seek member to the position returned by _rhs.mlibiterptr->getrecord() or _rhs.mlibiterptr->getrecordid()
regards
chudomir
best regards
chudomir
no luck. 'create()' returned a null pointer. in addition, this solution requires a 'seek()' call, which i was hoping to avoid in order to keep the code efficient. any ideas on how to get a new iterator that points to the same element as the old iterator without having to hunt for it?
i noticed that both of the constructors for oddbsymboltableiterator are protected, accessible only by friend class oddbsymboltable. am i foolish to think that i can get a copy of an oddbsymboltableiterator from anyplace besides an oddbsymboltable?
also, the crashes in 'clone()' and 'copyfrom()' seem like bugs: if these operations aren't supported by a particular derived class, they ought to do something more graceful than crash.
|