Files Classes Functions Hierarchy
00001 #include <iostream> 00002 using namespace std; 00003 00004 #include <singletontest.h> 00005 00006 #include <singleton.h> 00007 00008 00009 class singletontest_hat 00010 { 00011 public: 00012 00013 int data; 00014 00015 singletontest_hat() : data(0) {} 00016 00017 singletontest_hat(int data_) : data(data_) {} 00018 ~singletontest_hat() { cout << "~singletontest_hat() data=" << data << endl; } 00019 00020 template<class T> 00021 void print(T t) 00022 { 00023 cout << "singletontest_hat::print<T>(T t) t=" << t << endl; 00024 } 00025 }; 00026 00027 class singletontest_cat 00028 { 00029 public: 00030 00031 int data; 00032 singletontest_cat() : data(0) {} 00033 singletontest_cat(int data_) : data(data_) {} 00034 00035 void print() const 00036 { cout << "singletontest_cat data=" << data << endl; } 00037 00038 ~singletontest_cat() { cout << "~singletontest_cat::print() data=" << data << endl; } 00039 }; 00040 00041 00042 00043 00044 void singletontest01() 00045 { 00046 singletontest_cat c(23); 00047 cout << "Creating a singleton singletontest_cat object" << endl; 00048 cout << "This does not destruct the singletontest_cat when there "; 00049 cout << "are no references." << endl; 00050 { 00051 SingletonPtr<singletontest_cat> init(&c); 00052 } 00053 00054 cout << "Try accessing the singletontest_cat's print function." << endl; 00055 SingletonPtr<singletontest_cat>()->print(); 00056 00057 cout << endl << endl; 00058 00059 cout << "Reference count test" << endl; 00060 cout << "The singletontest_hat object is constructed and should be " << endl; 00061 cout << "destructed imediately when this singleton dies" << endl; 00062 00063 // Call delete on singletontest_hat(32) when out of scope. 00064 { 00065 SingletonPtr<singletontest_hat> (new singletontest_hat(32),SingletonPtr<singletontest_hat>::nonarray); 00066 } 00067 cout << "There are no longer any SingletonPtr<singletontest_hat> objects alive" << endl; 00068 00069 cout << endl; 00070 cout << "Reference Count test on arrays" << endl; 00071 cout << "Call delete[] when no SingletonPtr's exist" << endl; 00072 { 00073 SingletonPtr<singletontest_hat> (new singletontest_hat[5],SingletonPtr<singletontest_hat>::array); 00074 } 00075 cout << "The destructors for 5 singletontest_hat objects should have been called" << endl; 00076 } 00077 00078
1.5.8