btftoolchain
util.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <fstream>
4 #include <iostream>
5 #include <string>
6 
7 namespace helper
8 {
9 namespace util
10 {
17 std::string wstrTostr(const std::wstring& in);
18 
25 std::wstring strTowstr(const std::string& in);
26 
32 void getline(std::ifstream& file, std::string& out);
33 
37 template <typename To, typename From> To safe_dynamic_cast(From src) noexcept
38 {
39  To to{nullptr};
40  try
41  {
42  to = dynamic_cast<To>(src);
43  }
44  catch (...)
45  {
46  to = nullptr;
47  }
48 
49  if (to == nullptr)
50  {
51  std::cout << "Fatal Error: dynamic cast failed" << std::endl;
52  std::terminate();
53  }
54  return to;
55 }
56 
57 } // namespace util
58 } // namespace helper
std::string wstrTostr(const std::wstring &in)
Converts a wstirng to string.
Definition: util.cpp:7
std::wstring strTowstr(const std::string &in)
Converts a string to wstring.
Definition: util.cpp:14
void getline(std::ifstream &file, std::string &out)
wrapper for std::getline that removes CR (\r) at the end of the line.
Definition: util.cpp:21
To safe_dynamic_cast(From src) noexcept
Template to enable a safe dynamic cast by catching nullptr.
Definition: util.h:37
Definition: logging.h:27