MFile_impl.hpp
Go to the documentation of this file.
1 #ifndef MFILE_IMPL_HPP
2 #define MFILE_IMPL_HPP
3 
4 #include <string>
5 
6 namespace Kalman {
7 
8 template<typename T, K_UINT_32 BEG, bool DBG>
9 inline int MFile::get(std::string name, KVector<T,BEG,DBG>& tmpvector)
10 {
11  unsigned int i;
12 
13  for(i=0; i<VectorMFileElement.size(); i++)
14  {
15  if (VectorMFileElement[i].Name == name)
16  break;
17  }
18 
19  if (i==VectorMFileElement.size())
20  return -1;
21 
22  if (VectorMFileElement[i].Cols>VectorMFileElement[i].Rows)
23  {
24  // Row vector
25  tmpvector.resize(VectorMFileElement[i].Cols);
26  for(unsigned int j=0; j<VectorMFileElement[i].Cols; j++)
27  {
28  tmpvector(BEG+j)=Data[VectorMFileElement[i].Index+j];
29  }
30  }
31  else
32  {
33  // Column vector
34  tmpvector.resize(VectorMFileElement[i].Rows);
35  for(unsigned int j=0; j<VectorMFileElement[i].Rows; j++)
36  {
37  tmpvector(BEG+j)=Data[VectorMFileElement[i].Index+j*VectorMFileElement[i].Cols];
38  }
39  }
40 
41  return 0;
42 }
43 
44 
45 template<typename T, K_UINT_32 BEG, bool DBG>
46 inline int MFile::get(std::string name, KMatrix<T,BEG,DBG>& tmpmatrix)
47 {
48  unsigned int i;
49 
50  for(i=0; i<VectorMFileElement.size(); i++)
51  {
52  if (VectorMFileElement[i].Name == name)
53  break;
54  }
55 
56  if (i==VectorMFileElement.size())
57  return -1;
58 
59  tmpmatrix.resize(VectorMFileElement[i].Rows, VectorMFileElement[i].Cols);
60 
61  for(unsigned int j=0; j<VectorMFileElement[i].Rows; j++)
62  {
63  for(unsigned int k=0; k<VectorMFileElement[i].Cols; k++)
64  {
65  tmpmatrix(BEG+j,BEG+k) = Data[VectorMFileElement[i].Index + j*VectorMFileElement[i].Cols + k];
66  }
67  }
68 
69  return 0;
70 }
71 
72 
73 template<typename T, K_UINT_32 BEG, bool DBG>
74 inline int MFile::add(std::string name, KVector<T,BEG,DBG>& tmpvector, int type)
75 {
76  unsigned int i;
77  MFileElement tmpElement;
78  double tmpdouble;
79 
80  for(i=0; i<VectorMFileElement.size(); i++)
81  {
82  if (VectorMFileElement[i].Name == name)
83  break;
84  }
85 
86  //Element exist!
87  if (i!=VectorMFileElement.size())
88  return -1;
89 
90  if (type == ROW_VECTOR)
91  {
92  tmpElement.Rows = 1;
93  tmpElement.Cols = tmpvector.size();
94  tmpElement.Name = name;
95  tmpElement.Index = Data.size();
96  }
97  else
98  {
99  tmpElement.Rows = tmpvector.size();
100  tmpElement.Cols = 1;
101  tmpElement.Name = name;
102  tmpElement.Index = Data.size();
103  }
104 
105  VectorMFileElement.push_back(tmpElement);
106 
107 
108  for(unsigned int i=0; i<tmpvector.size(); i++)
109  {
110  tmpdouble = tmpvector(BEG + i);
111  Data.push_back(tmpdouble);
112  }
113 
114  return 0;
115 }
116 
117 
118 template<typename T, K_UINT_32 BEG, bool DBG>
119 inline int MFile::add(std::string name, KMatrix<T,BEG,DBG>& tmpmatrix)
120 {
121  unsigned int i;
122  MFileElement tmpElement;
123  double tmpdouble;
124 
125 
126  for(i=0; i<VectorMFileElement.size(); i++)
127  {
128  if (VectorMFileElement[i].Name == name)
129  break;
130  }
131 
132  //Element exist!
133  if (i!=VectorMFileElement.size())
134  return -1;
135 
136  tmpElement.Rows = tmpmatrix.nrow();
137  tmpElement.Cols = tmpmatrix.ncol();
138  tmpElement.Name = name;
139  tmpElement.Index = Data.size();
140  VectorMFileElement.push_back(tmpElement);
141 
142  for(unsigned int i=0; i<tmpmatrix.nrow(); i++)
143  {
144  for(unsigned int j=0; j<tmpmatrix.ncol(); j++)
145  {
146  tmpdouble = tmpmatrix(BEG + i,BEG + j);
147  Data.push_back(tmpdouble);
148  }
149  }
150 
151  return 0;
152 }
153 
154 }
155 
156 #endif
K_UINT_32 nrow() const
Returns m_, the number of rows of the matrix.
void resize(K_UINT_32 n)
Resizes the vector. Resulting vector contents are undefined.
Minimalist vector template class.
Definition: kvector.hpp:72
int get(std::string name, Kalman::KVector< T, BEG, DBG > &tmpvector)
Definition: MFile_impl.hpp:9
unsigned int Rows
Definition: MFile.h:45
std::vector< double > Data
Definition: MFile.h:82
unsigned int Index
Definition: MFile.h:44
int add(std::string name, Kalman::KVector< T, BEG, DBG > &tmpvector, int type=ROW_VECTOR)
Definition: MFile_impl.hpp:74
unsigned int Cols
Definition: MFile.h:46
std::vector< MFileElement > VectorMFileElement
Definition: MFile.h:81
std::string Name
Definition: MFile.h:47
void resize(K_UINT_32 m, K_UINT_32 n)
Resizes the matrix. Resulting matrix contents are undefined.
Minimalist matrix template class.
Definition: kmatrix.hpp:72
K_UINT_32 ncol() const
Returns n_, the number of columns of the matrix.
K_UINT_32 size() const
Returns the vector size.
#define ROW_VECTOR
Definition: MFile.h:39


kfilter
Author(s): Jorge Almeida, Vincent Zalzal, Sylvain Marleau, Richard Gourdeau
autogenerated on Mon Mar 2 2015 01:31:45