TooN 2.1
internal/data.hh
00001 namespace TooN{
00002     namespace Internal{
00003         template<int N, class P> class Data;
00004     }
00005 
00006 
00007     ///@internal
00008     ///@brief Object which fills a matrix some data.
00009     ///There is no size known, since the size of the data is known at compile time.
00010     ///Therefore if the size of the matrix is not known, then something deeply strange is
00011     ///going on.
00012     ///@ingroup gInternal
00013     template<int N, class P> struct Operator<Internal::Data<N, P> >
00014     {
00015         P vals[N];
00016 
00017         template<int R, int C, class T, class B>
00018         void eval(Matrix<R, C, T, B>& m) const
00019         {
00020             SizeMismatch<(R==-1?-1:(C==-1?-1:(R*C))), N>:: test(m.num_rows()*m.num_cols(), N);
00021             for(int r=0, n=0; r < R; r++)
00022                 for(int c=0; c < C; c++, n++)
00023                     m[r][c] = vals[n];
00024         }
00025 
00026         template<int S, typename P2, typename B>
00027         void eval(Vector<S, P2, B>& v) const
00028         {
00029             SizeMismatch<S, N>::test(v.size(), N);
00030             for(int i=0; i <N; i++)
00031                 v[i] = vals[i];
00032         }
00033     };
00034 
00035     #ifdef DOXYGEN_INCLUDE_ONLY_FOR_DOCS
00036     
00037         ///Package up the function arguments as some data for filling matrices.
00038         ///Matrices are filled in row major order.
00039         ///For example:
00040         ///@code
00041         ///   double theta = 2;
00042         ///   Matrix<2> rotation = data( cos(theta), sin(theta)
00043         ///                             -sin(theta), cos(theta));
00044         ///@endcode
00045         ///See also TooN::wrapMatrix().
00046         ///@param a The first data element.
00047         ///@ingroup gLinAlg
00048         inline Operator<Internal::Data<N, double> > Data(double a, ...);
00049 
00050         ///Package up the function arguments as some data for filling matrices.
00051         ///Any type can be uses. Matrices are filled in row-major order.
00052         ///@code
00053         ///   Matrix<2,2,float> rotation = data(1f, 2f, 3f, 4f);
00054         ///@endcode
00055         ///See also TooN::wrapMatrix().
00056         ///@param a The first data element.
00057         ///@ingroup gLinAlg
00058         template<typename Precision> inline Operator<Internal::Data<N, Precision> > Data(const Precision& a, ...);
00059 
00060     #endif
00061 
00062 }