Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <list>
- template <typename T> void ProxyNoOp(T *) {}
- template <typename T> void ProxyDelete(T * ptrT) {delete ptrT;}
- template <typename T, typename C, void (* Release)(T *) = ProxyNoOp<T> >
- class Proxy
- {
- public:
- class Container : public std::list<T *>
- {
- public:
- Container() {}
- ~Container() {clear();}
- void clear()
- {
- typename Container::iterator clsEnd = this->end();
- for (typename Container::iterator clsCurrent = this->begin(); clsCurrent != clsEnd; ++clsCurrent)
- {
- T * ptrT = *clsCurrent;
- static_cast<Proxy *>(ptrT)->m_ptrContainer = NULL;
- Release(ptrT);
- }
- }
- };
- private:
- typename Container::iterator m_clsPosition;
- C * m_ptrContainer;
- public:
- Proxy() : m_ptrContainer(NULL) {}
- ~Proxy()
- {
- if ( m_ptrContainer != NULL )
- {
- Container * ptrContainer = static_cast<Container *>(m_ptrContainer);
- static_cast<typename Container::Range *>(ptrContainer)->erase(m_clsPosition);
- }
- }
- C * GetContainer() const {return m_ptrContainer;}
- };
- #if 0
- class Child;
- class Parent : public Proxy<Child, Parent>::Container {};
- class Child: public Proxy<Child, Parent> {};
- #endif
- class Parent;
- class Child : public Proxy<Child, Parent> {};
- class Parent : public Proxy<Child, Parent>::Container {};
Advertisement
Add Comment
Please, Sign In to add comment