From 21af83013f3b1bae511a61b9e27224ab3de235c1 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 30 Apr 2007 11:22:08 +0000 Subject: Did more work on the utility code. --- src/utils.h | 55 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 23 deletions(-) (limited to 'src/utils.h') diff --git a/src/utils.h b/src/utils.h index c8bd4c56..8be512fb 100644 --- a/src/utils.h +++ b/src/utils.h @@ -9,24 +9,13 @@ */ namespace ledger { -#if ! defined(USE_BOOST_PYTHON) + using namespace boost; + +#if defined(VERIFY_ON) && ! defined(USE_BOOST_PYTHON) class string; #else typedef std::string string; #endif -} - -// jww (2007-04-30): These Boost includes can go into system.hh as -// soon as GCC fixes it's problem with pre-compiled headers and global -// variables defined in unnamed namespaces. - -#include -#include -#include -#include - -namespace ledger { - using namespace boost; typedef posix_time::ptime ptime; typedef ptime::time_duration_type time_duration; @@ -35,6 +24,9 @@ namespace ledger { typedef posix_time::seconds seconds; typedef filesystem::path path; + typedef boost::filesystem::ifstream ifstream; + typedef boost::filesystem::ofstream ofstream; + typedef boost::filesystem::filesystem_error filesystem_error; } /********************************************************************** @@ -71,8 +63,6 @@ namespace ledger { #endif #if defined(ASSERTS_ON) -#include - namespace ledger { void debug_assert(const string& reason, const string& func, const string& file, unsigned long line); @@ -247,11 +237,7 @@ extern unsigned int _trace_level; extern std::string _log_category; inline bool category_matches(const char * cat) { - return (_log_category == cat || - (std::strlen(cat) > _log_category.size() + 1 && - std::strncmp(cat, _log_category.c_str(), - _log_category.size()) == 0 && - cat[_log_category.size()] == '.')); + return starts_with(_log_category, cat); } #define SHOW_DEBUG(cat) \ @@ -403,21 +389,44 @@ void finish_timer(const char * name); * Exception handling */ -#include "error.h" +#include "context.h" namespace ledger { +#define DECLARE_EXCEPTION(name) \ + class name : public std::logic_error { \ + public: \ + name(const string& why) throw() : std::logic_error(why) {} \ + } + extern std::ostringstream _exc_buffer; template inline void throw_func(const std::string& message) { _exc_buffer.str(""); - throw T(message, context()); + throw T(message); } #define throw_(cls, msg) \ ((_exc_buffer << msg), throw_func(_exc_buffer.str())) +inline void throw_unexpected_error(char c, char wanted) { +#if 0 + if (c == -1) { + if (wanted) + throw new error(string("Missing '") + wanted + "'"); + else + throw new error("Unexpected end of input"); + } else { + if (wanted) + throw new error(string("Invalid char '") + c + + "' (wanted '" + wanted + "')"); + else + throw new error(string("Invalid char '") + c + "'"); + } +#endif +} + } // namespace ledger /********************************************************************** -- cgit v1.2.3