MRPT  1.9.9
system/include/mrpt/system/vector_loadsave.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <string>
12 #include <vector>
13 
14 namespace mrpt::system
15 {
16 /** @defgroup vector_loadsave Load and save vectors to files
17  * Header: `#include <mrpt/system/vector_loadsave.h>`.
18  * Library: \ref mrpt_system_grp
19  * \ingroup mrpt_system_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 /** @} */
65 
66 } // namespace mrpt::system
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.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7e629e01a Sat Dec 14 00:05:55 2019 +0100 at sáb dic 14 00:15:10 CET 2019