Simple Application Framework  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Saf/Ref.h
Go to the documentation of this file.
00001 /*
00002     This file is part of Simple Application Framework (Saf) library.
00003     Copyright (C) 2010 - 2012 Ondrej Danek <ondrej.danek@gmail.com>
00004 
00005     This library is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published 
00007     by the Free Software Foundation, either version 3 of the License, or
00008     (at your option) any later version.
00009 
00010     Saf is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with Simple Application Framework library. If not, 
00017     see <http://www.gnu.org/licenses/>.
00018 */
00019 
00028 #ifndef SAF_REF_H
00029 #define SAF_REF_H
00030 
00031 namespace Saf
00032 {
00034     namespace Internal
00035     {
00037         template <class T>
00038         class RefWrapper
00039         {
00040         private:
00042             T* m_ptr;
00043 
00044         public:
00046             explicit RefWrapper(T& val)
00047                 : m_ptr(&val)
00048             {}
00049 
00051             operator T& () const 
00052             { 
00053                 return *m_ptr; 
00054             }
00055 
00057             T& Ref() const
00058             { 
00059                 return *m_ptr; 
00060             }
00061 
00063             T* Ptr() const
00064             { 
00065                 return m_ptr; 
00066             }
00067         };
00068     }
00072     template <class T>
00073     inline Internal::RefWrapper<T> Ref(T& val)
00074     {
00075         return Internal::RefWrapper<T>(val);
00076     }
00077 
00079     template <class T>
00080     inline Internal::RefWrapper<T const> ConstRef(T const &val)
00081     {
00082         return Internal::RefWrapper<T const>(val);
00083     }
00084 }
00085 
00086 #endif