• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/collection/Association.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #ifndef _association_h
00018 #define _association_h
00019 
00020 #include <spl/Debug.h>
00021 #include <spl/Memory.h>
00022 
00029 template<typename KT, typename VT>
00030 class Association : public IMemoryValidate
00031 {
00032 protected:
00033         KT m_key;
00034         VT m_val;
00035 
00036 public:
00037         inline Association()
00038         : m_key(), m_val()
00039         {
00040         }
00041 
00042         inline Association(KT key, VT val)
00043         : m_key(key), m_val(val)
00044         {
00045         }
00046 
00047         inline Association(const Association& assoc)
00048         : m_key(assoc.m_key), m_val(assoc.m_val)
00049         {
00050         }
00051 
00052         virtual ~Association()
00053         {
00054         }
00055 
00056         inline KT Key()
00057         {
00058                 return m_key;
00059         }
00060 
00061         inline VT Value()
00062         {
00063                 return m_val;
00064         }
00065 
00066         inline KT& KeyRef()
00067         {
00068                 return m_key;
00069         }
00070 
00071         inline VT& ValueRef()
00072         {
00073                 return m_val;
00074         }
00075 
00076         inline Association<KT, VT>& operator =(const Association<KT, VT>& a)
00077         {
00078                 m_key = a.m_key;
00079                 m_val = a.m_val;
00080 
00081                 return *this;
00082         }
00083 
00084 #ifdef DEBUG
00085         virtual void ValidateMem() const
00086         {
00087                 ValidateType( m_key );
00088                 ValidateType( m_val );
00089         }
00090 
00091         virtual void CheckMem() const
00092         {
00093                 ValidateType( m_key );
00094                 ValidateType( m_val );
00095         }
00096 #endif
00097 };
00098 
00101 #endif