OmniSciDB  cde582ebc3
 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 <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 89 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:87
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1448
#define __FILENAME__
Definition: toString.h:89

Definition at line 90 of file toString.h.

Function Documentation

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

Definition at line 179 of file toString.h.

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

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

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

References toString().

320  {
321  return "(" + toString(v.first) + ", " + toString(v.second) + ")";
322 }
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1448

+ Here is the call graph for this function:

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

Definition at line 325 of file toString.h.

References run_benchmark_import::result, and toString().

325  {
326  auto result = std::string("[");
327  for (size_t i = 0; i < v.size(); ++i) {
328  if (i) {
329  result += ", ";
330  }
331  result += toString(v[i]);
332  }
333  result += "]";
334  return result;
335 }
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1448

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

References run_benchmark_import::result, and toString().

338  {
339  auto result = std::string("{");
340  size_t i = 0;
341  for (const auto& p : v) {
342  if (i) {
343  result += ", ";
344  }
345  result += toString(p);
346  i++;
347  }
348  result += "}";
349  return result;
350 }
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1448

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

References run_benchmark_import::result, and toString().

353  {
354  auto result = std::string("{");
355  size_t i = 0;
356  for (const auto& p : v) {
357  if (i) {
358  result += ", ";
359  }
360  result += toString(p);
361  i++;
362  }
363  result += "}";
364  return result;
365 }
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1448

+ Here is the call graph for this function:

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

Definition at line 368 of file toString.h.

References run_benchmark_import::result, and toString().

368  {
369  auto result = std::string("[");
370  size_t i = 0;
371  for (const auto& p : v) {
372  if (i) {
373  result += ", ";
374  }
375  result += toString(p);
376  i++;
377  }
378  result += "]";
379  return result;
380 }
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1448

+ Here is the call graph for this function:

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

Definition at line 383 of file toString.h.

References run_benchmark_import::result, and toString().

383  {
384  auto result = std::string("{");
385  size_t i = 0;
386  for (const auto& p : v) {
387  if (i) {
388  result += ", ";
389  }
390  result += toString(p);
391  i++;
392  }
393  result += "}";
394  return result;
395 }
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1448

+ Here is the call graph for this function:

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

Definition at line 398 of file toString.h.

References run_benchmark_import::result, and toString().

398  {
399  auto result = std::string("{");
400  size_t i = 0;
401  for (const auto& p : v) {
402  if (i) {
403  result += ", ";
404  }
405  result += toString(p);
406  i++;
407  }
408  result += "}";
409  return result;
410 }
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1448

+ Here is the call graph for this function:

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

Definition at line 424 of file toString.h.

References toStringImpl().

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

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

References toString().

Referenced by toString().

414  {
415  return (toString(std::get<0>(t)) + ... + (", " + toString(std::get<Is>(t))));
416 }
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1448

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

419  {
420  return {};
421 }
template<typename T >
std::string typeName ( const T *  v)

Definition at line 102 of file toString.h.

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

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

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

References setup::name.

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

Variable Documentation

std::mutex toString_PRINT_mutex
inlinestatic

Definition at line 87 of file toString.h.