EdbusContainer.h
/*
* $Id: EdbusContainer.h 2839 2009-09-28 11:36:20Z karijes $
*
* D-BUS stuff
* Copyright (c) 2008 edelib authors
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __EDELIB_EDBUSCONTAINER_H__
#define __EDELIB_EDBUSCONTAINER_H__
#include "List.h"
EDELIB_NS_BEGIN
#ifndef SKIP_DOCS
template <typename T>
struct EdbusContainerImpl {
list<T> lst;
unsigned int ref;
};
#endif
template <typename T>
class EdbusContainer {
public:
typedef typename list<T>::iterator iterator;
typedef typename list<T>::const_iterator const_iterator;
#ifndef SKIP_DOCS
typedef EdbusContainerImpl<T> EdbusContainerPrivate;
#endif
protected:
EdbusContainerPrivate* impl;
void dispose(void) {
if(!impl)
return;
delete impl;
impl = 0;
}
void unhook(void) {
E_ASSERT(impl != NULL);
if(impl->ref == 1)
return;
EdbusContainerPrivate* new_one = new EdbusContainerPrivate;
new_one->ref = 1;
/*
* Copy the content
*
* edelib::list does not have implemented copy operator
* and that is the way I like
*/
if(impl->lst.size() > 0) {
iterator it = impl->lst.begin(), it_end = impl->lst.end();
while(it != it_end) {
new_one->lst.push_back(*it);
++it;
}
}
impl->ref--;
impl = new_one;
}
EdbusContainer() : impl(0) {
impl = new EdbusContainerPrivate;
impl->ref = 1;
};
EdbusContainer(const EdbusContainer& other) {
if(this == &other)
return;
impl = other.impl;
other.impl->ref++;
}
~EdbusContainer() {
impl->ref--;
if(impl->ref == 0)
dispose();
}
EdbusContainer& operator=(const EdbusContainer& other) {
other.impl->ref++;
impl->ref--;
if(impl->ref == 0)
dispose();
impl = other.impl;
return *this;
}
};
EDELIB_NS_END
#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