Boost::shared_ptr

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Boost::shared_ptr

Post by coolkehon »

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
Mon Ouïe
Posts: 36
Joined: Sun Jul 05, 2009 10:22 pm

Post by Mon Ouïe »

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 ^^ )
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

I haven't re-installed my pspdev on ubuntu yet so could someone compile an example and confirm that it's working
Mon Ouïe
Posts: 36
Joined: Sun Jul 05, 2009 10:22 pm

Post by Mon Ouïe »

It's working :

Code: Select all

#include <pspkernel.h>

#include <vector>
#include <set>
#include <iostream>
#include <algorithm>
#include <boost/shared_ptr.hpp>

PSP_MODULE_INFO&#40;"boost test", 0, 1, 0&#41;;

struct Foo
&#123;
   Foo&#40;int _x&#41;&#58;
      x&#40;_x&#41;
   &#123;&#125;

   ~Foo&#40;&#41; &#123;
      pspDebugScreenPrintf&#40;"Destruction Foo with x=%d\n", x&#41;;
   &#125;

   int x;
&#125;;

typedef boost&#58;&#58;shared_ptr<Foo> FooPtr;

struct FooPtrOps
&#123;
   bool operator&#40;&#41;&#40;const FooPtr &a, const FooPtr &b&#41; &#123;
      return a->x > b->x;
   &#125;

   void operator&#40;&#41;&#40;const FooPtr &a&#41; &#123;
      pspDebugScreenPrintf&#40;"%d\n", a->x&#41;;
   &#125;
&#125;;


void func&#40;&#41; &#123;
   std&#58;&#58;vector<FooPtr>          foo_vector;
   std&#58;&#58;set<FooPtr, FooPtrOps>  foo_set;

   FooPtr foo_ptr&#40;new Foo&#40;2&#41;&#41;;
   foo_vector.push_back&#40;foo_ptr&#41;;
   foo_set.insert&#40;foo_ptr&#41;;

   foo_ptr.reset&#40;new Foo&#40;1&#41;&#41;;
   foo_vector.push_back&#40;foo_ptr&#41;;
   foo_set.insert&#40;foo_ptr&#41;;

   foo_ptr.reset&#40;new Foo&#40;3&#41;&#41;;
   foo_vector.push_back&#40;foo_ptr&#41;;
   foo_set.insert&#40;foo_ptr&#41;;

   foo_ptr.reset &#40;new Foo&#40;2&#41;&#41;;
   foo_vector.push_back&#40;foo_ptr&#41;;
   foo_set.insert&#40;foo_ptr&#41;;

   pspDebugScreenPrintf&#40;"foo_vector&#58; \n"&#41;;
   std&#58;&#58;for_each&#40;foo_vector.begin&#40;&#41;, foo_vector.end&#40;&#41;, FooPtrOps&#40;&#41;&#41;;

   pspDebugScreenPrintf&#40;"\nfoo_set&#58;\n"&#41;;
   std&#58;&#58;for_each&#40;foo_set.begin&#40;&#41;, foo_set.end&#40;&#41;, FooPtrOps&#40;&#41;&#41;;
   pspDebugScreenPrintf&#40;"\n"&#41;;
&#125;

int main&#40;&#41; &#123;
   pspDebugScreenInit&#40;&#41;;
   func&#40;&#41;;
   sceKernelDelayThread&#40;5000 * 1000&#41;;
   sceKernelExitGame&#40;&#41;;
&#125;
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 :)
coolkehon
Posts: 355
Joined: Mon Oct 20, 2008 5:44 am

Post by coolkehon »

thanks you very much greatly appreciated
Post Reply