MRPT  2.0.1
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-2020, 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 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020