Example for SharedPointer usage
- Author
- woelk
#include <Base/Common/SharedPtr.hh>
#include <iostream>
#include <vector>
#include <string>
using namespace BIAS;
using namespace std;
class foo {
public:
virtual ~foo() {};
int i;
double d;
};
std::ostream&
operator<<(std::ostream& os,
const foo& arg)
{ os << arg.i<<" "<<arg.d; return os; }
class uta : public foo {
public:
virtual ~uta() {};
string name;
};
std::ostream&
operator<<(std::ostream& os,
const uta& arg)
{ os << arg.i<<" "<<arg.d<<" "<<arg.name; return os; }
int main(int argc, char *argv[])
{
cout <<
"reference count of p_foo: "<<
RefCount(p_foo)<<endl;
p_foo->i = 5;
(*p_foo).d = 3.1415;
cout << "content of p_foo: "<<*p_foo<<endl;
if (p_foo2){
cout << "simple test for NULL pointer : (p_foo2) \n"
<< "content of p_foo2: "<<*p_foo2<<endl;
}
if (p_foo == p_foo2)
cout << "p_foo and p_foo2 point ot the same object: reference count "
else
cout << "this cannot happen\n";
cout <<
"re-assigned p_foo2: reference count "<<
RefCount(p_foo)<<endl;
pc_foo = ConstCast<const foo>(p_foo);
p_uta->i=2;
p_uta->d=2.0*3.1415;
p_uta->name="diogenes";
p_foo2 = DynamicCast<foo>(p_uta);
if (p_foo2 == p_uta)
cout << "p_uta and p_foo2 point to the same object: ref count "
<< " content of p_foo2: "<<*p_foo2<<endl;
else
cerr << "this will not happen\n";
if (p_uta2)
cout << "*p_uta2: "<<*p_uta2<<endl;
return 0;
}