OmniSciDB  21ac014ffc
 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 >
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 79 of file toString.h.

#define HAVE_TOSTRING

Definition at line 39 of file toString.h.

#define PRINT (   EXPR)
Value:
std::cout << "[" << __FILENAME__ << ":" << __func__ << "#" << __LINE__ \
<< "]: " #EXPR "=" << ::toString(EXPR) << std::endl;
std::string toString(const ExtArgumentType &sig_type)
#define __FILENAME__
Definition: toString.h:79

Definition at line 80 of file toString.h.

Function Documentation

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

Definition at line 147 of file toString.h.

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

147  {
148  if constexpr (std::is_same_v<T, std::string>) {
149  return "\"" + v + "\"";
150 #ifdef ENABLE_TOSTRING_RAPIDJSON
151  } else if constexpr (std::is_same_v<T, rapidjson::Value>) {
152  rapidjson::StringBuffer buffer;
153  rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
154  v.Accept(writer);
155  return buffer.GetString();
156 #endif
157 #ifdef ENABLE_TOSTRING_LLVM
158  } else if constexpr (std::is_same_v<T, llvm::Module>) {
159  std::string type_str;
160  llvm::raw_string_ostream rso(type_str);
161  v.print(rso, nullptr);
162  return "(" + rso.str() + ")";
163  } else if constexpr (std::is_same_v<T, llvm::Function>) {
164  std::string type_str;
165  llvm::raw_string_ostream rso(type_str);
166  v.print(rso, nullptr);
167  return "(" + rso.str() + ")";
168  } else if constexpr (std::is_same_v<T, llvm::Value>) {
169  std::string type_str;
170  llvm::raw_string_ostream rso(type_str);
171  v.print(rso);
172  return "(" + rso.str() + ")";
173  } else if constexpr (std::is_same_v<T, llvm::Type>) {
174  std::string type_str;
175  llvm::raw_string_ostream rso(type_str);
176  v.print(rso);
177  return "(" + rso.str() + ")";
178  } else if constexpr (std::is_same_v<T, llvm::Triple>) {
179  return v.str();
180  } else if constexpr (std::is_same_v<T, llvm::opt::ArgStringList>) {
181  std::string r;
182  for (unsigned i = 0; i < v.size(); i++) {
183  if (i) {
184  r += ", ";
185  }
186  r += v[i];
187  }
188  return "[" + r + "]";
189  } else if constexpr (std::is_same_v<T, llvm::opt::DerivedArgList>) {
190  std::string r;
191  for (unsigned i = 0; i < v.getNumInputArgStrings(); i++) {
192  if (i) {
193  r += ", ";
194  }
195  r += v.getArgString(i);
196  }
197  return "[" + r + "]";
198  } else if constexpr (std::is_same_v<T, clang::driver::JobList>) {
199  std::string type_str;
200  llvm::raw_string_ostream rso(type_str);
201  v.Print(rso, nullptr, true);
202  return rso.str();
203 #endif
204  } else if constexpr (std::is_same_v<T, bool>) {
205  return v ? "True" : "False";
206  } else if constexpr (std::is_arithmetic_v<T>) {
207  return std::to_string(v);
208 #ifdef ENABLE_TOSTRING_str
209  } else if constexpr (has_str_v<T>) {
210  return v.str();
211 #endif
212 #ifdef ENABLE_TOSTRING_to_string
213  } else if constexpr (has_to_string_v<T>) {
214  return v.to_string();
215 #endif
216  } else if constexpr (has_toString_v<T>) {
217  return v.toString();
218  } else if constexpr (get_has_toString_v<T>) {
219  auto ptr = v.get();
220  return (ptr == NULL ? "NULL" : "&" + ptr->toString());
221  } else if constexpr (std::is_same_v<T, void*>) {
222  std::ostringstream ss;
223  ss << std::hex << (uintptr_t)v;
224  return "0x" + ss.str();
225  } else if constexpr (std::is_same_v<
226  T,
227  std::chrono::time_point<std::chrono::system_clock>>) {
228  std::string s(30, '\0');
229  auto converted_v = (std::chrono::time_point<std::chrono::system_clock>)v;
230  std::time_t ts = std::chrono::system_clock::to_time_t(v);
231  std::strftime(&s[0], s.size(), "%Y-%m-%d %H:%M:%S", std::localtime(&ts));
232  return s + "." +
233  std::to_string((converted_v.time_since_epoch().count() / 1000) % 1000000);
234  } else if constexpr (std::is_same_v<T, JoinType>) {
235  switch (v) {
236  case JoinType::INNER:
237  return "INNER";
238  case JoinType::LEFT:
239  return "LEFT";
240  case JoinType::SEMI:
241  return "SEMI";
242  case JoinType::ANTI:
243  return "ANTI";
244  case JoinType::INVALID:
245  return "INVALID";
246  }
247  UNREACHABLE();
248  return "";
249  } else if constexpr (std::is_pointer_v<T>) {
250  return (v == NULL ? "NULL" : "&" + toString(*v));
251  } else if constexpr (has_printTo_v<T>) {
252  std::ostringstream ss;
253  v.printTo(ss);
254  return ss.str();
255  } else {
256  return typeName(&v);
257  }
258 }
std::string toString(const ExtArgumentType &sig_type)
tuple r
Definition: test_fsi.py:16
#define UNREACHABLE()
Definition: Logger.h:250
std::string to_string(char const *&&v)
std::string typeName(const T *v)
Definition: toString.h:85

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

References toString().

261  {
262  return "(" + toString(v.first) + ", " + toString(v.second) + ")";
263 }
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 266 of file toString.h.

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

266  {
267  auto result = std::string("[");
268  for (size_t i = 0; i < v.size(); ++i) {
269  if (i) {
270  result += ", ";
271  }
272  result += toString(v[i]);
273  }
274  result += "]";
275  return result;
276 }
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 279 of file toString.h.

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

279  {
280  auto result = std::string("{");
281  size_t i = 0;
282  for (const auto& p : v) {
283  if (i) {
284  result += ", ";
285  }
286  result += toString(p);
287  i++;
288  }
289  result += "}";
290  return result;
291 }
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 294 of file toString.h.

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

294  {
295  auto result = std::string("[");
296  size_t i = 0;
297  for (const auto& p : v) {
298  if (i) {
299  result += ", ";
300  }
301  result += toString(p);
302  i++;
303  }
304  result += "]";
305  return result;
306 }
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 309 of file toString.h.

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

309  {
310  auto result = std::string("{");
311  size_t i = 0;
312  for (const auto& p : v) {
313  if (i) {
314  result += ", ";
315  }
316  result += toString(p);
317  i++;
318  }
319  result += "}";
320  return result;
321 }
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 324 of file toString.h.

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

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

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

339  {
340  T left, right;
341  std::tie(left, right) = v;
342  return std::string("(") + toString(left) + ", " + toString(right) + ")";
343 }
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 85 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(), TableFunctionExecutionUnit::toString(), toString(), RexLiteral::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().

85  {
86  std::stringstream stream;
87  int status;
88 #ifdef _WIN32
89  stream << std::string(typeid(T).name());
90 #else
91  char* demangled = abi::__cxa_demangle(typeid(T).name(), 0, 0, &status);
92  stream << std::string(demangled);
93  free(demangled);
94 #endif
95  return stream.str();
96 }
string name
Definition: setup.in.py:72

+ Here is the caller graph for this function: