OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
toString.h File Reference
#include <cxxabi.h>
#include <chrono>
#include <iostream>
#include <set>
#include <sstream>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "sqldefs.h"
+ Include dependency graph for toString.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  anonymous_namespace{toString.h}::has_toString< T, typename >
 
struct  anonymous_namespace{toString.h}::has_toString< T, decltype(std::declval< T >().toString(), void())>
 
struct  anonymous_namespace{toString.h}::get_has_toString< T, typename >
 
struct  anonymous_namespace{toString.h}::has_printTo< T, typename >
 
struct  anonymous_namespace{toString.h}::has_printTo< T, decltype(std::declval< T >().printTo(std::declval< std::ostream & >()), void())>
 

Namespaces

 anonymous_namespace{toString.h}
 

Macros

#define HAVE_TOSTRING
 
#define __FILENAME__   (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
 
#define PRINT(EXPR)
 

Functions

template<typename T >
std::string typeName (const T *v)
 
template<typename T , typename... Args>
std::string typeName (T(*v)(Args...args))
 
template<typename T >
struct get_has_toString< T,
decltype(std::declval< T >
().get() -> 
anonymous_namespace{toString.h}::toString ()
 
template<typename T >
std::string toString (const T &v)
 
template<typename T1 , typename T2 >
std::string toString (const std::pair< T1, T2 > &v)
 
template<typename T >
std::string toString (const std::vector< T > &v)
 
template<typename T1 , typename T2 >
std::string toString (const std::unordered_map< T1, T2 > &v)
 
template<typename T >
std::string toString (const std::list< T > &v)
 
template<typename T >
std::string toString (const std::unordered_set< T > &v)
 
template<typename T >
std::string toString (const std::set< T > &v)
 
template<typename T >
std::string toString (const std::tuple< T, T > &v)
 

Variables

template<class T >
constexpr bool anonymous_namespace{toString.h}::has_toString_v = has_toString<T>::value
 
template<class T >
struct get_has_toString< T,
decltype(std::declval< T >
().get() -> void())> constexpr
bool 
anonymous_namespace{toString.h}::get_has_toString_v = get_has_toString<T>::value
 
template<class T >
constexpr bool anonymous_namespace{toString.h}::has_printTo_v = has_printTo<T>::value
 

Macro Definition Documentation

#define __FILENAME__   (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)

Definition at line 79 of file toString.h.

#define HAVE_TOSTRING

Definition at line 39 of file toString.h.

#define PRINT (   EXPR)
Value:
std::cout << std::hex \
<< ((std::hash<std::thread::id>()(std::this_thread::get_id())) & 0xffff) \
<< std::dec << " [" << __FILENAME__ << ":" << __func__ << "#" << __LINE__ \
<< "]: " #EXPR "=" << ::toString(EXPR) << std::endl \
<< std::flush;
std::string toString(const ExtArgumentType &sig_type)
#define __FILENAME__
Definition: toString.h:79

Definition at line 80 of file toString.h.

Function Documentation

template<typename T >
std::string toString ( const T &  v)

Definition at line 165 of file toString.h.

References ANTI, i, INNER, INVALID, LEFT, SEMI, omnisci.dtypes::T, to_string(), toString(), typeName(), and UNREACHABLE.

165  {
166  if constexpr (std::is_same_v<T, std::string>) { // NOLINT
167  return "\"" + v + "\"";
168 #ifdef ENABLE_TOSTRING_RAPIDJSON
169  } else if constexpr (std::is_same_v<T, rapidjson::Value>) { // NOLINT
170  rapidjson::StringBuffer buffer;
171  rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
172  v.Accept(writer);
173  return buffer.GetString();
174 #endif
175 #ifdef ENABLE_TOSTRING_LLVM
176  } else if constexpr (std::is_same_v<T, llvm::Module>) { // NOLINT
177  std::string type_str;
178  llvm::raw_string_ostream rso(type_str);
179  v.print(rso, nullptr);
180  return "(" + rso.str() + ")";
181  } else if constexpr (std::is_same_v<T, llvm::Function>) { // NOLINT
182  std::string type_str;
183  llvm::raw_string_ostream rso(type_str);
184  v.print(rso, nullptr);
185  return "(" + rso.str() + ")";
186  } else if constexpr (std::is_same_v<T, llvm::Value>) { // NOLINT
187  std::string type_str;
188  llvm::raw_string_ostream rso(type_str);
189  v.print(rso);
190  return "(" + rso.str() + ")";
191  } else if constexpr (std::is_same_v<T, llvm::Argument>) { // NOLINT
192  std::string type_str;
193  llvm::raw_string_ostream rso(type_str);
194  v.print(rso);
195  return "(" + rso.str() + ")";
196  } else if constexpr (std::is_same_v<T, llvm::Type>) { // NOLINT
197  std::string type_str;
198  llvm::raw_string_ostream rso(type_str);
199  v.print(rso);
200  return "(" + rso.str() + ")";
201  } else if constexpr (std::is_same_v<T, llvm::Triple>) { // NOLINT
202  return v.str();
203  } else if constexpr (std::is_same_v<T, llvm::opt::ArgStringList>) { // NOLINT
204  std::string r;
205  for (unsigned i = 0; i < v.size(); i++) {
206  if (i) {
207  r += ", ";
208  }
209  r += v[i];
210  }
211  return "[" + r + "]";
212  } else if constexpr (std::is_same_v<T, llvm::opt::DerivedArgList>) { // NOLINT
213  std::string r;
214  for (unsigned i = 0; i < v.getNumInputArgStrings(); i++) {
215  if (i) {
216  r += ", ";
217  }
218  r += v.getArgString(i);
219  }
220  return "[" + r + "]";
221  } else if constexpr (std::is_same_v<T, clang::driver::JobList>) { // NOLINT
222  std::string type_str;
223  llvm::raw_string_ostream rso(type_str);
224  v.Print(rso, nullptr, true);
225  return rso.str();
226 #endif
227  } else if constexpr (std::is_same_v<T, bool>) { // NOLINT
228  return v ? "True" : "False";
229  } else if constexpr (std::is_arithmetic_v<T>) { // NOLINT
230  return std::to_string(v);
231 #ifdef ENABLE_TOSTRING_str
232  } else if constexpr (has_str_v<T>) { // NOLINT
233  return v.str();
234 #endif
235 #ifdef ENABLE_TOSTRING_to_string
236  } else if constexpr (has_to_string_v<T>) { // NOLINT
237  return v.to_string();
238 #endif
239  } else if constexpr (has_toString_v<T>) { // NOLINT
240  return v.toString();
241  } else if constexpr (get_has_toString_v<T>) {
242  auto ptr = v.get();
243  return (ptr == NULL ? "NULL" : "&" + ptr->toString());
244  } else if constexpr (std::is_same_v<T, void*>) {
245  std::ostringstream ss;
246  ss << std::hex << (uintptr_t)v;
247  return "0x" + ss.str();
248  } else if constexpr (std::is_same_v<
249  T,
250  std::chrono::time_point<std::chrono::system_clock>>) {
251  std::string s(30, '\0');
252  auto converted_v = (std::chrono::time_point<std::chrono::system_clock>)v;
253  std::time_t ts = std::chrono::system_clock::to_time_t(v);
254  std::strftime(&s[0], s.size(), "%Y-%m-%d %H:%M:%S", std::localtime(&ts));
255  return s + "." +
256  std::to_string((converted_v.time_since_epoch().count() / 1000) % 1000000);
257  } else if constexpr (std::is_same_v<T, JoinType>) {
258  switch (v) {
259  case JoinType::INNER:
260  return "INNER";
261  case JoinType::LEFT:
262  return "LEFT";
263  case JoinType::SEMI:
264  return "SEMI";
265  case JoinType::ANTI:
266  return "ANTI";
267  case JoinType::INVALID:
268  return "INVALID";
269  }
270  UNREACHABLE();
271  return "";
272  } else if constexpr (std::is_pointer_v<T>) {
273  return (v == NULL ? "NULL" : "&" + toString(*v));
274  } else if constexpr (has_printTo_v<T>) {
275  std::ostringstream ss;
276  v.printTo(ss);
277  return ss.str();
278  } else {
279  return typeName(&v);
280  }
281 }
std::string toString(const ExtArgumentType &sig_type)
#define UNREACHABLE()
Definition: Logger.h:253
std::string to_string(char const *&&v)
std::string typeName(const T *v)
Definition: toString.h:88

+ Here is the call graph for this function:

template<typename T1 , typename T2 >
std::string toString ( const std::pair< T1, T2 > &  v)

Definition at line 284 of file toString.h.

References toString().

284  {
285  return "(" + toString(v.first) + ", " + toString(v.second) + ")";
286 }
std::string toString(const ExtArgumentType &sig_type)

+ Here is the call graph for this function:

template<typename T >
std::string toString ( const std::vector< T > &  v)

Definition at line 289 of file toString.h.

References i, run_benchmark_import::result, and toString().

289  {
290  auto result = std::string("[");
291  for (size_t i = 0; i < v.size(); ++i) {
292  if (i) {
293  result += ", ";
294  }
295  result += toString(v[i]);
296  }
297  result += "]";
298  return result;
299 }
std::string toString(const ExtArgumentType &sig_type)

+ Here is the call graph for this function:

template<typename T1 , typename T2 >
std::string toString ( const std::unordered_map< T1, T2 > &  v)

Definition at line 302 of file toString.h.

References i, run_benchmark_import::result, and toString().

302  {
303  auto result = std::string("{");
304  size_t i = 0;
305  for (const auto& p : v) {
306  if (i) {
307  result += ", ";
308  }
309  result += toString(p);
310  i++;
311  }
312  result += "}";
313  return result;
314 }
std::string toString(const ExtArgumentType &sig_type)

+ Here is the call graph for this function:

template<typename T >
std::string toString ( const std::list< T > &  v)

Definition at line 317 of file toString.h.

References i, run_benchmark_import::result, and toString().

317  {
318  auto result = std::string("[");
319  size_t i = 0;
320  for (const auto& p : v) {
321  if (i) {
322  result += ", ";
323  }
324  result += toString(p);
325  i++;
326  }
327  result += "]";
328  return result;
329 }
std::string toString(const ExtArgumentType &sig_type)

+ Here is the call graph for this function:

template<typename T >
std::string toString ( const std::unordered_set< T > &  v)

Definition at line 332 of file toString.h.

References i, run_benchmark_import::result, and toString().

332  {
333  auto result = std::string("{");
334  size_t i = 0;
335  for (const auto& p : v) {
336  if (i) {
337  result += ", ";
338  }
339  result += toString(p);
340  i++;
341  }
342  result += "}";
343  return result;
344 }
std::string toString(const ExtArgumentType &sig_type)

+ Here is the call graph for this function:

template<typename T >
std::string toString ( const std::set< T > &  v)

Definition at line 347 of file toString.h.

References i, run_benchmark_import::result, and toString().

347  {
348  auto result = std::string("{");
349  size_t i = 0;
350  for (const auto& p : v) {
351  if (i) {
352  result += ", ";
353  }
354  result += toString(p);
355  i++;
356  }
357  result += "}";
358  return result;
359 }
std::string toString(const ExtArgumentType &sig_type)

+ Here is the call graph for this function:

template<typename T >
std::string toString ( const std::tuple< T, T > &  v)

Definition at line 362 of file toString.h.

References omnisci.dtypes::T, and toString().

362  {
363  T left, right;
364  std::tie(left, right) = v;
365  return std::string("(") + toString(left) + ", " + toString(right) + ")";
366 }
std::string toString(const ExtArgumentType &sig_type)

+ Here is the call graph for this function:

template<typename T >
std::string typeName ( const T *  v)

Definition at line 88 of file toString.h.

References setup::name, and omnisci.dtypes::T.

Referenced by com.omnisci.jdbc.OmniSciConnection::createArrayOf(), com.mapd.calcite.parser.MapDTypeSystem::getMaxPrecision(), com.mapd.parser.extension.ddl.omnisci.OmniSciTypeNameSpec::OmniSciTypeNameSpec(), ColumnList< T >::operator[](), InputDescriptor::toString(), ColumnDescriptor::toString(), ExecutionResult::toString(), RexAbstractInput::toString(), InputColDescriptor::toString(), Chunk_NS::Chunk::toString(), TableFunctionExecutionUnit::toString(), toString(), ResultSet::toString(), RexOperator::toString(), RexSubQuery::toString(), RexInput::toString(), RexCase::toString(), RexFunctionOperator::toString(), SortField::toString(), RexWindowFunctionOperator::toString(), RexRef::toString(), RexAgg::toString(), RelScan::toString(), RelProject::toString(), RelAggregate::toString(), RelJoin::toString(), RelTranslatedJoin::toString(), RelFilter::toString(), RelLeftDeepInnerJoin::toString(), RelCompound::toString(), RelSort::toString(), RelModify::toString(), RelTableFunction::toString(), RelLogicalValues::toString(), and RelLogicalUnion::toString().

88  {
89  std::stringstream stream;
90  int status;
91 #ifdef _WIN32
92  stream << std::string(typeid(T).name());
93 #else
94  char* demangled = abi::__cxa_demangle(typeid(T).name(), 0, 0, &status);
95  stream << std::string(demangled);
96  free(demangled);
97 #endif
98  return stream.str();
99 }
string name
Definition: setup.in.py:72

+ Here is the caller graph for this function:

template<typename T , typename... Args>
std::string typeName ( T(*)(Args...args)  v)

Definition at line 102 of file toString.h.

References setup::name.

102  {
103  std::stringstream stream;
104  int status;
105 #ifdef _WIN32
106  stream << std::string(typeid(v).name());
107 #else
108  char* demangled = abi::__cxa_demangle(typeid(v).name(), 0, 0, &status);
109  stream << std::string(demangled);
110  free(demangled);
111 #endif
112  stream << "@0x" << std::hex << (uintptr_t)(reinterpret_cast<const void*>(v));
113  return stream.str();
114 }
string name
Definition: setup.in.py:72