I spent all the day trying to iterate into the "root" items in a storage area.
I don't know what to do.
After getting the StorageArea reference I don't know how to use the StorageAreaIterator
I'm stuck with
StorageArea *area = storage.find_area("World Bank");
Please help!!
POL source code, how to iterate through storage
Moderator: POL Developer
Re: POL source code, how to iterate through storage
I'd suggest to look with distro097 in pkg/items/containers/include/storageAreas to see exemples of what you are trying to do.
Re: POL source code, how to iterate through storage
He means polcore source not escript
Since _items is a private member you can only iterate inside the StorageArea class or a friendclass, its a map so
for (Cont::iterator itr=_items.begin(); itr!=_items.end(); ++itr)
...
or you use the class StorageAreaIterator
should be something like:
BObject* pIterVal = new BObject(UninitObject::create());
StorageArea *area = storage.find_area("World Bank");
ContIterator* pIter = area->createIterator( pIterVal );
do
{
BObject* next = pIter->step();
}
while (next != NULL);
Since _items is a private member you can only iterate inside the StorageArea class or a friendclass, its a map so
for (Cont::iterator itr=_items.begin(); itr!=_items.end(); ++itr)
...
or you use the class StorageAreaIterator
should be something like:
BObject* pIterVal = new BObject(UninitObject::create());
StorageArea *area = storage.find_area("World Bank");
ContIterator* pIter = area->createIterator( pIterVal );
do
{
BObject* next = pIter->step();
}
while (next != NULL);
Re: POL source code, how to iterate through storage
StorageAreaImp and StorageAreaIterator are friend but they are defined in storage.cpp and not declared anywhere so I copy-pasted them in my file (uoimport.cpp) adding them as friend too.
friend class SAI;
friend class SAIMP;
StorageArea don't have a "createiterator()" method, I had to do this:
So, I can iterate BUT I only get BObjects
BObjects are created on UObjects
and I don't know how to get the UObject back from them.
Anyway, I solved by creating new methods "createMYIterator()" and "MyStep()" to be able to get an UObject instead of a BObject.
There must be a better way to do that...
My Working Code:
friend class SAI;
friend class SAIMP;
StorageArea don't have a "createiterator()" method, I had to do this:
Code: Select all
StorageArea *area = storage.find_area("World Bank");
if(area != NULL)
cout<<"World Bank found"<<endl; // <- I always get this
else
cout<<"WORLD BANK ERROR"<<endl;
BObject* pIterVal = new BObject(UninitObject::create());
SAIMP aIter = SAIMP(area); // <- I must create a StorageAreaImp
ContIterator* pIter = aIter.createIterator(pIterVal); // <- and then create an iterator (StorageAreaIterator)
BObject* next;
do
{
next = pIter->step();
cout<<'.'; // <- many dots showing, something in going on
}
while (next != NULL);
BObjects are created on UObjects
Code: Select all
BObject* result = new BObject( make_itemref( (*itr).second ) ); //<- (*itr).second is a UObject
Anyway, I solved by creating new methods "createMYIterator()" and "MyStep()" to be able to get an UObject instead of a BObject.
There must be a better way to do that...
My Working Code:
Code: Select all
StorageArea *area = storage.find_area("World Bank");
BObject* pIterVal = new BObject(UninitObject::create());
SAIMP aIter = SAIMP(area);
SAI* pIter = aIter.createMYIterator(pIterVal);
UObject* next;
next = pIter->mystep();
while (next != NULL)
{
cout<<next->name()<<'\t';
next = pIter->mystep();
}