edelib 2.1.0
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
26EDELIB_NS_BEGIN
27
28#ifndef SKIP_DOCS
29template <typename T>
30struct EdbusContainerImpl {
31 list<T> lst;
32 unsigned int ref;
33};
34#endif
35
51template <typename T>
53public:
57 typedef typename list<T>::iterator iterator;
58
63
64#ifndef SKIP_DOCS
65 typedef EdbusContainerImpl<T> EdbusContainerPrivate;
66#endif
67
68protected:
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
130 if(this == &other)
131 return;
132
133 impl = other.impl;
134 other.impl->ref++;
135 }
136
142 impl->ref--;
143
144 if(impl->ref == 0)
145 dispose();
146 }
147
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
163EDELIB_NS_END
164#endif
Abstract container for D-Bus containers.
Definition: EdbusContainer.h:52
EdbusContainerPrivate * impl
Definition: EdbusContainer.h:72
EdbusContainer & operator=(const EdbusContainer &other)
Definition: EdbusContainer.h:151
EdbusContainer()
Definition: EdbusContainer.h:121
EdbusContainer(const EdbusContainer &other)
Definition: EdbusContainer.h:129
list< T >::const_iterator const_iterator
Definition: EdbusContainer.h:62
list< T >::iterator iterator
Definition: EdbusContainer.h:57
void dispose(void)
Definition: EdbusContainer.h:77
void unhook(void)
Definition: EdbusContainer.h:90
~EdbusContainer()
Definition: EdbusContainer.h:141
Linked list class.
Definition: List.h:160
#define E_ASSERT(expr)
Definition: Debug.h:117