Main MRPT website > C++ reference for MRPT 1.5.9
printf_vector.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-2017, 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 <mrpt/math/eigen_frwds.h>
12 #include <string>
13 #include <vector>
14 #include <cstdio>
15 
16 namespace mrpt
17 {
18  namespace utils
19  {
20  /** \addtogroup
21  * @{ */
22 
23  /** Generates a string for a vector in the format [A,B,C,...] to std::cout, and the fmt string for <b>each</b> vector element. */
24  template <typename T>
25  std::string sprintf_vector(const char *fmt, const std::vector<T> &V )
26  {
27  std::string ret = "[";
28  const size_t N = V.size();
29  for (size_t i=0;i<N;i++)
30  {
31  ret+= format(fmt,V[i]);
32  if (i!=(N-1)) ret+= ",";
33  }
34  ret+="]";
35  return ret;
36  }
37  /// @overload
38  template <typename Derived>
39  std::string sprintf_vector(const char *fmt, const Eigen::MatrixBase<Derived> &V )
40  {
41  std::string ret = "[";
42  const size_t N = V.size();
43  for (size_t i=0;i<N;i++)
44  {
45  ret+= format(fmt,V[i]);
46  if (i!=(N-1)) ret+= ",";
47  }
48  ret+="]";
49  return ret;
50  }
51 
52  /** Prints a vector in the format [A,B,C,...] to std::cout, and the fmt string for <b>each</b> vector element. */
53  template <typename T>
54  void printf_vector(const char *fmt, const std::vector<T> &V ) {
55  ::fputs(sprintf_vector(fmt, V).c_str(),stdout);
56  }
57 
58  /** @} */ // end of grouping
59  }
60 }
std::string sprintf_vector(const char *fmt, const std::vector< T > &V)
Generates a string for a vector in the format [A,B,C,...] to std::cout, and the fmt string for each v...
Definition: printf_vector.h:25
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:21
GLsizei const GLchar ** string
Definition: glext.h:3919
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void printf_vector(const char *fmt, const std::vector< T > &V)
Prints a vector in the format [A,B,C,...] to std::cout, and the fmt string for each vector element...
Definition: printf_vector.h:54



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020