1 // Slightly modified Boost C++ library
\r
2 #include "scoped_ptr.hpp"
\r
3 #include "scoped_array.hpp"
\r
5 #include <memory> //auto_ptr
\r
13 using namespace ecrobot;
\r
19 #include "ecrobot_interface.h"
\r
22 // nxtOSEK hook to be invoked from an ISR in category 2
\r
23 void user_1ms_isr_type2(void)
\r
25 SleeperMonitor(); // needed for I2C device and Clock classes
\r
32 Foo(){ lcd.putf("sn", "Foo::Foo()"); }
\r
33 ~Foo(){ lcd.putf("sn", "Foo::~Foo()"); }
\r
37 void updateWaitReset(Clock& c)
\r
49 lcd.putf("sn", "new/delete");
\r
50 Foo *foo = new Foo();
\r
52 lcd.putf("x", (U32)foo,8);
\r
56 updateWaitReset(nxtClock);
\r
60 lcd.putf("sn", "auto_ptr");
\r
61 std::auto_ptr<Foo> autoPtr(new Foo());
\r
63 lcd.putf("x", (U32)autoPtr.get(),8);
\r
66 //autoPtr deleted automatically when the current scope ends
\r
69 updateWaitReset(nxtClock);
\r
71 //transfer from std::auto_ptr to boost::scoped_ptr
\r
73 lcd.putf("sn", "auto->scoped");
\r
74 std::auto_ptr<Foo> autoPtr(new Foo());
\r
77 //show that the raw pointer address is the same with get()
\r
78 lcd.putf("sxn", "autoPtr ", (U32)autoPtr.get(),8);
\r
79 boost::scoped_ptr<Foo> scopedPtr(autoPtr);
\r
80 lcd.putf("sx", "scpdPtr ", (U32)scopedPtr.get(),8);
\r
84 //scoped_ptr deleted automatically when the current scope ends
\r
87 updateWaitReset(nxtClock);
\r
89 //boost::scoped_array
\r
91 lcd.putf("sn", "scoped_array");
\r
92 boost::scoped_array<Foo> scopedArray(new Foo[2]);
\r
95 //scoped_array deleted automatically when the current scope ends
\r
98 updateWaitReset(nxtClock);
\r
100 lcd.putf("s", "Assert test");
\r
102 nxtClock.wait(2000);
\r
104 //should produce an assert for null deref
\r
105 boost::scoped_ptr<Foo> scopedPtr;
\r
106 scopedPtr->doNothing();
\r