14 #include <type_traits>
25 inline const char* filename(
const char* pathname)
27 const char* p = strrchr(pathname,
'\\');
29 p = strrchr(pathname,
'/');
36 inline void output_ts(std::ostream& o,
const char* type,
const char* fn,
long ln)
38 std::ios_base::fmtflags ff=o.flags();
39 time_t now=time(NULL);
40 struct tm* ti=localtime(&now);
41 o << std::dec << std::right <<
"[";
42 o << ti->tm_year+1900 <<
"-" << ti->tm_mon+1 <<
"-" << ti->tm_mday;
43 o <<
" " << std::setw(2) << ti->tm_hour <<
":" << std::setw(2) << ti->tm_min
44 <<
":" << std::setw(2) << ti->tm_sec <<
"] "
45 << type <<
" " << filename(fn) <<
"#" << ln;
64 #ifndef PROTON_DEBUG_OPT
65 #define PROTON_DEBUG_OPT 1
75 #define PROTON_LOG( lvl, out )\
77 if ( proton::log_console && (lvl) <= proton::debug_level ) {\
78 proton::detail::output_ts(std::cerr, "PROTON_LOG", __FILE__, __LINE__);\
79 std::cerr << " : " << out << std::endl;\
90 #define PROTON_THROW_IF(cond, out)\
93 if(proton::log_console){\
94 proton::detail::output_ts(std::cerr, "BAD", __FILE__, __LINE__);\
95 std::cerr << " : " << out << std::endl;\
97 if(proton::wait_on_err>=2){\
98 std::cout << "Assert failed. Waiting, press any key to continue..." << std::endl;\
101 throw proton::err("assert");\
105 #define PROTON_LOG( lvl, out )
106 #define PROTON_THROW_IF(cond, out)
115 #define PROTON_ERR(out)\
117 if(proton::log_console){\
118 proton::detail::output_ts(std::cerr, "ERR", __FILE__, __LINE__);\
119 std::cerr << " : " << out << std::endl;\
121 if(proton::wait_on_err>=1){\
122 std::cout << "An error has happened. Waiting, press any key to continue..." << std::endl;\
125 throw proton::err("err");\
131 class err:
public std::exception{
138 err(
const char* msg)
throw():_msg(msg)
141 err(
const err& e)
throw():_msg(e._msg)
144 err& operator=(
const err& e)
throw()
153 const char*
what()
const throw()
159 inline std::ostream& operator<<(std::ostream& o,
const err& e)
171 template<
typename T>
struct min_t{
172 typedef typename std::remove_reference<decltype(*(((T*)1)->begin()))>::type item_t;
173 static const item_t& result(
const T& v)
175 return *std::min_element(v.begin(), v.end());
179 template<
typename T>
struct max_t{
180 typedef typename std::remove_reference<decltype(*(((T*)1)->begin()))>::type item_t;
181 static const item_t& result(
const T& v)
183 return *std::max_element(v.begin(), v.end());
187 template<
typename T>
struct has_t{
189 template<
typename V>
static bool result(
const T& x, V&& v)
191 return std::find(x.begin(), x.end(), v)!=x.end();
195 template<
typename T>
struct len_t{
197 static size_t result(
const T& x)
212 const typename detail::min_t<T>::item_t&
min(
const T& v)
214 return detail::min_t<T>::result(v);
220 const typename detail::max_t<T>::item_t&
max(
const T& v)
222 return detail::max_t<T>::result(v);
230 template <
typename T,
typename V>
231 bool has(
const T& x, V&& v)
233 return detail::has_t<T>::result(x, v);
241 return detail::len_t<T>::result(v);