diff --git a/include/fc/filesystem.hpp b/include/fc/filesystem.hpp index bd091b5..d1a9c31 100644 --- a/include/fc/filesystem.hpp +++ b/include/fc/filesystem.hpp @@ -159,7 +159,7 @@ namespace fc { { public: inline ~temp_file_base() { remove(); } - inline operator bool() const { return _path; } + inline operator bool() const { return _path.valid(); } inline bool operator!() const { return !_path; } const fc::path& path() const; void remove(); diff --git a/include/fc/io/fstream.hpp b/include/fc/io/fstream.hpp index fe05a9a..a11f915 100644 --- a/include/fc/io/fstream.hpp +++ b/include/fc/io/fstream.hpp @@ -29,7 +29,7 @@ namespace fc { enum seekdir { beg, cur, end }; ifstream(); - ifstream( const fc::path& file, int m ); + ifstream( const fc::path& file, int m = binary); ~ifstream(); void open( const fc::path& file, int m ); diff --git a/include/fc/optional.hpp b/include/fc/optional.hpp index 594bf18..a4e774d 100644 --- a/include/fc/optional.hpp +++ b/include/fc/optional.hpp @@ -183,7 +183,10 @@ namespace fc { bool valid()const { return _valid; } bool operator!()const { return !_valid; } - operator bool()const { return _valid; } + + // this operation is not safe and can result in unintential + // casts and comparisons, use valid() or !! + explicit operator bool()const { return _valid; } T& operator*() { assert(_valid); return ref(); } const T& operator*()const { assert(_valid); return ref(); } diff --git a/include/fc/variant.hpp b/include/fc/variant.hpp index 7d2690f..4bed054 100644 --- a/include/fc/variant.hpp +++ b/include/fc/variant.hpp @@ -238,7 +238,7 @@ namespace fc variant( const optional& v ) { memset( this, 0, sizeof(*this) ); - if( v ) *this = variant(*v); + if( v.valid() ) *this = variant(*v); } template diff --git a/src/filesystem.cpp b/src/filesystem.cpp index a95aae7..7b4b8ec 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -356,7 +356,7 @@ namespace fc { void temp_file_base::remove() { - if (_path) + if (_path.valid()) { try { diff --git a/src/log/logger_config.cpp b/src/log/logger_config.cpp index 22465de..413be71 100644 --- a/src/log/logger_config.cpp +++ b/src/log/logger_config.cpp @@ -36,11 +36,11 @@ namespace fc { auto lgr = logger::get( cfg.loggers[i].name ); // TODO: finish configure logger here... - if( cfg.loggers[i].parent ) { + if( cfg.loggers[i].parent.valid() ) { lgr.set_parent( logger::get( *cfg.loggers[i].parent ) ); } lgr.set_name(cfg.loggers[i].name); - if( cfg.loggers[i].level ) lgr.set_log_level( *cfg.loggers[i].level ); + if( cfg.loggers[i].level.valid() ) lgr.set_log_level( *cfg.loggers[i].level ); for( auto a = cfg.loggers[i].appenders.begin(); a != cfg.loggers[i].appenders.end(); ++a ){ diff --git a/src/network/url.cpp b/src/network/url.cpp index 23a7e79..3456b3c 100644 --- a/src/network/url.cpp +++ b/src/network/url.cpp @@ -59,7 +59,7 @@ namespace fc _path = fc::path( "/" ) / _lpath; #endif fc::getline( ss, _largs ); - if( _args && _args->size() ) + if( _args.valid() && _args->size() ) { // TODO: args = fc::move(_args); } @@ -88,16 +88,16 @@ namespace fc { fc::stringstream ss; ss<_proto<<"://"; - if( my->_user ) { + if( my->_user.valid() ) { ss << *my->_user; - if( my->_pass ) { + if( my->_pass.valid() ) { ss<<":"<<*my->_pass; } ss<<"@"; } - if( my->_host ) ss<<*my->_host; - if( my->_port ) ss<<":"<<*my->_port; - if( my->_path ) ss<_path->generic_string(); + if( my->_host.valid() ) ss<<*my->_host; + if( my->_port.valid() ) ss<<":"<<*my->_port; + if( my->_path.valid() ) ss<_path->generic_string(); // if( my->_args ) ss<<"?"<<*my->_args; return ss.str(); }