00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 #ifndef KMATRIX_HPP
00028 #define KMATRIX_HPP
00029 
00032 
00033 #include <vector>
00034 #include <string>
00035 #include <iostream>
00036 
00037 #include <kfilter/ktypes.hpp>
00038 
00039 namespace Kalman {
00040 
00042 
00071   template<typename T, K_UINT_32 BEG, bool DBG>
00072   class KMatrix {
00073   public:
00074 
00075     typedef T type;          
00076 
00077     enum { beg = BEG         
00078     };
00079 
00081 
00082 
00084     inline KMatrix();
00085 
00087     inline KMatrix(K_UINT_32 m, K_UINT_32 n);
00088 
00090     inline KMatrix(K_UINT_32 m, K_UINT_32 n, const T& a);
00091 
00093     inline KMatrix(K_UINT_32 m, K_UINT_32 n, const T* v);
00094 
00096     inline KMatrix(const KMatrix& M);
00097 
00099     inline ~KMatrix();
00100 
00102 
00104 
00105 
00107     inline T& operator()(K_UINT_32 i, K_UINT_32 j);
00108 
00110     inline const T& operator()(K_UINT_32 i, K_UINT_32 j) const;
00111 
00113     inline K_UINT_32 nrow() const;
00114 
00116     inline K_UINT_32 ncol() const;
00117 
00119 
00121     inline void resize(K_UINT_32 m, K_UINT_32 n);
00122 
00124     inline KMatrix& operator=(const T& a);
00125 
00127     inline KMatrix& operator=(const KMatrix& M);
00128 
00130     inline void assign(K_UINT_32 m, K_UINT_32 n, const T* v);
00131 
00133     inline void swap(KMatrix& M);
00134 
00136 
00137 
00139     inline void get(std::istream& is);
00140 
00142     inline void put(std::ostream& os) const;
00143 
00145 
00146   private:
00148 
00151     std::vector<T*> vimpl_;
00152     std::vector<T> Mimpl_;    
00153     
00155 
00160     T** M_;
00161     K_UINT_32 m_;             
00162     K_UINT_32 n_;             
00163 
00165     inline void init(K_UINT_32 m, K_UINT_32 n);
00166   };
00167 
00169   template<typename T, K_UINT_32 BEG, bool DBG>
00170   inline std::istream& operator>>(std::istream& is, 
00171                                   KMatrix<T, BEG, DBG>& M);
00172 
00174   template<typename T, K_UINT_32 BEG, bool DBG>
00175   inline std::ostream& operator<<(std::ostream& os, 
00176                                   const KMatrix<T, BEG, DBG>& M);
00177 
00179   typedef unsigned short KMatrixContext;
00180 
00182   extern KMatrixContext DEFAULT_MATRIX_CONTEXT;
00183 
00185   KMatrixContext createKMatrixContext(std::string elemDelim = " ", 
00186                                       std::string rowDelim = "\n",
00187                                       std::string startDelim = "", 
00188                                       std::string endDelim = "", 
00189                                       unsigned prec = 4);
00190 
00192   KMatrixContext selectKMatrixContext(KMatrixContext c);
00193 
00194 }
00195 
00196 #include <kfilter/kmatrix_impl.hpp>
00197 
00198 #endif