Boost::shared_ptr
Boost::shared_ptr
I'm making a game for the pc but I'm making it so that it will be easily ported to the psp. Does boost4psp support the boost::shared_ptr class
It's working :
http://www.boost.org/doc/libs/1_40_0/li ... xample.cpp
I just replaced cout by pspDebugScreenPrintf, and moved the sample part in another function, because we cannot see the destructor part if they're not destroyed before the sceKernelDelayThread... It could be done with { /* */ } too.
It displays the expected output :)
Code: Select all
#include <pspkernel.h>
#include <vector>
#include <set>
#include <iostream>
#include <algorithm>
#include <boost/shared_ptr.hpp>
PSP_MODULE_INFO("boost test", 0, 1, 0);
struct Foo
{
Foo(int _x):
x(_x)
{}
~Foo() {
pspDebugScreenPrintf("Destruction Foo with x=%d\n", x);
}
int x;
};
typedef boost::shared_ptr<Foo> FooPtr;
struct FooPtrOps
{
bool operator()(const FooPtr &a, const FooPtr &b) {
return a->x > b->x;
}
void operator()(const FooPtr &a) {
pspDebugScreenPrintf("%d\n", a->x);
}
};
void func() {
std::vector<FooPtr> foo_vector;
std::set<FooPtr, FooPtrOps> foo_set;
FooPtr foo_ptr(new Foo(2));
foo_vector.push_back(foo_ptr);
foo_set.insert(foo_ptr);
foo_ptr.reset(new Foo(1));
foo_vector.push_back(foo_ptr);
foo_set.insert(foo_ptr);
foo_ptr.reset(new Foo(3));
foo_vector.push_back(foo_ptr);
foo_set.insert(foo_ptr);
foo_ptr.reset (new Foo(2));
foo_vector.push_back(foo_ptr);
foo_set.insert(foo_ptr);
pspDebugScreenPrintf("foo_vector: \n");
std::for_each(foo_vector.begin(), foo_vector.end(), FooPtrOps());
pspDebugScreenPrintf("\nfoo_set:\n");
std::for_each(foo_set.begin(), foo_set.end(), FooPtrOps());
pspDebugScreenPrintf("\n");
}
int main() {
pspDebugScreenInit();
func();
sceKernelDelayThread(5000 * 1000);
sceKernelExitGame();
}
I just replaced cout by pspDebugScreenPrintf, and moved the sample part in another function, because we cannot see the destructor part if they're not destroyed before the sceKernelDelayThread... It could be done with { /* */ } too.
It displays the expected output :)