Main MRPT website > C++ reference
MRPT logo
vector_loadsave.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2015, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <mrpt/utils/utils_defs.h>
12 
13 namespace mrpt
14 {
15  namespace system
16  {
17  /** A useful function for debugging, which saves a std::vector into a text file (compat. with MATLAB)
18  * \return Returns false on any error, true on everything OK.
19  */
20  bool BASE_IMPEXP vectorToTextFile( const std::vector<float> &vec, const std::string &fileName, bool append = false, bool byRows=false );
21  //! \overload
22  bool BASE_IMPEXP vectorToTextFile( const std::vector<double> &vec, const std::string &fileName, bool append = false, bool byRows=false );
23  //! \overload
24  bool BASE_IMPEXP vectorToTextFile( const std::vector<int> &vec, const std::string &fileName, bool append = false, bool byRows=false );
25  //! \overload
26  bool BASE_IMPEXP vectorToTextFile( const std::vector<size_t> &vec, const std::string &fileName, bool append = false, bool byRows=false );
27  //! \overload
28  template <class EIGEN_MATRIX>
29  bool vectorToTextFile( const EIGEN_MATRIX &vec, const std::string &fileName ) {
30  try {
31  vec.saveToTextFile(fileName);
32  return true;
33  } catch(...) {return false;}
34  }
35 
36  /** Load a std::vector from a text file (compat. with MATLAB)
37  * \return Returns false on any error, true on everything OK.
38  * \sa loadBinaryFile
39  */
40  bool BASE_IMPEXP vectorFromTextFile( std::vector<double> &vec, const std::string &fileName, const bool byRows=false );
41 
42  /** Saves a vector directly as a binary dump to a file:
43  * \return Returns false on any error, true on everything OK.
44  * \sa loadBinaryFile
45  */
46  bool BASE_IMPEXP vectorToBinaryFile( const vector_byte &vec, const std::string &fileName );
47 
48  /** Loads a entire file as a vector of bytes.
49  * \return Returns false on any error, true on everything OK.
50  * \sa vectorToBinaryFile
51  */
52  bool BASE_IMPEXP loadBinaryFile( vector_byte &out_data, const std::string &fileName );
53 
54 
55  } // End of namespace
56 } // End of namespace
bool BASE_IMPEXP loadBinaryFile(vector_byte &out_data, const std::string &fileName)
Loads a entire file as a vector of bytes.
bool BASE_IMPEXP vectorFromTextFile(std::vector< double > &vec, const std::string &fileName, const bool byRows=false)
Load a std::vector from a text file (compat.
std::vector< uint8_t > vector_byte
Definition: types_simple.h:23
bool BASE_IMPEXP vectorToTextFile(const std::vector< float > &vec, const std::string &fileName, bool append=false, bool byRows=false)
A useful function for debugging, which saves a std::vector into a text file (compat.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool BASE_IMPEXP vectorToBinaryFile(const vector_byte &vec, const std::string &fileName)
Saves a vector directly as a binary dump to a file:



Page generated by Doxygen 1.8.9.1 for MRPT 1.3.0 SVN: at Sun Sep 13 03:55:12 UTC 2015