POL source code, how to iterate through storage

Here you can post threads requesting help on the official POL Ultima Online Emulator Core 098.

Moderator: POL Developer

Post Reply
Gnafu
Grandmaster Poster
Posts: 136
Joined: Thu Feb 02, 2006 7:29 am
Location: Livorno, Italy
Contact:

POL source code, how to iterate through storage

Post by Gnafu » Sat May 15, 2010 4:21 pm

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!!
:shame:

User avatar
*Edwards
Forum Regular
Posts: 302
Joined: Fri Dec 28, 2007 11:19 pm
Location: Montreal, Canada

Re: POL source code, how to iterate through storage

Post by *Edwards » Sat May 15, 2010 4:28 pm

I'd suggest to look with distro097 in pkg/items/containers/include/storageAreas to see exemples of what you are trying to do.

Turley
POL Developer
Posts: 670
Joined: Sun Feb 05, 2006 4:45 am

Re: POL source code, how to iterate through storage

Post by Turley » Sat May 15, 2010 11:58 pm

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);

Gnafu
Grandmaster Poster
Posts: 136
Joined: Thu Feb 02, 2006 7:29 am
Location: Livorno, Italy
Contact:

Re: POL source code, how to iterate through storage

Post by Gnafu » Sun May 16, 2010 7:04 am

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:

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);
So, I can iterate BUT I only get BObjects :(
BObjects are created on UObjects

Code: Select all

    BObject* result = new BObject( make_itemref( (*itr).second ) );   //<- (*itr).second is a UObject
and I don't know how to get the UObject back from them. :cry:


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();
	}

Post Reply