Commainit.h

Go to the documentation of this file.
00001 /*
00002  * Expression Template Matrix Library
00003  *
00004  * Copyright (C) 2004 - 2006 Ricky Lung <mtlung@users.sourceforge.net>
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  */
00021 
00022 
00030 #ifdef _MSC_VER
00031 #   pragma once
00032 #   pragma warning( push )
00033 #   pragma warning( disable : 4512 4786 )
00034 #endif  // _MSC_VER
00035 
00036 #ifndef _EXMAT_COMMAINIT_H
00037 #define _EXMAT_COMMAINIT_H
00038 
00039 namespace exmat {
00040 
00041 template<class MAT>
00042 class CommaInitHelper {
00043     typedef CommaInitHelper<MAT>            self_type;
00044     typedef typename MAT::const_param_type  const_param_type;
00045     typedef typename MAT::iterator          iterator;
00046     typedef typename MAT::ErrChecker        ErrChecker;
00047 public:
00048     EXMAT_INLINE2 CommaInitHelper(iterator iter, const MAT& mat)
00049         : m_iter(iter), m_mat(mat) {}
00050     EXMAT_INLINE2 self_type operator,(const_param_type val) {
00051 //      ErrChecker::Assert
00052 //          (unsigned(m_iter-m_mat.begin()) < unsigned(m_mat.rows()*m_mat.cols()),
00053 //          CommaInitOutOfBoundErrMsg);
00054         *m_iter = val;
00055         return self_type(++m_iter, m_mat);
00056     }
00057 private:
00058     CommaInitHelper();
00059 protected:
00060     iterator m_iter;
00061     const MAT& m_mat;
00062 };
00063 
00065 
00068 template<class MAT>
00069 class CommaInitializer {
00070     typedef typename MAT::value_type        value_type;
00071     typedef typename MAT::const_param_type  const_param_type;
00072     typedef typename MAT::iterator          iterator;
00073     typedef typename MAT::ErrChecker        ErrChecker;
00074 
00075 public:
00076     EXMAT_INLINE2 CommaInitializer(MAT& mat, const_param_type val)
00077         : m_mat(mat), m_val(val), m_wipeOnDestruct(true)
00078     {}
00079 
00080     EXMAT_INLINE2 ~CommaInitializer() {
00081         if(m_wipeOnDestruct)
00082             m_mat.ScalarInit(m_val);
00083     }
00084 
00085     EXMAT_INLINE2 CommaInitHelper<MAT> operator,(const_param_type val) {
00086         // !-- May not needed, since it may not be possible to create zero sized container
00087         ErrChecker::Assert(m_mat.rows() > 0 && m_mat.cols() > 0, "Zero size container being initialized!\n");
00088         m_wipeOnDestruct = false;
00089         iterator it1 = m_mat.begin();
00090         *it1 = m_val;
00091         *(++it1) = val;
00092         return CommaInitHelper<MAT>(++it1, m_mat);
00093     }
00094 
00095 private:
00096     // Disable the default constructor
00097     CommaInitializer();
00098 protected:
00099     MAT& m_mat;
00100     const value_type m_val;
00101     mutable bool m_wipeOnDestruct;
00102 };
00103 
00104 }   // namespace exmat
00105 
00106 #if _MSC_VER
00107 #   pragma warning( pop )
00108 #endif  // EXMAT_VC
00109 
00110 #endif  // _EXMAT_COMMAINIT_H
00111 

Generated on Sat May 6 23:11:55 2006 for Exmat by  doxygen 1.4.6-NO