forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Boost::shared_ptr

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
coolkehon



Joined: 20 Oct 2008
Posts: 355

PostPosted: Mon Sep 21, 2009 2:59 pm    Post subject: Boost::shared_ptr Reply with quote

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
View user's profile Send private message MSN Messenger
Mon Ouïe



Joined: 05 Jul 2009
Posts: 36

PostPosted: Tue Sep 22, 2009 3:24 am    Post subject: Reply with quote

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
View user's profile Send private message
coolkehon



Joined: 20 Oct 2008
Posts: 355

PostPosted: Tue Sep 22, 2009 4:47 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Mon Ouïe



Joined: 05 Jul 2009
Posts: 36

PostPosted: Tue Sep 22, 2009 5:13 am    Post subject: Reply with quote

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
View user's profile Send private message
coolkehon



Joined: 20 Oct 2008
Posts: 355

PostPosted: Tue Sep 22, 2009 11:16 am    Post subject: Reply with quote

thanks you very much greatly appreciated
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group