| View previous topic :: View next topic |
| Author |
Message |
coolkehon
Joined: 20 Oct 2008 Posts: 355
|
Posted: Mon Sep 21, 2009 2:59 pm Post subject: 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 |
|
| Back to top |
|
 |
Mon Ouïe
Joined: 05 Jul 2009 Posts: 36
|
Posted: Tue Sep 22, 2009 3:24 am Post subject: |
|
|
| I've not tried shared_ptr, but I'm pretty sur the "header only" part of boost can be used. ( I've already compiled the multi_array sample ^^ ) |
|
| Back to top |
|
 |
coolkehon
Joined: 20 Oct 2008 Posts: 355
|
Posted: Tue Sep 22, 2009 4:47 am Post subject: |
|
|
| I haven't re-installed my pspdev on ubuntu yet so could someone compile an example and confirm that it's working |
|
| Back to top |
|
 |
Mon Ouïe
Joined: 05 Jul 2009 Posts: 36
|
Posted: Tue Sep 22, 2009 5:13 am Post subject: |
|
|
It's working :
| Code: | #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();
}
|
http://www.boost.org/doc/libs/1_40_0/libs/smart_ptr/example/shared_ptr_example.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 :) |
|
| Back to top |
|
 |
coolkehon
Joined: 20 Oct 2008 Posts: 355
|
Posted: Tue Sep 22, 2009 11:16 am Post subject: |
|
|
| thanks you very much greatly appreciated |
|
| Back to top |
|
 |
|