NDArrayHelper.h
Go to the documentation of this file.
1 #pragma once
2 #include <string>
3 #include <vector>
4 
5 #include <SimoxUtility/algorithm/string.h>
6 
8 {
9 public:
10  // Uses the simox utility to parse floatingpoint and fixed precision types
11  // it then writes the result into a byte vector
12  // an empty byte vector encodes a parsing error.
13  template <typename T>
14  std::vector<unsigned char> static toByteVector(const std::string& str)
15  {
16  try
17  {
18  auto val = simox::alg::to_<T>(str);
19  std::vector<unsigned char> res(sizeof(val), 0);
20  T* reinterpPtr = reinterpret_cast<T*>(res.data());
21  T* laundered = std::launder(reinterpPtr);
22  *laundered = val;
23  return res;
24  }
25  catch (const simox::error::SimoxError& err)
26  {
27  return {};
28  }
29  }
30 };
str
std::string str(const T &t)
Definition: UserAssistedSegmenterGuiWidgetController.cpp:42
NDArrayHelper
Definition: NDArrayHelper.h:7
NDArrayHelper::toByteVector
static std::vector< unsigned char > toByteVector(const std::string &str)
Definition: NDArrayHelper.h:14
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35