Main MRPT website > C++ reference for MRPT 1.9.9
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
18  * <mrpt/system/vector_loadsave.h>)
19  * \ingroup mrpt_base_grp
20  * @{ */
21 
22 /** A useful function for debugging, which saves a std::vector into a text file
23 * (compat. with MATLAB)
24 * \return Returns false on any error, true on everything OK.
25 */
26 bool vectorToTextFile(
27  const std::vector<float>& vec, const std::string& fileName,
28  bool append = false, bool byRows = false);
29 //! \overload
30 bool vectorToTextFile(
31  const std::vector<double>& vec, const std::string& fileName,
32  bool append = false, bool byRows = false);
33 //! \overload
34 bool vectorToTextFile(
35  const std::vector<int>& vec, const std::string& fileName,
36  bool append = false, bool byRows = false);
37 //! \overload
38 bool vectorToTextFile(
39  const std::vector<size_t>& vec, const std::string& fileName,
40  bool append = false, bool byRows = false);
41 //! \overload
42 template <class EIGEN_MATRIX>
43 bool vectorToTextFile(const EIGEN_MATRIX& vec, const std::string& fileName)
44 {
45  try
46  {
47  vec.saveToTextFile(fileName);
48  return true;
49  }
50  catch (...)
51  {
52  return false;
53  }
54 }
55 
56 /** Load a std::vector from a text file (compat. with MATLAB)
57 * \return Returns false on any error, true on everything OK.
58 * \sa loadBinaryFile
59 */
61  std::vector<double>& vec, const std::string& fileName,
62  const bool byRows = false);
63 
64 /** Saves a vector directly as a binary dump to a file:
65 * \return Returns false on any error, true on everything OK.
66 * \sa loadBinaryFile
67 */
68 bool vectorToBinaryFile(const vector_byte& vec, const std::string& fileName);
69 
70 /** Loads a entire file as a vector of bytes.
71 * \return Returns false on any error, true on everything OK.
72 * \sa vectorToBinaryFile
73 */
74 bool loadBinaryFile(vector_byte& out_data, const std::string& fileName);
75 
76 /** @} */
77 
78 } // End of namespace
79 } // End of namespace
std::vector< uint8_t > vector_byte
Definition: types_simple.h:27
bool 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:4101
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
bool vectorFromTextFile(std::vector< double > &vec, const std::string &fileName, const bool byRows=false)
Load a std::vector from a text file (compat.
bool 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 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.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019