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  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, 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 <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
GLsizei const GLchar ** string
Definition: glext.h:4101
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: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020