OmniSciDB  72c90bc290
 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 <thread>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include "DataMgr/MemoryLevel.h"
#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())>
 
struct  anonymous_namespace{toString.h}::has_operator_lshift< T, typename >
 
struct  anonymous_namespace{toString.h}::declval< std::ostream & >()<< std::declval< T >(), 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
 
template<class T >
constexpr bool anonymous_namespace{toString.h}::has_operator_lshift_v = has_operator_lshift<T>::value
 

Macro Definition Documentation

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

Definition at line 93 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:91
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
#define __FILENAME__
Definition: toString.h:93

Definition at line 94 of file toString.h.

Function Documentation

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

Definition at line 194 of file toString.h.

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

194  {
195  if constexpr (std::is_same_v<T, std::string>) { // NOLINT
196  return "\"" + v + "\"";
197 #ifdef ENABLE_TOSTRING_RAPIDJSON
198  } else if constexpr (std::is_same_v<T, rapidjson::Value>) { // NOLINT
199  rapidjson::StringBuffer buffer;
200  rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
201  v.Accept(writer);
202  return buffer.GetString();
203 #endif
204 #ifdef ENABLE_TOSTRING_LLVM
205  } else if constexpr (std::is_same_v<T, llvm::Module>) { // NOLINT
206  std::string type_str;
207  llvm::raw_string_ostream rso(type_str);
208  v.print(rso, nullptr);
209  return "(" + rso.str() + ")";
210  } else if constexpr (std::is_same_v<T, llvm::Function>) { // NOLINT
211  std::string type_str;
212  llvm::raw_string_ostream rso(type_str);
213  v.print(rso, nullptr);
214  return "(" + rso.str() + ")";
215  } else if constexpr (std::is_same_v<T, llvm::Value>) { // NOLINT
216  std::string type_str;
217  llvm::raw_string_ostream rso(type_str);
218  v.print(rso);
219  return "(" + rso.str() + ")";
220  } else if constexpr (std::is_same_v<T, llvm::Argument>) { // NOLINT
221  std::string type_str;
222  llvm::raw_string_ostream rso(type_str);
223  v.print(rso);
224  return "(" + rso.str() + ")";
225  } else if constexpr (std::is_same_v<T, llvm::Type>) { // NOLINT
226  std::string type_str;
227  llvm::raw_string_ostream rso(type_str);
228  v.print(rso);
229  return "(" + rso.str() + ")";
230  } else if constexpr (std::is_same_v<T, llvm::Triple>) { // NOLINT
231  return v.str();
232  } else if constexpr (std::is_same_v<T, llvm::opt::ArgStringList>) { // NOLINT
233  std::string r;
234  for (unsigned i = 0; i < v.size(); i++) {
235  if (i) {
236  r += ", ";
237  }
238  r += v[i];
239  }
240  return "[" + r + "]";
241  } else if constexpr (std::is_same_v<T, llvm::opt::DerivedArgList>) { // NOLINT
242  std::string r;
243  for (unsigned i = 0; i < v.getNumInputArgStrings(); i++) {
244  if (i) {
245  r += ", ";
246  }
247  r += v.getArgString(i);
248  }
249  return "[" + r + "]";
250  } else if constexpr (std::is_same_v<T, clang::driver::JobList>) { // NOLINT
251  std::string type_str;
252  llvm::raw_string_ostream rso(type_str);
253  v.Print(rso, nullptr, true);
254  return rso.str();
255 #endif
256 #ifdef ENABLE_TOSTRING_PTHREAD
257  } else if constexpr (std::is_same_v<T, pthread_mutex_t>) { // NOLINT
258  std::string r;
259  r += "lock=" + std::to_string(v.__data.__lock);
260  r += ", &owner=" + std::to_string(v.__data.__owner);
261  r += ", &nusers=" + std::to_string(v.__data.__nusers);
262  r += ", &count=" + std::to_string(v.__data.__count);
263  return "{" + r + "}";
264 #endif
265  } else if constexpr (std::is_same_v<T, bool>) { // NOLINT
266  return v ? "True" : "False";
267  } else if constexpr (std::is_arithmetic_v<T>) { // NOLINT
268  return std::to_string(v);
269 #ifdef ENABLE_TOSTRING_str
270  } else if constexpr (has_str_v<T>) { // NOLINT
271  return v.str();
272 #endif
273 #ifdef ENABLE_TOSTRING_to_string
274  } else if constexpr (has_to_string_v<T>) { // NOLINT
275  return v.to_string();
276 #endif
277  } else if constexpr (has_toString_v<T>) { // NOLINT
278  return v.toString();
279  } else if constexpr (get_has_toString_v<T>) {
280  auto ptr = v.get();
281  return (ptr == NULL ? "NULL" : "&" + ptr->toString());
282  } else if constexpr (std::is_same_v<T, void*>) {
283  std::ostringstream ss;
284  ss << std::hex << (uintptr_t)v;
285  return "0x" + ss.str();
286  } else if constexpr (std::is_same_v<
287  T,
288  std::chrono::time_point<std::chrono::system_clock>>) {
289  std::string s(30, '\0');
290  auto converted_v = (std::chrono::time_point<std::chrono::system_clock>)v;
291  std::time_t ts = std::chrono::system_clock::to_time_t(v);
292  std::strftime(&s[0], s.size(), "%Y-%m-%d %H:%M:%S", std::localtime(&ts));
293  return s + "." +
294  std::to_string((converted_v.time_since_epoch().count() / 1000) % 1000000);
295  } else if constexpr (std::is_same_v<T, JoinType>) {
296  switch (v) {
297  case JoinType::INNER:
298  return "INNER";
299  case JoinType::LEFT:
300  return "LEFT";
301  case JoinType::SEMI:
302  return "SEMI";
303  case JoinType::ANTI:
304  return "ANTI";
306  return "WINDOW_FUNCTION";
308  return "WINDOW_FUNCTION_FRAMING";
309  case JoinType::INVALID:
310  return "INVALID";
311  }
312  assert(false);
313  return "";
314  } else if constexpr (std::is_same_v<T, Data_Namespace::MemoryLevel>) {
315  switch (v) {
317  return "DISK";
319  return "CPU_Memory";
321  return "GPU_Memory";
322  default:
323  break;
324  }
325  assert(false);
326  return "";
327  } else if constexpr (std::is_pointer_v<T>) {
328  return (v == NULL ? "NULL" : "&" + toString(*v));
329  } else if constexpr (has_printTo_v<T>) {
330  std::ostringstream ss;
331  v.printTo(ss);
332  return ss.str();
333 #ifndef _WIN32
334  } else if constexpr (has_operator_lshift_v<T>) {
335  std::stringstream stream;
336  stream << v;
337  return stream.str();
338 #endif
339  } else {
340  return typeName(&v);
341  }
342 }
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
std::string to_string(char const *&&v)
std::string typeName(const T *v)
Definition: toString.h:106

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

References toString().

358  {
359  return "(" + toString(v.first) + ", " + toString(v.second) + ")";
360 }
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64

+ Here is the call graph for this function:

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

Definition at line 363 of file toString.h.

References run_benchmark_import::result, and toString().

363  {
364  auto result = std::string("[");
365  for (size_t i = 0; i < v.size(); ++i) {
366  if (i) {
367  result += ", ";
368  }
369  result += toString(v[i]);
370  }
371  result += "]";
372  return result;
373 }
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64

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

References run_benchmark_import::result, and toString().

376  {
377  auto result = std::string("{");
378  size_t i = 0;
379  for (const auto& p : v) {
380  if (i) {
381  result += ", ";
382  }
383  result += toString(p);
384  i++;
385  }
386  result += "}";
387  return result;
388 }
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64

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

References run_benchmark_import::result, and toString().

391  {
392  auto result = std::string("{");
393  size_t i = 0;
394  for (const auto& p : v) {
395  if (i) {
396  result += ", ";
397  }
398  result += toString(p);
399  i++;
400  }
401  result += "}";
402  return result;
403 }
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64

+ Here is the call graph for this function:

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

Definition at line 406 of file toString.h.

References run_benchmark_import::result, and toString().

406  {
407  auto result = std::string("[");
408  size_t i = 0;
409  for (const auto& p : v) {
410  if (i) {
411  result += ", ";
412  }
413  result += toString(p);
414  i++;
415  }
416  result += "]";
417  return result;
418 }
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64

+ Here is the call graph for this function:

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

Definition at line 421 of file toString.h.

References run_benchmark_import::result, and toString().

421  {
422  auto result = std::string("{");
423  size_t i = 0;
424  for (const auto& p : v) {
425  if (i) {
426  result += ", ";
427  }
428  result += toString(p);
429  i++;
430  }
431  result += "}";
432  return result;
433 }
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64

+ Here is the call graph for this function:

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

Definition at line 436 of file toString.h.

References run_benchmark_import::result, and toString().

436  {
437  auto result = std::string("{");
438  size_t i = 0;
439  for (const auto& p : v) {
440  if (i) {
441  result += ", ";
442  }
443  result += toString(p);
444  i++;
445  }
446  result += "}";
447  return result;
448 }
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64

+ Here is the call graph for this function:

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

Definition at line 462 of file toString.h.

References toStringImpl().

462  {
463  return "(" + toStringImpl(t, std::index_sequence_for<Ts...>{}) + ")";
464 }
std::string toStringImpl(const std::tuple< Ts...> &t, const std::index_sequence< 0, Is...>)
Definition: toString.h:451

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

References toString().

Referenced by toString().

452  {
453  return (toString(std::get<0>(t)) + ... + (", " + toString(std::get<Is>(t))));
454 }
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64

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

457  {
458  return {};
459 }
template<typename T >
std::string typeName ( const T *  v)

Definition at line 106 of file toString.h.

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

Referenced by ai.heavy.jdbc.HeavyAIConnection::createArrayOf(), flatbuffer::NestedArray< char >::extend(), com.mapd.calcite.parser.HeavyDBTypeSystem::getMaxPrecision(), flatbuffer::NestedArray< char >::getRawBuffer(), flatbuffer::Column< Geo::MultiLineString, GeoMultiLineString >::getTypeInfo(), flatbuffer::NestedArray< char >::getTypeInfo(), flatbuffer::NestedArray< char >::getValue(), com.mapd.parser.extension.ddl.heavydb.HeavyDBTypeNameSpec::HeavyDBTypeNameSpec(), flatbuffer::NestedArray< char >::isNull(), flatbuffer::NestedArray< char >::size(), Geo::LineString::toCoords(), Geo::MultiPoint::toCoords(), Geo::MultiLineString::toCoords(), Geo::Polygon::toCoords(), Geo::MultiPolygon::toCoords(), CompilationResult::toString(), InputDescriptor::toString(), ExecutionResult::toString(), ColumnDescriptor::toString(), InputColDescriptor::toString(), QueryCompilationDescriptor::toString(), Chunk_NS::Chunk::toString(), RexAbstractInput::toString(), toString(), ResultSet::toString(), TableFunctionExecutionUnit::toString(), TextEncodingDict::toString(), RexOperator::toString(), TableFunctionManager::toString(), RexCase::toString(), RexFunctionOperator::toString(), SortField::toString(), Array< T >::toString(), RexWindowFunctionOperator::toString(), RexRef::toString(), RexAgg::toString(), Timestamp::toString(), RexSubQuery::toString(), RexInput::toString(), RelScan::toString(), Column< T >::toString(), flatbuffer::Column< Geo::MultiLineString, GeoMultiLineString >::toString(), RelProject::toString(), RelAggregate::toString(), flatbuffer::NestedArray< char >::toString(), RelJoin::toString(), Geo::Point2D::toString(), RelTranslatedJoin::toString(), RelFilter::toString(), RelLeftDeepInnerJoin::toString(), RelCompound::toString(), RelSort::toString(), Column< GeoPoint >::toString(), RelModify::toString(), Column< TextEncodingDict >::toString(), ColumnList< T >::toString(), ColumnList< Array< T > >::toString(), RelTableFunction::toString(), ColumnList< TextEncodingDict >::toString(), RelLogicalValues::toString(), and RelLogicalUnion::toString().

106  {
107  std::stringstream stream;
108  int status;
109 #ifdef _WIN32
110  stream << std::string(typeid(T).name());
111 #else
112  char* demangled = abi::__cxa_demangle(typeid(T).name(), 0, 0, &status);
113  stream << std::string(demangled);
114  free(demangled);
115 #endif
116  return stream.str();
117 }
string name
Definition: setup.in.py:72
template<typename T , typename... Args>
std::string typeName ( T(*)(Args...args)  v)

Definition at line 120 of file toString.h.

References setup::name.

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

Variable Documentation

std::mutex toString_PRINT_mutex
inlinestatic

Definition at line 91 of file toString.h.