00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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
00052
00053
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
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
00097 CommaInitializer();
00098 protected:
00099 MAT& m_mat;
00100 const value_type m_val;
00101 mutable bool m_wipeOnDestruct;
00102 };
00103
00104 }
00105
00106 #if _MSC_VER
00107 # pragma warning( pop )
00108 #endif // EXMAT_VC
00109
00110 #endif // _EXMAT_COMMAINIT_H
00111