From c12ac793b31ac4cc59c022c3decc0271a077c89d Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Fri, 14 Sep 2012 00:56:20 -0400 Subject: [PATCH] updated filesystem and exception api --- include/fc/exception.hpp | 19 +++++++++++++++++-- include/fc/filesystem.hpp | 10 ++++++++-- src/filesystem.cpp | 9 +++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/include/fc/exception.hpp b/include/fc/exception.hpp index 551792f..8eabf9f 100644 --- a/include/fc/exception.hpp +++ b/include/fc/exception.hpp @@ -3,6 +3,11 @@ #include #include +// TODO: Remove boost exception dependency here!! +// TODO: Remove boost format dependency here!! +#include +#include + // provided for easy integration with boost. namespace boost { class exception_ptr; } @@ -46,9 +51,19 @@ namespace fc { } void rethrow_exception( const exception_ptr& e ); -} // namespace fc -#define FC_THROW( X, ... ) throw (X) + typedef boost::error_info err_msg; + struct exception : public virtual boost::exception, public virtual std::exception { + const char* what()const throw() { return "exception"; } + virtual void rethrow()const { BOOST_THROW_EXCEPTION(*this); } + const std::string& message()const { return *boost::get_error_info(*this); } + }; +} // namespace fc +#define FC_THROW(X,...) throw X +#define FC_THROW_MSG( MSG, ... ) \ + do { \ + BOOST_THROW_EXCEPTION( fc::exception() << fc::err_msg( (boost::format( MSG ) __VA_ARGS__ ).str() ) );\ + } while(0) #endif // _FC_EXCEPTION_HPP_ diff --git a/include/fc/filesystem.hpp b/include/fc/filesystem.hpp index de3ca6e..ad659f1 100644 --- a/include/fc/filesystem.hpp +++ b/include/fc/filesystem.hpp @@ -25,17 +25,23 @@ namespace fc { path& operator /=( const fc::path& ); friend path operator /( const fc::path& p, const fc::path& ); + friend bool operator ==( const fc::path& p, const fc::path& ); + friend bool operator !=( const fc::path& p, const fc::path& ); operator boost::filesystem::path& (); operator const boost::filesystem::path& ()const; + fc::path filename()const; fc::string string()const; private: fwd _p; }; - bool exists( const path& p ); - void create_directories( const path& p ); + bool exists( const path& p ); + bool is_directory( const path& p ); + bool is_regular( const path& p ); + void create_directories( const path& p ); + uint64_t file_size( const path& p ); } #endif // _FC_FILESYSTEM_HPP_ diff --git a/src/filesystem.cpp b/src/filesystem.cpp index 4a305f3..ab6fb29 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -30,6 +30,9 @@ namespace fc { return *this; } + bool operator ==( const fc::path& l, const fc::path& r ) { return *l._p == *r._p; } + bool operator !=( const fc::path& l, const fc::path& r ) { return *l._p != *r._p; } + path& path::operator /=( const fc::path& p ) { *_p /= *p._p; return *this; @@ -50,8 +53,14 @@ namespace fc { fc::string path::string()const { return _p->string().c_str(); } + fc::path path::filename()const { + return _p->filename(); + } bool exists( const path& p ) { return boost::filesystem::exists(p); } void create_directories( const path& p ) { boost::filesystem::create_directories(p); } + bool is_directory( const path& p ) { return boost::filesystem::is_directory(p); } + bool is_regular( const path& p ) { return boost::filesystem::is_regular(p); } + uint64_t file_size( const path& p ) { return boost::filesystem::file_size(p); } }