Main MRPT website > C++ reference for MRPT 1.9.9
vector_loadsave.cpp
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 
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 }
mrpt::io
Definition: img/CImage.h:22
s
GLdouble s
Definition: glext.h:3676
vector_loadsave.h
CFileOutputStream.h
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
CFileInputStream.h
mrpt::io::loadBinaryFile
bool loadBinaryFile(std::vector< uint8_t > &out_data, const std::string &fileName)
Loads a entire file as a vector of bytes.
Definition: system/src/vector_loadsave.cpp:20
mrpt::io::CFileInputStream
This CStream derived class allow using a file as a read-only, binary stream.
Definition: io/CFileInputStream.h:23
mrpt::io::loadTextFile
bool loadTextFile(std::vector< std::string > &o, const std::string &fileName)
Loads a text file as a vector of string lines.
Definition: system/src/vector_loadsave.cpp:58
mrpt::io::CFileOutputStream
This CStream derived class allow using a file as a write-only, binary stream.
Definition: io/CFileOutputStream.h:24
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::io::vectorToBinaryFile
bool vectorToBinaryFile(const std::vector< uint8_t > &vec, const std::string &fileName)
Saves a vector directly as a binary dump to a file:
Definition: system/src/vector_loadsave.cpp:43
io-precomp.h



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST