Main MRPT website > C++ reference for MRPT 1.9.9
test.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 
11 #include <mrpt/io/zip.h>
12 #include <mrpt/system/CTicTac.h>
13 #include <mrpt/core/format.h>
14 #include <cstdio>
15 #include <iostream>
16 
17 using namespace mrpt;
18 using namespace std;
19 
20 // ------------------------------------------------------
21 // MAIN
22 // ------------------------------------------------------
23 int main(int argc, char** argv)
24 {
25  try
26  {
27  if (argc < 2)
28  {
29  cerr << "Usage: test-compress <input_file> [compression level 1-9]"
30  << endl;
31  return -1;
32  }
33 
34  std::vector<uint8_t> buf;
35 
36  if (!mrpt::io::loadBinaryFile(buf, argv[1]))
37  {
38  cerr << "Error loading file: " << argv[1] << endl;
39  return -1;
40  }
41 
42  string gzfile = format("%s.gz", argv[1]);
43  int compress_level = 9;
44  if (argc >= 3)
45  {
46  compress_level = atoi(argv[2]);
47  }
48  mrpt::system::CTicTac tictac;
49 
50  tictac.Tic();
51 
52  if (!mrpt::io::zip::compress_gz_file(gzfile, buf, compress_level))
53  {
54  cerr << "Error writing compressing file: " << gzfile << endl;
55  return -1;
56  }
57 
58  double t = tictac.Tac();
59  cout << format(
60  "Compressed %s (compress level=%i) in %.04f seconds.",
61  gzfile.c_str(), compress_level, t)
62  << endl;
63 
64  return 0;
65  }
66  catch (std::exception& e)
67  {
68  std::cout << "MRPT exception caught: " << e.what() << std::endl;
69  return -1;
70  }
71  catch (...)
72  {
73  printf("Untyped exception!!");
74  return -1;
75  }
76 }
mrpt::io::zip::compress_gz_file
bool compress_gz_file(const std::string &file_path, const std::vector< uint8_t > &buffer, const int compress_level=9)
Compress a memory buffer into a gzip file (xxxx.gz).
Definition: zip.cpp:234
t
GLdouble GLdouble t
Definition: glext.h:3689
vector_loadsave.h
mrpt::system::CTicTac
A high-performance stopwatch, with typical resolution of nanoseconds.
Definition: system/CTicTac.h:19
format.h
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::system::CTicTac::Tac
double Tac() noexcept
Stops the stopwatch.
Definition: CTicTac.cpp:90
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
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::format
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
mrpt::system::CTicTac::Tic
void Tic() noexcept
Starts the stopwatch.
Definition: CTicTac.cpp:79
CTicTac.h
zip.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