OmniSciDB  16c4e035a1
 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 84 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:84

Definition at line 85 of file toString.h.

Function Documentation

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

Definition at line 170 of file toString.h.

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

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

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

References toString().

311  {
312  return "(" + toString(v.first) + ", " + toString(v.second) + ")";
313 }
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 316 of file toString.h.

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

316  {
317  auto result = std::string("[");
318  for (size_t i = 0; i < v.size(); ++i) {
319  if (i) {
320  result += ", ";
321  }
322  result += toString(v[i]);
323  }
324  result += "]";
325  return result;
326 }
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 329 of file toString.h.

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

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

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

344  {
345  auto result = std::string("[");
346  size_t i = 0;
347  for (const auto& p : v) {
348  if (i) {
349  result += ", ";
350  }
351  result += toString(p);
352  i++;
353  }
354  result += "]";
355  return result;
356 }
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 359 of file toString.h.

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

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

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

374  {
375  auto result = std::string("{");
376  size_t i = 0;
377  for (const auto& p : v) {
378  if (i) {
379  result += ", ";
380  }
381  result += toString(p);
382  i++;
383  }
384  result += "}";
385  return result;
386 }
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 389 of file toString.h.

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

389  {
390  T left, right;
391  std::tie(left, right) = v;
392  return std::string("(") + toString(left) + ", " + toString(right) + ")";
393 }
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 93 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(), toString(), TableFunctionExecutionUnit::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().

93  {
94  std::stringstream stream;
95  int status;
96 #ifdef _WIN32
97  stream << std::string(typeid(T).name());
98 #else
99  char* demangled = abi::__cxa_demangle(typeid(T).name(), 0, 0, &status);
100  stream << std::string(demangled);
101  free(demangled);
102 #endif
103  return stream.str();
104 }
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 107 of file toString.h.

References setup::name.

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