OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
toString.h File Reference
#include <cxxabi.h>
#include <cassert>
#include <chrono>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "sqldefs.h"
#include <mutex>
+ 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(...)
 

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 T1 , typename T2 >
std::string toString (const std::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... Ts, size_t... Is>
std::string toStringImpl (const std::tuple< Ts...> &t, const std::index_sequence< 0, Is...>)
 
template<typename... T>
std::string toStringImpl (const std::tuple<> &t, const std::index_sequence<>)
 
template<typename... Ts>
std::string toString (const std::tuple< Ts...> &t)
 

Variables

static std::mutex toString_PRINT_mutex
 
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 90 of file toString.h.

#define HAVE_TOSTRING

Definition at line 39 of file toString.h.

#define PRINT (   ...)
Value:
{ \
std::lock_guard<std::mutex> print_lock(toString_PRINT_mutex); \
std::cout << std::hex \
<< ((std::hash<std::thread::id>()(std::this_thread::get_id())) & 0xffff) \
<< std::dec << " [" << __FILENAME__ << ":" << __func__ << "#" << __LINE__ \
<< "]: " #__VA_ARGS__ "=" << ::toString(std::make_tuple(__VA_ARGS__)) \
<< std::endl \
<< std::flush; \
}
static std::mutex toString_PRINT_mutex
Definition: toString.h:88
std::string toString(const ExecutorDeviceType &device_type)
#define __FILENAME__
Definition: toString.h:90

Definition at line 91 of file toString.h.

Function Documentation

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

Definition at line 180 of file toString.h.

References ANTI, INNER, INVALID, LEFT, SEMI, heavydb.dtypes::T, to_string(), toString(), typeName(), WINDOW_FUNCTION, and WINDOW_FUNCTION_FRAMING.

180  {
181  if constexpr (std::is_same_v<T, std::string>) { // NOLINT
182  return "\"" + v + "\"";
183 #ifdef ENABLE_TOSTRING_RAPIDJSON
184  } else if constexpr (std::is_same_v<T, rapidjson::Value>) { // NOLINT
185  rapidjson::StringBuffer buffer;
186  rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
187  v.Accept(writer);
188  return buffer.GetString();
189 #endif
190 #ifdef ENABLE_TOSTRING_LLVM
191  } else if constexpr (std::is_same_v<T, llvm::Module>) { // NOLINT
192  std::string type_str;
193  llvm::raw_string_ostream rso(type_str);
194  v.print(rso, nullptr);
195  return "(" + rso.str() + ")";
196  } else if constexpr (std::is_same_v<T, llvm::Function>) { // NOLINT
197  std::string type_str;
198  llvm::raw_string_ostream rso(type_str);
199  v.print(rso, nullptr);
200  return "(" + rso.str() + ")";
201  } else if constexpr (std::is_same_v<T, llvm::Value>) { // NOLINT
202  std::string type_str;
203  llvm::raw_string_ostream rso(type_str);
204  v.print(rso);
205  return "(" + rso.str() + ")";
206  } else if constexpr (std::is_same_v<T, llvm::Argument>) { // NOLINT
207  std::string type_str;
208  llvm::raw_string_ostream rso(type_str);
209  v.print(rso);
210  return "(" + rso.str() + ")";
211  } else if constexpr (std::is_same_v<T, llvm::Type>) { // NOLINT
212  std::string type_str;
213  llvm::raw_string_ostream rso(type_str);
214  v.print(rso);
215  return "(" + rso.str() + ")";
216  } else if constexpr (std::is_same_v<T, llvm::Triple>) { // NOLINT
217  return v.str();
218  } else if constexpr (std::is_same_v<T, llvm::opt::ArgStringList>) { // NOLINT
219  std::string r;
220  for (unsigned i = 0; i < v.size(); i++) {
221  if (i) {
222  r += ", ";
223  }
224  r += v[i];
225  }
226  return "[" + r + "]";
227  } else if constexpr (std::is_same_v<T, llvm::opt::DerivedArgList>) { // NOLINT
228  std::string r;
229  for (unsigned i = 0; i < v.getNumInputArgStrings(); i++) {
230  if (i) {
231  r += ", ";
232  }
233  r += v.getArgString(i);
234  }
235  return "[" + r + "]";
236  } else if constexpr (std::is_same_v<T, clang::driver::JobList>) { // NOLINT
237  std::string type_str;
238  llvm::raw_string_ostream rso(type_str);
239  v.Print(rso, nullptr, true);
240  return rso.str();
241 #endif
242 #ifdef ENABLE_TOSTRING_PTHREAD
243  } else if constexpr (std::is_same_v<T, pthread_mutex_t>) { // NOLINT
244  std::string r;
245  r += "lock=" + std::to_string(v.__data.__lock);
246  r += ", &owner=" + std::to_string(v.__data.__owner);
247  r += ", &nusers=" + std::to_string(v.__data.__nusers);
248  r += ", &count=" + std::to_string(v.__data.__count);
249  return "{" + r + "}";
250 #endif
251  } else if constexpr (std::is_same_v<T, bool>) { // NOLINT
252  return v ? "True" : "False";
253  } else if constexpr (std::is_arithmetic_v<T>) { // NOLINT
254  return std::to_string(v);
255 #ifdef ENABLE_TOSTRING_str
256  } else if constexpr (has_str_v<T>) { // NOLINT
257  return v.str();
258 #endif
259 #ifdef ENABLE_TOSTRING_to_string
260  } else if constexpr (has_to_string_v<T>) { // NOLINT
261  return v.to_string();
262 #endif
263  } else if constexpr (has_toString_v<T>) { // NOLINT
264  return v.toString();
265  } else if constexpr (get_has_toString_v<T>) {
266  auto ptr = v.get();
267  return (ptr == NULL ? "NULL" : "&" + ptr->toString());
268  } else if constexpr (std::is_same_v<T, void*>) {
269  std::ostringstream ss;
270  ss << std::hex << (uintptr_t)v;
271  return "0x" + ss.str();
272  } else if constexpr (std::is_same_v<
273  T,
274  std::chrono::time_point<std::chrono::system_clock>>) {
275  std::string s(30, '\0');
276  auto converted_v = (std::chrono::time_point<std::chrono::system_clock>)v;
277  std::time_t ts = std::chrono::system_clock::to_time_t(v);
278  std::strftime(&s[0], s.size(), "%Y-%m-%d %H:%M:%S", std::localtime(&ts));
279  return s + "." +
280  std::to_string((converted_v.time_since_epoch().count() / 1000) % 1000000);
281  } else if constexpr (std::is_same_v<T, JoinType>) {
282  switch (v) {
283  case JoinType::INNER:
284  return "INNER";
285  case JoinType::LEFT:
286  return "LEFT";
287  case JoinType::SEMI:
288  return "SEMI";
289  case JoinType::ANTI:
290  return "ANTI";
292  return "WINDOW_FUNCTION";
294  return "WINDOW_FUNCTION_FRAMING";
295  case JoinType::INVALID:
296  return "INVALID";
297  }
298  assert(false);
299  return "";
300  } else if constexpr (std::is_pointer_v<T>) {
301  return (v == NULL ? "NULL" : "&" + toString(*v));
302  } else if constexpr (has_printTo_v<T>) {
303  std::ostringstream ss;
304  v.printTo(ss);
305  return ss.str();
306  } else {
307  return typeName(&v);
308  }
309 }
std::string to_string(char const *&&v)
std::string toString(const ExecutorDeviceType &device_type)
std::string typeName(const T *v)
Definition: toString.h:103

+ 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 325 of file toString.h.

References toString().

325  {
326  return "(" + toString(v.first) + ", " + toString(v.second) + ")";
327 }
std::string toString(const ExecutorDeviceType &device_type)

+ Here is the call graph for this function:

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

Definition at line 330 of file toString.h.

References run_benchmark_import::result, and toString().

330  {
331  auto result = std::string("[");
332  for (size_t i = 0; i < v.size(); ++i) {
333  if (i) {
334  result += ", ";
335  }
336  result += toString(v[i]);
337  }
338  result += "]";
339  return result;
340 }
std::string toString(const ExecutorDeviceType &device_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 343 of file toString.h.

References run_benchmark_import::result, and toString().

343  {
344  auto result = std::string("{");
345  size_t i = 0;
346  for (const auto& p : v) {
347  if (i) {
348  result += ", ";
349  }
350  result += toString(p);
351  i++;
352  }
353  result += "}";
354  return result;
355 }
std::string toString(const ExecutorDeviceType &device_type)

+ Here is the call graph for this function:

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

Definition at line 358 of file toString.h.

References run_benchmark_import::result, and toString().

358  {
359  auto result = std::string("{");
360  size_t i = 0;
361  for (const auto& p : v) {
362  if (i) {
363  result += ", ";
364  }
365  result += toString(p);
366  i++;
367  }
368  result += "}";
369  return result;
370 }
std::string toString(const ExecutorDeviceType &device_type)

+ Here is the call graph for this function:

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

Definition at line 373 of file toString.h.

References run_benchmark_import::result, and toString().

373  {
374  auto result = std::string("[");
375  size_t i = 0;
376  for (const auto& p : v) {
377  if (i) {
378  result += ", ";
379  }
380  result += toString(p);
381  i++;
382  }
383  result += "]";
384  return result;
385 }
std::string toString(const ExecutorDeviceType &device_type)

+ Here is the call graph for this function:

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

Definition at line 388 of file toString.h.

References run_benchmark_import::result, and toString().

388  {
389  auto result = std::string("{");
390  size_t i = 0;
391  for (const auto& p : v) {
392  if (i) {
393  result += ", ";
394  }
395  result += toString(p);
396  i++;
397  }
398  result += "}";
399  return result;
400 }
std::string toString(const ExecutorDeviceType &device_type)

+ Here is the call graph for this function:

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

Definition at line 403 of file toString.h.

References run_benchmark_import::result, and toString().

403  {
404  auto result = std::string("{");
405  size_t i = 0;
406  for (const auto& p : v) {
407  if (i) {
408  result += ", ";
409  }
410  result += toString(p);
411  i++;
412  }
413  result += "}";
414  return result;
415 }
std::string toString(const ExecutorDeviceType &device_type)

+ Here is the call graph for this function:

template<typename... Ts>
std::string toString ( const std::tuple< Ts...> &  t)

Definition at line 429 of file toString.h.

References toStringImpl().

429  {
430  return "(" + toStringImpl(t, std::index_sequence_for<Ts...>{}) + ")";
431 }
std::string toStringImpl(const std::tuple< Ts...> &t, const std::index_sequence< 0, Is...>)
Definition: toString.h:418

+ Here is the call graph for this function:

template<typename... Ts, size_t... Is>
std::string toStringImpl ( const std::tuple< Ts...> &  t,
const std::index_sequence< 0, Is...>   
)

Definition at line 418 of file toString.h.

References toString().

Referenced by toString().

419  {
420  return (toString(std::get<0>(t)) + ... + (", " + toString(std::get<Is>(t))));
421 }
std::string toString(const ExecutorDeviceType &device_type)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename... T>
std::string toStringImpl ( const std::tuple<> &  t,
const std::index_sequence<>   
)

Definition at line 424 of file toString.h.

424  {
425  return {};
426 }
template<typename T >
std::string typeName ( const T *  v)

Definition at line 103 of file toString.h.

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

Referenced by ai.heavy.jdbc.HeavyAIConnection::createArrayOf(), com.mapd.calcite.parser.ExtTableFunctionTypeChecker::doesOperandTypeMatch(), com.mapd.calcite.parser.HeavyDBTypeSystem::getMaxPrecision(), com.mapd.parser.extension.ddl.heavydb.HeavyDBTypeNameSpec::HeavyDBTypeNameSpec(), ColumnList< T >::operator[](), CompilationResult::toString(), InputDescriptor::toString(), ExecutionResult::toString(), ColumnDescriptor::toString(), InputColDescriptor::toString(), RexAbstractInput::toString(), QueryCompilationDescriptor::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().

103  {
104  std::stringstream stream;
105  int status;
106 #ifdef _WIN32
107  stream << std::string(typeid(T).name());
108 #else
109  char* demangled = abi::__cxa_demangle(typeid(T).name(), 0, 0, &status);
110  stream << std::string(demangled);
111  free(demangled);
112 #endif
113  return stream.str();
114 }
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 117 of file toString.h.

References setup::name.

117  {
118  std::stringstream stream;
119  int status;
120 #ifdef _WIN32
121  stream << std::string(typeid(v).name());
122 #else
123  char* demangled = abi::__cxa_demangle(typeid(v).name(), 0, 0, &status);
124  stream << std::string(demangled);
125  free(demangled);
126 #endif
127  stream << "@0x" << std::hex << (uintptr_t)(reinterpret_cast<const void*>(v));
128  return stream.str();
129 }
string name
Definition: setup.in.py:72

Variable Documentation

std::mutex toString_PRINT_mutex
inlinestatic

Definition at line 88 of file toString.h.