MRPT  1.9.9
vector_loadsave.cpp
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 
10 #include "io-precomp.h" // Precompiled headers
11 
15 
16 using namespace mrpt;
17 using namespace mrpt::io;
18 using namespace std;
19 
21  std::vector<uint8_t>& out_data, const std::string& fileName)
22 {
23  try
24  {
25  CFileInputStream fi(fileName);
26  size_t N = fi.getTotalBytesCount();
27 
28  out_data.resize(N);
29  if (N)
30  {
31  size_t NN = fi.Read(&out_data[0], N);
32  return NN == N;
33  }
34  else
35  return true;
36  }
37  catch (...)
38  {
39  return false;
40  }
41 }
42 
44  const std::vector<uint8_t>& vec, const std::string& fileName)
45 {
46  try
47  {
48  mrpt::io::CFileOutputStream of(fileName);
49  if (!vec.empty()) of.Write(&vec[0], sizeof(vec[0]) * vec.size());
50  return true;
51  }
52  catch (...)
53  {
54  return false;
55  }
56 }
57 
59  std::vector<std::string>& o, const std::string& fileName)
60 {
61  o.clear();
62  std::ifstream f(fileName);
63  if (!f.is_open()) return false;
64  std::string s;
65  while (std::getline(f, s)) o.emplace_back(std::move(s));
66  return true;
67 }
bool vectorToBinaryFile(const std::vector< uint8_t > &vec, const std::string &fileName)
Saves a vector directly as a binary dump to a file:
STL namespace.
GLdouble s
Definition: glext.h:3682
bool loadBinaryFile(std::vector< uint8_t > &out_data, const std::string &fileName)
Loads a entire file as a vector of bytes.
This CStream derived class allow using a file as a read-only, binary stream.
bool loadTextFile(std::vector< std::string > &o, const std::string &fileName)
Loads a text file as a vector of string lines.
This CStream derived class allow using a file as a write-only, binary stream.
GLsizei const GLchar ** string
Definition: glext.h:4116
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019