OmniSciDB  b28c0d5765
 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(), and typeName().

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";
291  case JoinType::INVALID:
292  return "INVALID";
293  }
294  assert(false);
295  return "";
296  } else if constexpr (std::is_pointer_v<T>) {
297  return (v == NULL ? "NULL" : "&" + toString(*v));
298  } else if constexpr (has_printTo_v<T>) {
299  std::ostringstream ss;
300  v.printTo(ss);
301  return ss.str();
302  } else {
303  return typeName(&v);
304  }
305 }
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 321 of file toString.h.

References toString().

321  {
322  return "(" + toString(v.first) + ", " + toString(v.second) + ")";
323 }
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 326 of file toString.h.

References run_benchmark_import::result, and toString().

326  {
327  auto result = std::string("[");
328  for (size_t i = 0; i < v.size(); ++i) {
329  if (i) {
330  result += ", ";
331  }
332  result += toString(v[i]);
333  }
334  result += "]";
335  return result;
336 }
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 339 of file toString.h.

References run_benchmark_import::result, and toString().

339  {
340  auto result = std::string("{");
341  size_t i = 0;
342  for (const auto& p : v) {
343  if (i) {
344  result += ", ";
345  }
346  result += toString(p);
347  i++;
348  }
349  result += "}";
350  return result;
351 }
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 354 of file toString.h.

References run_benchmark_import::result, and toString().

354  {
355  auto result = std::string("{");
356  size_t i = 0;
357  for (const auto& p : v) {
358  if (i) {
359  result += ", ";
360  }
361  result += toString(p);
362  i++;
363  }
364  result += "}";
365  return result;
366 }
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 369 of file toString.h.

References run_benchmark_import::result, and toString().

369  {
370  auto result = std::string("[");
371  size_t i = 0;
372  for (const auto& p : v) {
373  if (i) {
374  result += ", ";
375  }
376  result += toString(p);
377  i++;
378  }
379  result += "]";
380  return result;
381 }
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 384 of file toString.h.

References run_benchmark_import::result, and toString().

384  {
385  auto result = std::string("{");
386  size_t i = 0;
387  for (const auto& p : v) {
388  if (i) {
389  result += ", ";
390  }
391  result += toString(p);
392  i++;
393  }
394  result += "}";
395  return result;
396 }
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 399 of file toString.h.

References run_benchmark_import::result, and toString().

399  {
400  auto result = std::string("{");
401  size_t i = 0;
402  for (const auto& p : v) {
403  if (i) {
404  result += ", ";
405  }
406  result += toString(p);
407  i++;
408  }
409  result += "}";
410  return result;
411 }
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 425 of file toString.h.

References toStringImpl().

425  {
426  return "(" + toStringImpl(t, std::index_sequence_for<Ts...>{}) + ")";
427 }
std::string toStringImpl(const std::tuple< Ts...> &t, const std::index_sequence< 0, Is...>)
Definition: toString.h:414

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

References toString().

Referenced by toString().

415  {
416  return (toString(std::get<0>(t)) + ... + (", " + toString(std::get<Is>(t))));
417 }
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 420 of file toString.h.

420  {
421  return {};
422 }
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(), CompilationResult::toString(), InputDescriptor::toString(), ExecutionResult::toString(), ColumnDescriptor::toString(), RexAbstractInput::toString(), InputColDescriptor::toString(), QueryCompilationDescriptor::toString(), Chunk_NS::Chunk::toString(), TextEncodingDict::toString(), TableFunctionExecutionUnit::toString(), toString(), ResultSet::toString(), Array< T >::toString(), RexOperator::toString(), RexSubQuery::toString(), RexInput::toString(), Timestamp::toString(), RexCase::toString(), RexFunctionOperator::toString(), SortField::toString(), RexWindowFunctionOperator::toString(), Column< T >::toString(), RexRef::toString(), RexAgg::toString(), Column< TextEncodingDict >::toString(), RelScan::toString(), ColumnList< T >::toString(), ColumnList< Array< T > >::toString(), ColumnList< TextEncodingDict >::toString(), RelProject::toString(), TableFunctionManager::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.