Advertisement
Guest User

map_ref

a guest
Dec 30th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. template<typename _TKey, typename _TValue>
  2. class map_ref
  3. {
  4.     public:
  5.         typedef _TKey TKey;
  6.         typedef _TValue TValue;
  7.         typedef std::map<_TKey, _TValue> TContainer;
  8.         typedef typename TContainer::iterator iterator;
  9.         typedef typename TContainer::const_iterator const_iterator;
  10.  
  11.  
  12.     public:
  13.         TContainer& Get()       { return m_Container; }
  14.         operator TContainer&()  { return m_Container; }
  15.  
  16.         TContainer* operator->()                { return &m_Container; }
  17.         TContainer const* operator->() const    { return &m_Container; }
  18.  
  19.         TValue& operator[](_TKey const& _key)               { return m_Container[_key]; }
  20.         TValue const& operator[](_TKey const& _key) const   { return m_Container[_key]; }
  21.  
  22.         bool ContainsKey(_TKey const& _key) const
  23.         {
  24.             TContainer::const_iterator iteContainer = m_Container.find(_key);
  25.             return iteContainer != m_Container.end();
  26.         }
  27.  
  28.         bool Find(_TKey const& _key, TValue& _rValue) const
  29.         {
  30.             TContainer::const_iterator iteContainer = m_Container.find(_key);
  31.             if ( iteContainer == m_Container.end() )
  32.                 return false;
  33.  
  34.             _rValue = iteContainer->second;
  35.             return true;
  36.         }
  37.  
  38.         template<typename T_FUNCTOR>
  39.         void ForEach(T_FUNCTOR _functor) const
  40.         {
  41.             TContainer::const_iterator iteContainer = m_Container.begin();
  42.             for ( ; iteContainer != m_Container.end() ; iteContainer++ )
  43.             {
  44.                 _functor(iteContainer->first, iteContainer->second);
  45.             }
  46.         }
  47.  
  48.  
  49.     private:
  50.         TContainer m_Container;
  51. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement