updated filesystem and exception api

This commit is contained in:
Daniel Larimer 2012-09-14 00:56:20 -04:00
parent 766f44e629
commit c12ac793b3
3 changed files with 34 additions and 4 deletions

View file

@ -3,6 +3,11 @@
#include <fc/shared_ptr.hpp>
#include <fc/string.hpp>
// TODO: Remove boost exception dependency here!!
// TODO: Remove boost format dependency here!!
#include <boost/format.hpp>
#include <boost/exception/all.hpp>
// 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<struct err_msg_,std::string> 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<fc::err_msg>(*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_

View file

@ -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<boost::filesystem::path,8> _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_

View file

@ -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); }
}