field_bones.hpp
Go to the documentation of this file.
00001 // Copyright (C) 2008-2011 NICTA (www.nicta.com.au)
00002 // Copyright (C) 2008-2011 Conrad Sanderson
00003 // Copyright (C) 2009-2010 Ian Cullinan
00004 // 
00005 // This file is part of the Armadillo C++ library.
00006 // It is provided without any warranty of fitness
00007 // for any purpose. You can redistribute this file
00008 // and/or modify it under the terms of the GNU
00009 // Lesser General Public License (LGPL) as published
00010 // by the Free Software Foundation, either version 3
00011 // of the License or (at your option) any later version.
00012 // (see http://www.opensource.org/licenses for more info)
00013 
00014 
00017 
00018 
00019 
00020 struct field_prealloc_n_elem
00021   {
00022   static const uword val = 16;
00023   };
00024 
00025 
00026 
00029 
00030 template<typename oT>
00031 class field
00032   {
00033   public:
00034   
00035   typedef oT object_type;
00036   
00037   const uword n_rows;     
00038   const uword n_cols;     
00039   const uword n_elem;     
00040   
00041   
00042   private:
00043   
00044   arma_aligned oT** mem;             
00045   arma_aligned oT*  mem_local[ field_prealloc_n_elem::val ];
00047   
00048   
00049   public:
00050   
00051   inline ~field();
00052   inline  field();
00053   
00054   inline                  field(const field& x);
00055   inline const field& operator=(const field& x);
00056   
00057   inline                  field(const subview_field<oT>& x);
00058   inline const field& operator=(const subview_field<oT>& x);
00059   
00060   inline explicit field(const uword n_elem_in);
00061   inline          field(const uword n_rows_in, const uword n_cols_in);
00062   
00063   inline void  set_size(const uword n_obj_in);
00064   inline void  set_size(const uword n_rows_in, const uword n_cols_in);
00065   
00066   template<typename oT2>
00067   inline void copy_size(const field<oT2>& x);
00068   
00069   arma_inline       oT& operator[](const uword i);
00070   arma_inline const oT& operator[](const uword i) const;
00071   
00072   arma_inline       oT&         at(const uword i);
00073   arma_inline const oT&         at(const uword i) const;
00074   
00075   arma_inline       oT& operator()(const uword i);
00076   arma_inline const oT& operator()(const uword i) const;
00077   
00078   arma_inline       oT&         at(const uword row, const uword col);
00079   arma_inline const oT&         at(const uword row, const uword col) const;
00080   
00081   arma_inline       oT& operator()(const uword row, const uword col);
00082   arma_inline const oT& operator()(const uword row, const uword col) const;
00083   
00084   inline field_injector<field> operator<<(const oT& val);
00085   inline field_injector<field> operator<<(const injector_end_of_row& x);
00086   
00087   
00088   inline       subview_field<oT> row(const uword row_num);
00089   inline const subview_field<oT> row(const uword row_num) const;
00090   
00091   inline       subview_field<oT> col(const uword col_num);
00092   inline const subview_field<oT> col(const uword col_num) const;
00093   
00094   inline       subview_field<oT> rows(const uword in_row1, const uword in_row2);
00095   inline const subview_field<oT> rows(const uword in_row1, const uword in_row2) const;
00096   
00097   inline       subview_field<oT> cols(const uword in_col1, const uword in_col2);
00098   inline const subview_field<oT> cols(const uword in_col1, const uword in_col2) const;
00099   
00100   inline       subview_field<oT> subfield(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2);
00101   inline const subview_field<oT> subfield(const uword in_row1, const uword in_col1, const uword in_row2, const uword in_col2) const;
00102   
00103   inline       subview_field<oT> subfield  (const span& row_span, const span& col_span);
00104   inline const subview_field<oT> subfield  (const span& row_span, const span& col_span) const;
00105   
00106   inline       subview_field<oT> operator()(const span& row_span, const span& col_span);
00107   inline const subview_field<oT> operator()(const span& row_span, const span& col_span) const;
00108   
00109   
00110   inline void print(const std::string extra_text = "") const;
00111   inline void print(std::ostream& user_stream, const std::string extra_text = "") const;
00112   
00113   inline void fill(const oT& x);
00114   
00115   inline void reset();
00116   inline void reset_objects();
00117   
00118   arma_inline bool is_empty() const;
00119   
00120   arma_inline arma_warn_unused bool in_range(const uword   i) const;
00121   arma_inline arma_warn_unused bool in_range(const span& x) const;
00122   
00123   arma_inline arma_warn_unused bool in_range(const uword   in_row,   const uword   in_col  ) const;
00124   arma_inline arma_warn_unused bool in_range(const span& row_span, const uword   in_col  ) const;
00125   arma_inline arma_warn_unused bool in_range(const uword   in_row,   const span& col_span) const;
00126   arma_inline arma_warn_unused bool in_range(const span& row_span, const span& col_span) const;
00127   
00128   inline bool save(const std::string   name, const file_type type = arma_binary, const bool print_status = true) const;
00129   inline bool save(      std::ostream& os,   const file_type type = arma_binary, const bool print_status = true) const;
00130   
00131   inline bool load(const std::string   name, const file_type type = auto_detect, const bool print_status = true);
00132   inline bool load(      std::istream& is,   const file_type type = auto_detect, const bool print_status = true);
00133   
00134   
00135   inline bool quiet_save(const std::string   name, const file_type type = arma_binary) const;
00136   inline bool quiet_save(      std::ostream& os,   const file_type type = arma_binary) const;
00137   
00138   inline bool quiet_load(const std::string   name, const file_type type = auto_detect);
00139   inline bool quiet_load(      std::istream& is,   const file_type type = auto_detect);
00140   
00141   
00142   // iterators
00143   
00144   class iterator
00145     {
00146     public:
00147     
00148     inline iterator(field<oT>& in_M, const bool at_end = false);
00149     
00150     inline oT& operator* ();
00151     
00152     inline iterator& operator++();
00153     inline void      operator++(int);
00154     
00155     inline iterator& operator--();
00156     inline void      operator--(int);
00157     
00158     inline bool operator!=(const iterator& X) const;
00159     inline bool operator==(const iterator& X) const;
00160     
00161     arma_aligned field<oT>& M;
00162     arma_aligned uword        i;
00163     };
00164   
00165   
00166   class const_iterator
00167     {
00168     public:
00169     
00170     const_iterator(const field<oT>& in_M, const bool at_end = false);
00171     const_iterator(const iterator& X);
00172     
00173     inline const oT& operator*() const;
00174     
00175     inline const_iterator& operator++();
00176     inline void            operator++(int);
00177     
00178     inline const_iterator& operator--();
00179     inline void            operator--(int);
00180     
00181     inline bool operator!=(const const_iterator& X) const;
00182     inline bool operator==(const const_iterator& X) const;
00183     
00184     arma_aligned const field<oT>& M;
00185     arma_aligned       uword        i;
00186     };
00187   
00188   inline       iterator begin();
00189   inline const_iterator begin() const;
00190   
00191   inline       iterator end();
00192   inline const_iterator end()   const;
00193   
00194   
00195   private:
00196   
00197   inline void init(const field<oT>& x);
00198   inline void init(const uword n_rows_in, const uword n_cols_in);
00199   
00200   inline void delete_objects();
00201   inline void create_objects();
00202   
00203   friend class field_aux;
00204   friend class subview_field<oT>;
00205   
00206   
00207   public:
00208   
00209   #ifdef ARMA_EXTRA_FIELD_PROTO
00210     #include ARMA_INCFILE_WRAP(ARMA_EXTRA_FIELD_PROTO)
00211   #endif
00212   };
00213 
00214 
00215 
00216 class field_aux
00217   {
00218   public:
00219   
00220   template<typename oT> inline static void reset_objects(field< oT >& x);
00221   template<typename eT> inline static void reset_objects(field< Mat<eT> >& x);
00222   template<typename eT> inline static void reset_objects(field< Col<eT> >& x);
00223   template<typename eT> inline static void reset_objects(field< Row<eT> >& x);
00224   template<typename eT> inline static void reset_objects(field< Cube<eT> >& x);
00225                         inline static void reset_objects(field< std::string >& x);
00226   
00227   
00228   template<typename oT> inline static bool save(const field< oT >& x,       const std::string& name, const file_type type, std::string& err_msg);
00229   template<typename oT> inline static bool save(const field< oT >& x,       std::ostream& os,        const file_type type, std::string& err_msg);
00230   template<typename oT> inline static bool load(      field< oT >& x,       const std::string& name, const file_type type, std::string& err_msg);
00231   template<typename oT> inline static bool load(      field< oT >& x,       std::istream& is,        const file_type type, std::string& err_msg);
00232 
00233   template<typename eT> inline static bool save(const field< Mat<eT> >& x,  const std::string& name, const file_type type, std::string& err_msg);
00234   template<typename eT> inline static bool save(const field< Mat<eT> >& x,  std::ostream& os,        const file_type type, std::string& err_msg);
00235   template<typename eT> inline static bool load(      field< Mat<eT> >& x,  const std::string& name, const file_type type, std::string& err_msg);
00236   template<typename eT> inline static bool load(      field< Mat<eT> >& x,  std::istream& is,        const file_type type, std::string& err_msg);
00237   
00238   template<typename eT> inline static bool save(const field< Col<eT> >& x,  const std::string& name, const file_type type, std::string& err_msg);
00239   template<typename eT> inline static bool save(const field< Col<eT> >& x,  std::ostream& os,        const file_type type, std::string& err_msg);
00240   template<typename eT> inline static bool load(      field< Col<eT> >& x,  const std::string& name, const file_type type, std::string& err_msg);
00241   template<typename eT> inline static bool load(      field< Col<eT> >& x,  std::istream& is,        const file_type type, std::string& err_msg);
00242   
00243   template<typename eT> inline static bool save(const field< Row<eT> >& x,  const std::string& name, const file_type type, std::string& err_msg);
00244   template<typename eT> inline static bool save(const field< Row<eT> >& x,  std::ostream& os,        const file_type type, std::string& err_msg);
00245   template<typename eT> inline static bool load(      field< Row<eT> >& x,  const std::string& name, const file_type type, std::string& err_msg);
00246   template<typename eT> inline static bool load(      field< Row<eT> >& x,  std::istream& is,        const file_type type, std::string& err_msg);
00247 
00248   template<typename eT> inline static bool save(const field< Cube<eT> >& x, const std::string& name, const file_type type, std::string& err_msg);
00249   template<typename eT> inline static bool save(const field< Cube<eT> >& x, std::ostream& os,        const file_type type, std::string& err_msg);
00250   template<typename eT> inline static bool load(      field< Cube<eT> >& x, const std::string& name, const file_type type, std::string& err_msg);
00251   template<typename eT> inline static bool load(      field< Cube<eT> >& x, std::istream& is,        const file_type type, std::string& err_msg);
00252   
00253   inline static bool save(const field< std::string >& x, const std::string& name, const file_type type, std::string& err_msg);
00254   inline static bool save(const field< std::string >& x, std::ostream& os,        const file_type type, std::string& err_msg);
00255   inline static bool load(      field< std::string >& x, const std::string& name, const file_type type, std::string& err_msg);
00256   inline static bool load(      field< std::string >& x, std::istream& is,        const file_type type, std::string& err_msg);
00257   
00258   };
00259 
00260 


armadillo_matrix
Author(s): Conrad Sanderson - NICTA (www.nicta.com.au), (Wrapper by Sjoerd van den Dries)
autogenerated on Tue Jan 7 2014 11:42:03