00001 /* vim: set sw=2: 00002 * Copyright (c) 2009, Gennady Bystritsky <bystr@mac.com> 00003 * 00004 * Distributed under the MIT Licence. 00005 * This is free software. See 'LICENSE' for details. 00006 * You must read and accept the license prior to use. 00007 * 00008 * Author: Gennady Bystritsky (gennady.bystritsky@quest.com) 00009 */ 00010 00011 #ifndef _SK_RT_SYNCHRONIZEDCOLLECTION_HXX_ 00012 #define _SK_RT_SYNCHRONIZEDCOLLECTION_HXX_ 00013 00014 #include <sk/util/Collection.hxx> 00015 #include <sk/util/Holder.hxx> 00016 #include <sk/rt/Mutex.h> 00017 00018 namespace sk { 00019 namespace rt { 00020 template<typename T> 00021 class SynchronizedCollection 00022 : public virtual sk::util::Collection<T> 00023 { 00024 public: 00025 SynchronizedCollection(sk::util::Collection<T>& collection); 00026 SynchronizedCollection(sk::util::Collection<T>* collection); 00027 ~SynchronizedCollection(); 00028 00029 T& get(const Selector<T>& selector) const; 00030 void forEach(const Processor<T>& procesor) const; 00031 bool find(sk::util::Holder<T>& holder, const Selector<T>& selector) const; 00032 bool isEmpty() const; 00033 int size() const; 00034 bool contains(const T& object) const; 00035 bool contains(const Selector<T>& selector) const; 00036 bool containsAll(const Collection<T>& other) const; 00037 bool add(T& object); 00038 bool add(T* object); 00039 bool addAll(const Collection<T>& other); 00040 bool moveAll(Collection<T>& other); 00041 void clear(); 00042 bool remove(const T& object); 00043 bool remove(const Selector<T>& selector); 00044 T* cutoff(const T& object); 00045 T* cutoff(const Selector<T>& selector); 00046 T* release(const T& object); 00047 T* release(const Selector<T>& selector); 00048 bool removeAll(const Collection<T>& other); 00049 bool removeAll(const Selector<T>& selector); 00050 bool retainAll(const Collection<T>& other); 00051 bool retainAll(const Selector<T>& selector); 00052 00053 protected: 00054 sk::rt::Mutex _mutex; 00055 00056 private: 00057 SynchronizedCollection(const SynchronizedCollection<T>& other); 00058 SynchronizedCollection<T>& operator = (const SynchronizedCollection<T>& other); 00059 00060 sk::util::Holder<sk::uitl::Collection<T> > _collectionHolder; 00061 sk::uitl::Collection<T>& _collection; 00062 }; 00063 } 00064 } 00065 00066 #endif /* _SK_RT_SYNCHRONIZEDCOLLECTION_HXX_ */