Base.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2009 NICTA
00002 // 
00003 // Authors:
00004 // - Conrad Sanderson (conradsand at ieee dot org)
00005 // 
00006 // This file is part of the Armadillo C++ library.
00007 // It is provided without any warranty of fitness
00008 // for any purpose. You can redistribute this file
00009 // and/or modify it under the terms of the GNU
00010 // Lesser General Public License (LGPL) as published
00011 // by the Free Software Foundation, either version 3
00012 // of the License or (at your option) any later version.
00013 // (see http://www.opensource.org/licenses for more info)
00014 
00015 
00016 //! \addtogroup Base
00017 //! @{
00018 
00019 
00020 //! Class for static polymorphism, modelled after the "Curiously Recurring Template Pattern" (CRTP).
00021 //! Used for type-safe downcasting in functions that restrict their input(s) to be classes that are
00022 //! derived from Base (e.g. Mat, Op, Glue, diagview, subview).
00023 //! A Base object can be converted to a Mat object by the unwrap class.
00024 
00025 template<typename elem_type, typename derived>
00026 struct Base
00027   {
00028   
00029   arma_inline
00030   const derived&
00031   get_ref() const
00032     {
00033     return static_cast<const derived&>(*this);
00034     }
00035 
00036   };
00037 
00038 
00039 
00040 template<typename elem_type, typename derived_vec>
00041 struct Base_vec
00042   {
00043   
00044   arma_inline
00045   const derived_vec&
00046   get_ref() const
00047     {
00048     return static_cast<const derived_vec&>(*this);
00049     }
00050 
00051   };
00052 
00053 
00054 
00055 //! @}