cpp-common
common.impl.hh
Go to the documentation of this file.
1 // -*- mode: c++; c-basic-offset: 2; -*-
2 
9 #include "nvsl/common.hh"
10 #include "nvsl/string.hh"
11 
12 inline std::string nvsl::ns_to_latex(size_t ns, const std::string &name,
13  nvsl::time_unit unit) {
14  std::string result = "";
15  size_t us, ms, s;
16 
17  const auto name_fixed = nvsl::zip(nvsl::split(name, "_"), "");
18 
19  us = ns / 100;
20  ms = ns / 100000;
21  s = ns / 100000000;
22 
23  switch (unit) {
24  case nvsl::time_unit::s_unit:
25  result = to_latex(name_fixed, ns, "~s", 1000000000);
26  break;
27  case nvsl::time_unit::ms_unit:
28  result = to_latex(name_fixed, ns, "~ms", 1000000);
29  break;
30  case nvsl::time_unit::us_unit:
31  result = to_latex(name_fixed, ns, "~\\us{}", 1000);
32  break;
33  case nvsl::time_unit::ns_unit:
34  result = to_latex(name_fixed, ns, "~ns", 1);
35  break;
36  case nvsl::time_unit::any_unit:
37  if (s != 0)
38  result = to_latex(name_fixed, ns, "~s", 1000000000);
39  else if (ms != 0)
40  result = to_latex(name_fixed, ns, "~ms", 1000000);
41  else if (us != 0)
42  result = to_latex(name_fixed, ns, "~\\us{}", 1000);
43  else
44  result = to_latex(name_fixed, ns, "~ns", 1);
45  break;
46  }
47 
48  return result;
49 }
nvsl::zip
auto zip(const std::vector< std::string > arr, const std::string join_str)
Concat all the elements of a string vector into a stingle string.
Definition: string.hh:42
common.hh
Common macros, constexpr and function definitions.
string.hh
Usefult string functions. Mostly resemble python's.