Galois
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gIO.h
Go to the documentation of this file.
1 /*
2  * This file belongs to the Galois project, a C++ library for exploiting
3  * parallelism. The code is being released under the terms of the 3-Clause BSD
4  * License (a copy is located in LICENSE.txt at the top-level directory).
5  *
6  * Copyright (C) 2018, The University of Texas at Austin. All rights reserved.
7  * UNIVERSITY EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS
8  * SOFTWARE AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF MERCHANTABILITY,
9  * FITNESS FOR ANY PARTICULAR PURPOSE, NON-INFRINGEMENT AND WARRANTIES OF
10  * PERFORMANCE, AND ANY WARRANTY THAT MIGHT OTHERWISE ARISE FROM COURSE OF
11  * DEALING OR USAGE OF TRADE. NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH
12  * RESPECT TO THE USE OF THE SOFTWARE OR DOCUMENTATION. Under no circumstances
13  * shall University be liable for incidental, special, indirect, direct or
14  * consequential damages or loss of profits, interruption of business, or
15  * related expenses which may arise from use of Software or Documentation,
16  * including but not limited to those resulting from defects in Software and/or
17  * Documentation, or loss or inaccuracy of data of any kind.
18  */
19 
20 #ifndef GALOIS_GIO_H
21 #define GALOIS_GIO_H
22 
23 #include <sstream>
24 #include <cerrno>
25 #include <cstdlib>
26 #include <string.h>
27 
28 #include "galois/config.h"
29 
30 // FIXME: move to Runtime
31 
32 namespace galois {
33 
35 void gPrintStr(const std::string&);
37 void gInfoStr(const std::string&);
39 void gWarnStr(const std::string&);
41 void gDebugStr(const std::string&);
43 void gErrorStr(const std::string&);
44 
46 template <typename... Args>
47 void gPrint(Args&&... args) {
48  std::ostringstream os;
49  (os << ... << args);
50  gPrintStr(os.str());
51 }
52 
54 template <typename... Args>
55 void gInfo(Args&&... args) {
56  std::ostringstream os;
57  (os << ... << args);
58  gInfoStr(os.str());
59 }
60 
62 template <typename... Args>
63 void gWarn(Args&&... args) {
64  std::ostringstream os;
65  (os << ... << args);
66  gWarnStr(os.str());
67 }
68 
71 template <typename... Args>
72 void gDebug(Args&&... GALOIS_USED_ONLY_IN_DEBUG(args)) {
73 #ifndef NDEBUG
74  std::ostringstream os;
75  (os << ... << args);
76  gDebugStr(os.str());
77 #endif
78 }
79 
81 template <typename... Args>
82 void gError(Args&&... args) {
83  std::ostringstream os;
84  (os << ... << args);
85  gErrorStr(os.str());
86 }
87 
88 void gFlush();
89 
90 #define GALOIS_SYS_DIE(...) \
91  do { \
92  galois::gError(__FILE__, ":", __LINE__, ": ", strerror(errno), ": ", \
93  ##__VA_ARGS__); \
94  abort(); \
95  } while (0)
96 #define GALOIS_DIE(...) \
97  do { \
98  galois::gError(__FILE__, ":", __LINE__, ": ", ##__VA_ARGS__); \
99  abort(); \
100  } while (0)
101 #define GALOIS_ASSERT(cond, ...) \
103  do { \
104  bool b = (cond); \
105  if (!b) { \
106  galois::gError(__FILE__, ":", __LINE__, ": assertion failed: ", #cond, \
107  " ", ##__VA_ARGS__); \
108  abort(); \
109  } \
110  } while (0)
111 
112 template <unsigned ENABLE>
113 struct debug {
114  template <typename... Args>
115  static void print(const Args&... args) {
116  gDebug(args...);
117  }
118 };
119 
120 template <>
121 struct debug<0> {
122  template <typename... Args>
123  inline static void print(const Args&...) {}
124 };
125 
126 } // end namespace galois
127 
128 #endif //_GIO_H
static void print(const Args &...)
Definition: gIO.h:123
void gInfo(Args &&...args)
Prints an info string from a sequence of things.
Definition: gIO.h:55
void gWarnStr(const std::string &)
Prints a warning string (for easy parsing)
Definition: gIO.cpp:93
void gDebug(Args &&...GALOIS_USED_ONLY_IN_DEBUG(args))
Prints a debug string from a sequence of things; prints nothing if NDEBUG is defined.
Definition: gIO.h:72
void gInfoStr(const std::string &)
Prints an info string (for easy parsing)
Definition: gIO.cpp:89
void gError(Args &&...args)
Prints error message.
Definition: gIO.h:82
void gErrorStr(const std::string &)
Prints an error string (for easy parsing)
Definition: gIO.cpp:97
void gDebugStr(const std::string &)
Prints a debug string (for easy parsing)
Definition: gIO.cpp:49
void gPrint(Args &&...args)
Prints a sequence of things.
Definition: gIO.h:47
void gFlush()
Definition: gIO.cpp:101
void gPrintStr(const std::string &)
Prints a string.
Definition: gIO.cpp:85
Definition: gIO.h:113
static void print(const Args &...args)
Definition: gIO.h:115
void gWarn(Args &&...args)
Prints a warning string from a sequence of things.
Definition: gIO.h:63