Main MRPT website > C++ reference for MRPT 1.5.7
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-2017, 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  /** @defgroup vector_loadsave Load and save vectors to files (in #include <mrpt/system/vector_loadsave.h>)
18  * \ingroup mrpt_base_grp
19  * @{ */
20 
21  /** A useful function for debugging, which saves a std::vector into a text file (compat. with MATLAB)
22  * \return Returns false on any error, true on everything OK.
23  */
24  bool BASE_IMPEXP vectorToTextFile( const std::vector<float> &vec, const std::string &fileName, bool append = false, bool byRows=false );
25  //! \overload
26  bool BASE_IMPEXP vectorToTextFile( const std::vector<double> &vec, const std::string &fileName, bool append = false, bool byRows=false );
27  //! \overload
28  bool BASE_IMPEXP vectorToTextFile( const std::vector<int> &vec, const std::string &fileName, bool append = false, bool byRows=false );
29  //! \overload
30  bool BASE_IMPEXP vectorToTextFile( const std::vector<size_t> &vec, const std::string &fileName, bool append = false, bool byRows=false );
31  //! \overload
32  template <class EIGEN_MATRIX>
33  bool vectorToTextFile( const EIGEN_MATRIX &vec, const std::string &fileName ) {
34  try {
35  vec.saveToTextFile(fileName);
36  return true;
37  } catch(...) {return false;}
38  }
39 
40  /** Load a std::vector from a text file (compat. with MATLAB)
41  * \return Returns false on any error, true on everything OK.
42  * \sa loadBinaryFile
43  */
44  bool BASE_IMPEXP vectorFromTextFile( std::vector<double> &vec, const std::string &fileName, const bool byRows=false );
45 
46  /** Saves a vector directly as a binary dump to a file:
47  * \return Returns false on any error, true on everything OK.
48  * \sa loadBinaryFile
49  */
50  bool BASE_IMPEXP vectorToBinaryFile( const vector_byte &vec, const std::string &fileName );
51 
52  /** Loads a entire file as a vector of bytes.
53  * \return Returns false on any error, true on everything OK.
54  * \sa vectorToBinaryFile
55  */
56  bool BASE_IMPEXP loadBinaryFile( vector_byte &out_data, const std::string &fileName );
57 
58  /** @} */
59 
60  } // End of namespace
61 } // End of namespace
std::vector< uint8_t > vector_byte
Definition: types_simple.h:26
bool BASE_IMPEXP vectorToBinaryFile(const vector_byte &vec, const std::string &fileName)
Saves a vector directly as a binary dump to a file:
GLsizei const GLchar ** string
Definition: glext.h:3919
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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.
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.
bool BASE_IMPEXP loadBinaryFile(vector_byte &out_data, const std::string &fileName)
Loads a entire file as a vector of bytes.



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019