123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- #pragma once
- #include <vector>
- #include <list>
- #include "XDWExclusiveHolder.tlh"
- #include "XDWExclusiveHolder.tli"
- #include "Iterator.tlh"
- //-----------------------------------------------------------------------------
- // ExclusiveList
- //-----------------------------------------------------------------------------
- template <class T>
- class ExclusiveList : public XDWExclusiveHolder <std::list <T> >
- {
- typedef XDWExclusiveHolder <std::list <T> > inherited;
- public:
- using container = std::list <T>;
- using reference = typename std::list <T>::reference;
- using const_reference = typename std::list <T>::const_reference;
- using const_iterator = typename std::list <T>::const_iterator;
- public:
- ExclusiveList ()
- {
- Attach (new std::list <T> ());
- }
- public:
- bool IsEmpty () const
- {
- LockHolder Lock (this);
- if (m_pObject == NULL) return true;
- return m_pObject->empty ();
- }
- template <class Action> void LockForEach (Action action)
- {
- LockHolder holder (this);
- for (auto Iter = Iterator::From (holder.As ()); Iter; Iter ++)
- {
- action (Iter ());
- }
- }
- template <class Action> int LockForEachIf (Action action)
- {
- LockHolder holder (this);
- for (auto Iter = Iterator::From (holder.As ()); Iter; Iter ++)
- {
- if (! action (Iter ()))
- return Iter.Index ();
- }
- return -1;
- }
- };
- //-----------------------------------------------------------------------------
- // ExclusiveVector
- //-----------------------------------------------------------------------------
- template <class T>
- class ExclusiveVector : public XDWExclusiveHolder <std::vector <T> >
- {
- typedef XDWExclusiveHolder <std::vector <T> > inherited;
- public:
- using container = std::vector <T>;
- using reference = typename std::vector <T>::reference;
- using const_reference = typename std::vector <T>::const_reference;
- using const_iterator = typename std::vector <T>::const_iterator;
- public:
- ExclusiveVector ()
- {
- Attach (new std::vector <T> ());
- }
- public:
- bool IsEmpty () const
- {
- LockHolder Lock (this);
- if (m_pObject == NULL) return true;
- return m_pObject->empty ();
- }
- template <class Action> void LockForEach (Action action)
- {
- LockHolder holder (this);
- for (auto Iter = Iterator::From (holder.As ()); Iter; Iter ++ )
- {
- action (Iter ());
- }
- }
- template <class Action> int LockForEachIf (Action action)
- {
- LockHolder holder (this);
- for (auto Iter = Iterator::From (holder.As ()); Iter; Iter++)
- {
- if (! action (Iter ()))
- return Iter.Index ();
- }
- return -1;
- }
- };
|