Skip to content

Commit

Permalink
Replace tabs with spaces to use DFHack code style.
Browse files Browse the repository at this point in the history
  • Loading branch information
BenLubar committed Dec 26, 2017
1 parent 3bdbb8e commit f0d8bd9
Show file tree
Hide file tree
Showing 21 changed files with 7,796 additions and 7,796 deletions.
34 changes: 17 additions & 17 deletions debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ static std::ofstream weblegends_debug_stream;

static void weblegends_debug_log_message()
{
Core::getInstance().getConsole().color(COLOR_YELLOW);
Core::getInstance().getConsole().print("[weblegends] Debug messages have been written to weblegends_debug.log. Please send this file to https://github.com/BenLubar/weblegends\n");
Core::getInstance().getConsole().reset_color();
Core::getInstance().getConsole().color(COLOR_YELLOW);
Core::getInstance().getConsole().print("[weblegends] Debug messages have been written to weblegends_debug.log. Please send this file to https://github.com/BenLubar/weblegends\n");
Core::getInstance().getConsole().reset_color();
}

std::ostream & weblegends_debug_log()
{
if (!weblegends_debug_stream.is_open())
{
weblegends_debug_stream.open("weblegends_debug.log", std::ios_base::out | std::ios_base::app);
weblegends_debug_stream << "weblegends " << WEBLEGENDS_GIT_DESCRIPTION << " debug log opened" << std::endl;
weblegends_debug_stream << "weblegends commit: " << WEBLEGENDS_GIT_COMMIT << std::endl;
weblegends_debug_log_message();
}

return weblegends_debug_stream;
if (!weblegends_debug_stream.is_open())
{
weblegends_debug_stream.open("weblegends_debug.log", std::ios_base::out | std::ios_base::app);
weblegends_debug_stream << "weblegends " << WEBLEGENDS_GIT_DESCRIPTION << " debug log opened" << std::endl;
weblegends_debug_stream << "weblegends commit: " << WEBLEGENDS_GIT_COMMIT << std::endl;
weblegends_debug_log_message();
}

return weblegends_debug_stream;
}

void weblegends_debug_close_log()
{
if (!weblegends_debug_stream.is_open())
{
weblegends_debug_stream.close();
weblegends_debug_log_message();
}
if (!weblegends_debug_stream.is_open())
{
weblegends_debug_stream.close();
weblegends_debug_log_message();
}
}

#endif
52 changes: 26 additions & 26 deletions debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,67 +12,67 @@ void weblegends_debug_close_log();
template<typename E>
struct weblegends_switch_debug_enum_base
{
weblegends_switch_debug_enum_base(E var) : var(var) {}
E var;
weblegends_switch_debug_enum_base(E var) : var(var) {}
E var;
};

template<typename E>
struct weblegends_switch_debug_enum : public weblegends_switch_debug_enum_base<E>
{
weblegends_switch_debug_enum(E var) : weblegends_switch_debug_enum_base<E>(var) {}
weblegends_switch_debug_enum(E var) : weblegends_switch_debug_enum_base<E>(var) {}
};

template<typename E>
inline typename std::ostream & operator<<(std::ostream & s, const weblegends_switch_debug_enum_base<E> & e)
{
return s << typeid(e.var).name() << "(" << int64_t(e.var) << ")";
return s << typeid(e.var).name() << "(" << int64_t(e.var) << ")";
}

template<typename E>
inline typename std::enable_if<std::is_same<typename df::enum_traits<E>::enum_type, E>::value, std::ostream &>::type operator<<(std::ostream & s, const weblegends_switch_debug_enum<E> e)
{
return s << df::identity_traits<E>::get()->getName() << "(" << enum_item_key(e.var) << ")";
return s << df::identity_traits<E>::get()->getName() << "(" << enum_item_key(e.var) << ")";
}

inline constexpr const char *weblegends_basename(const char *p1, const char *p2)
{
// https://gist.github.com/rsms/a5fa779736ea4932be91
return *p2 == '\0' ? p1 : *p2 == '/' || *p2 == '\\' ? weblegends_basename(p2 + 1, p2 + 1) : weblegends_basename(p1, p2 + 1);
// https://gist.github.com/rsms/a5fa779736ea4932be91
return *p2 == '\0' ? p1 : *p2 == '/' || *p2 == '\\' ? weblegends_basename(p2 + 1, p2 + 1) : weblegends_basename(p1, p2 + 1);
}

#define BEFORE_SWITCH(var, expr) \
{ \
auto var = expr; \
try \
{ \
bool var##_found = false
auto var = expr; \
try \
{ \
bool var##_found = false

#define BREAK(var) \
var##_found = true; \
break
var##_found = true; \
break

#define AFTER_SWITCH(var, message) \
if (!var##_found) \
{ \
weblegends_debug_log() << "[weblegends] [" << weblegends_basename(__FILE__, __FILE__) << ":" << __LINE__ << "] missing enum-item: " << weblegends_switch_debug_enum<decltype(var)>(var) << ": " << (message) << std::endl; \
} \
} \
catch (...) \
{ \
weblegends_debug_log() << "[weblegends] [" << weblegends_basename(__FILE__, __FILE__) << ":" << __LINE__ << "] exception in switch: " << weblegends_switch_debug_enum<decltype(var)>(var) << ": " << (message) << std::endl; \
throw; \
} \
if (!var##_found) \
{ \
weblegends_debug_log() << "[weblegends] [" << weblegends_basename(__FILE__, __FILE__) << ":" << __LINE__ << "] missing enum-item: " << weblegends_switch_debug_enum<decltype(var)>(var) << ": " << (message) << std::endl; \
} \
} \
catch (...) \
{ \
weblegends_debug_log() << "[weblegends] [" << weblegends_basename(__FILE__, __FILE__) << ":" << __LINE__ << "] exception in switch: " << weblegends_switch_debug_enum<decltype(var)>(var) << ": " << (message) << std::endl; \
throw; \
} \
}

#define ASSUME_EQUAL(actual, expected, message) \
if ((actual) != (expected)) \
{ \
typedef typename std::remove_reference<decltype((actual))>::type T; \
weblegends_debug_log() << "[weblegends] [" << weblegends_basename(__FILE__, __FILE__) << ":" << __LINE__ << "] expected " << weblegends_switch_debug_enum<T>((actual)) << " to equal " << weblegends_switch_debug_enum<T>(static_cast<T>((expected))) << ": " << (message) << std::endl; \
typedef typename std::remove_reference<decltype((actual))>::type T; \
weblegends_debug_log() << "[weblegends] [" << weblegends_basename(__FILE__, __FILE__) << ":" << __LINE__ << "] expected " << weblegends_switch_debug_enum<T>((actual)) << " to equal " << weblegends_switch_debug_enum<T>(static_cast<T>((expected))) << ": " << (message) << std::endl; \
}

#define UNEXPECTED(message) \
weblegends_debug_log() << "[weblegends] [" << weblegends_basename(__FILE__, __FILE__) << ":" << __LINE__ << "] " << (message) << std::endl;
weblegends_debug_log() << "[weblegends] [" << weblegends_basename(__FILE__, __FILE__) << ":" << __LINE__ << "] " << (message) << std::endl;

#else

Expand Down
Loading

0 comments on commit f0d8bd9

Please sign in to comment.