00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef __EDELIB_EDBUSCONTAINER_H__
00022 #define __EDELIB_EDBUSCONTAINER_H__
00023
00024 #include "List.h"
00025
00026 EDELIB_NS_BEGIN
00027
00028 #ifndef SKIP_DOCS
00029 template <typename T>
00030 struct EdbusContainerImpl {
00031 list<T> lst;
00032 unsigned int ref;
00033 };
00034 #endif
00035
00051 template <typename T>
00052 class EdbusContainer {
00053 public:
00057 typedef typename list<T>::iterator iterator;
00058
00062 typedef typename list<T>::const_iterator const_iterator;
00063
00064 #ifndef SKIP_DOCS
00065 typedef EdbusContainerImpl<T> EdbusContainerPrivate;
00066 #endif
00067
00068 protected:
00072 EdbusContainerPrivate* impl;
00073
00077 void dispose(void) {
00078 if(!impl)
00079 return;
00080
00081 delete impl;
00082 impl = 0;
00083 }
00084
00090 void unhook(void) {
00091 E_ASSERT(impl != NULL);
00092
00093 if(impl->ref == 1)
00094 return;
00095
00096 EdbusContainerPrivate* new_one = new EdbusContainerPrivate;
00097 new_one->ref = 1;
00098
00099
00100
00101
00102
00103
00104
00105 if(impl->lst.size() > 0) {
00106 iterator it = impl->lst.begin(), it_end = impl->lst.end();
00107
00108 while(it != it_end) {
00109 new_one->lst.push_back(*it);
00110 ++it;
00111 }
00112 }
00113
00114 impl->ref--;
00115 impl = new_one;
00116 }
00117
00121 EdbusContainer() : impl(0) {
00122 impl = new EdbusContainerPrivate;
00123 impl->ref = 1;
00124 };
00125
00129 EdbusContainer(const EdbusContainer& other) {
00130 if(this == &other)
00131 return;
00132
00133 impl = other.impl;
00134 other.impl->ref++;
00135 }
00136
00141 ~EdbusContainer() {
00142 impl->ref--;
00143
00144 if(impl->ref == 0)
00145 dispose();
00146 }
00147
00151 EdbusContainer& operator=(const EdbusContainer& other) {
00152 other.impl->ref++;
00153 impl->ref--;
00154
00155 if(impl->ref == 0)
00156 dispose();
00157
00158 impl = other.impl;
00159 return *this;
00160 }
00161 };
00162
00163 EDELIB_NS_END
00164 #endif