edelib 2.1.0

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List

EdbusContainer.h
1 /*
2 * $Id: EdbusContainer.h 2839 2009-09-28 11:36:20Z karijes $
3 *
4 * D-BUS stuff
5 * Copyright (c) 2008 edelib authors
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #ifndef __EDELIB_EDBUSCONTAINER_H__
22 #define __EDELIB_EDBUSCONTAINER_H__
23
24 #include "List.h"
25
26 EDELIB_NS_BEGIN
27
28 #ifndef SKIP_DOCS
29 template <typename T>
30 struct EdbusContainerImpl {
31 list<T> lst;
32 unsigned int ref;
33 };
34 #endif
35
51 template <typename T>
52 class EdbusContainer {
53 public:
57 typedef typename list<T>::iterator iterator;
58
62 typedef typename list<T>::const_iterator const_iterator;
63
64 #ifndef SKIP_DOCS
65 typedef EdbusContainerImpl<T> EdbusContainerPrivate;
66 #endif
67
68 protected:
72 EdbusContainerPrivate* impl;
73
77 void dispose(void) {
78 if(!impl)
79 return;
80
81 delete impl;
82 impl = 0;
83 }
84
90 void unhook(void) {
91 E_ASSERT(impl != NULL);
92
93 if(impl->ref == 1)
94 return;
95
96 EdbusContainerPrivate* new_one = new EdbusContainerPrivate;
97 new_one->ref = 1;
98
99 /*
100 * Copy the content
101 *
102 * edelib::list does not have implemented copy operator
103 * and that is the way I like
104 */
105 if(impl->lst.size() > 0) {
106 iterator it = impl->lst.begin(), it_end = impl->lst.end();
107
108 while(it != it_end) {
109 new_one->lst.push_back(*it);
110 ++it;
111 }
112 }
113
114 impl->ref--;
115 impl = new_one;
116 }
117
121 EdbusContainer() : impl(0) {
122 impl = new EdbusContainerPrivate;
123 impl->ref = 1;
124 };
125
129 EdbusContainer(const EdbusContainer& other) {
130 if(this == &other)
131 return;
132
133 impl = other.impl;
134 other.impl->ref++;
135 }
136
141 ~EdbusContainer() {
142 impl->ref--;
143
144 if(impl->ref == 0)
145 dispose();
146 }
147
151 EdbusContainer& operator=(const EdbusContainer& other) {
152 other.impl->ref++;
153 impl->ref--;
154
155 if(impl->ref == 0)
156 dispose();
157
158 impl = other.impl;
159 return *this;
160 }
161 };
162
163 EDELIB_NS_END
164 #endif
edelib::EdbusContainer::~EdbusContainer
~EdbusContainer()
Definition: EdbusContainer.h:141
E_ASSERT
#define E_ASSERT(expr)
Definition: Debug.h:117
edelib::list
Linked list class.
Definition: List.h:160
edelib::EdbusContainer::EdbusContainer
EdbusContainer(const EdbusContainer &other)
Definition: EdbusContainer.h:129
edelib::EdbusContainer::dispose
void dispose(void)
Definition: EdbusContainer.h:77
edelib::EdbusContainer::impl
EdbusContainerPrivate * impl
Definition: EdbusContainer.h:72
edelib::EdbusContainer::const_iterator
list< T >::const_iterator const_iterator
Definition: EdbusContainer.h:62
edelib::EdbusContainer::operator=
EdbusContainer & operator=(const EdbusContainer &other)
Definition: EdbusContainer.h:151
edelib::EdbusContainer::unhook
void unhook(void)
Definition: EdbusContainer.h:90
edelib::EdbusContainer::iterator
list< T >::iterator iterator
Definition: EdbusContainer.h:57
edelib::EdbusContainer
Abstract container for D-Bus containers.
Definition: EdbusContainer.h:52
edelib::EdbusContainer::EdbusContainer
EdbusContainer()
Definition: EdbusContainer.h:121