|
Boost-Commit : |
From: bdawes_at_[hidden]
Date: 2007-08-08 13:51:04
Author: bemandawes
Date: 2007-08-08 13:51:01 EDT (Wed, 08 Aug 2007)
New Revision: 38510
URL: http://svn.boost.org/trac/boost/changeset/38510
Log:
Remove posix(), add default generic_error_code imp, add test cases
Text files modified:
branches/c++0x/boost/boost/system/error_code.hpp | 54 ++++++++++++++++++++++-----------------
branches/c++0x/boost/libs/system/src/error_code.cpp | 12 --------
branches/c++0x/boost/libs/system/test/error_code_test.cpp | 30 +++++++++++++--------
3 files changed, 49 insertions(+), 47 deletions(-)
Modified: branches/c++0x/boost/boost/system/error_code.hpp
==============================================================================
--- branches/c++0x/boost/boost/system/error_code.hpp (original)
+++ branches/c++0x/boost/boost/system/error_code.hpp 2007-08-08 13:51:01 EDT (Wed, 08 Aug 2007)
@@ -129,16 +129,12 @@
public:
virtual ~error_category(){}
virtual const std::string & name() const = 0;
- virtual posix::posix_errno posix( int ev) const = 0;
- virtual error_code generic_error_code( int ev) const = 0;
+ virtual error_code generic_error_code( int ev) const;
virtual std::string message( int ev ) const = 0;
bool operator==(const error_category & rhs) const { return this == &rhs; }
bool operator!=(const error_category & rhs) const { return !(*this == rhs); }
- bool operator<( const error_category & rhs ) const
- {
- return name() < rhs.name();
- }
+ bool operator<( const error_category & rhs ) const{ return name() < rhs.name(); }
};
// predefined error categories -----------------------------------------//
@@ -159,7 +155,7 @@
public:
// constructors:
- error_code() : m_val(0), m_cat(&posix_category) {}
+ error_code() : m_val(0), m_cat(&posix_category) {}
error_code( int val, const error_category & cat ) : m_val(val), m_cat(&cat) {}
template<typename Enum>
@@ -188,7 +184,6 @@
// observers:
int value() const { return m_val; }
const error_category & category() const { return *m_cat; }
- posix::posix_errno posix() const { return m_cat->posix(value()); }
error_code generic_error_code() const { return m_cat->generic_error_code(value()); }
std::string message() const { return m_cat->message(value()); }
@@ -206,35 +201,40 @@
}
// relationals:
- bool operator==( const error_code & rhs ) const
+ inline friend bool same( const error_code & lhs,
+ const error_code & rhs )
+ // the more symmetrical non-member syntax is preferred
+ {
+ return lhs.m_cat == rhs.m_cat && lhs.m_val == rhs.m_val;
+ }
+
+ inline friend bool operator==( const error_code & lhs,
+ const error_code & rhs )
{
- if ( category() == rhs.category() ) return value() == rhs.value();
- return equivalent( *this, rhs );
+ if ( lhs.m_cat == rhs.m_cat ) return lhs.m_val == rhs.m_val;
+ return same( lhs, rhs.generic_error_code() )
+ || same( lhs.generic_error_code(), rhs );
+ // Rationale: As in the language proper, a single automatic conversion
+ // is acceptable, but two automatic conversions are not. Thus
+ // return same (lhs.generic_error_code(), rhs.generic_error_code()) is
+ // not an acceptable implementation as it performs two conversions.
}
- bool operator!=( const error_code & rhs ) const
+ inline friend bool operator!=( const error_code & lhs,
+ const error_code & rhs )
{
- return !(*this == rhs);
+ return !(lhs == rhs);
}
private:
int m_val;
const error_category * m_cat;
+
};
// non-member functions ------------------------------------------------//
- // the more symmetrical non-member syntax is preferred
- inline bool equal( const error_code & lhs, const error_code & rhs )
- {
- return lhs.category() == rhs.category() && lhs.value() == rhs.value();
- }
-
- inline bool equivalent( const error_code & lhs, const error_code & rhs )
- {
- return equal( lhs.generic_error_code(), rhs.generic_error_code() );
- }
// posix::posix_errno make_error_code:
inline error_code make_error_code( posix::posix_errno e )
@@ -260,6 +260,14 @@
: 0);
}
+ // error_category::generic_error_code ----------------------------------//
+ // implemented here now that error_code is a complete type
+ inline error_code error_category::generic_error_code( int ev) const
+ {
+ return error_code( ev, *this );
+ }
+
+
} // namespace system
} // namespace boost
Modified: branches/c++0x/boost/libs/system/src/error_code.cpp
==============================================================================
--- branches/c++0x/boost/libs/system/src/error_code.cpp (original)
+++ branches/c++0x/boost/libs/system/src/error_code.cpp 2007-08-08 13:51:01 EDT (Wed, 08 Aug 2007)
@@ -202,8 +202,6 @@
{
public:
const std::string & name() const;
- posix::posix_errno posix( int ev ) const;
- error_code generic_error_code( int ev ) const;
std::string message( int ev ) const;
};
@@ -227,16 +225,6 @@
return s;
}
- posix_errno posix_error_category::posix( int ev ) const
- {
- return static_cast<posix_errno>(ev);
- }
-
- error_code posix_error_category::generic_error_code( int ev ) const
- {
- return error_code( ev, posix_category );
- }
-
std::string posix_error_category::message( int ev ) const
{
// strerror_r is preferred because it is always thread safe,
Modified: branches/c++0x/boost/libs/system/test/error_code_test.cpp
==============================================================================
--- branches/c++0x/boost/libs/system/test/error_code_test.cpp (original)
+++ branches/c++0x/boost/libs/system/test/error_code_test.cpp 2007-08-08 13:51:01 EDT (Wed, 08 Aug 2007)
@@ -59,10 +59,12 @@
{
// unit tests:
error_code ec;
+ error_code gec;
BOOST_CHECK( !ec );
BOOST_CHECK( ec.value() == 0 );
- BOOST_CHECK( ec.posix() == 0 );
- BOOST_CHECK( ec.posix() == posix::no_error );
+ gec = ec.generic_error_code();
+ BOOST_CHECK( gec.value() == 0 );
+ BOOST_CHECK( gec.category() == posix_category );
BOOST_CHECK( ec == posix::no_error );
BOOST_CHECK( ec.category() == posix_category );
BOOST_CHECK( ec.category().name() == "POSIX" );
@@ -70,8 +72,9 @@
error_code ec_0_system( 0, system_category );
BOOST_CHECK( !ec_0_system );
BOOST_CHECK( ec_0_system.value() == 0 );
- BOOST_CHECK( ec_0_system.posix() == 0 );
- BOOST_CHECK( ec_0_system.posix() == posix::no_error );
+ gec = ec_0_system.generic_error_code();
+ BOOST_CHECK( gec.value() == 0 );
+ BOOST_CHECK( gec.category() == posix_category );
BOOST_CHECK( ec_0_system == posix::no_error );
BOOST_CHECK( ec_0_system.category() == system_category );
BOOST_CHECK( ec_0_system.category().name() == "system" );
@@ -90,9 +93,12 @@
ec = error_code( BOOST_ACCESS_ERROR_MACRO, system_category );
BOOST_CHECK( ec );
BOOST_CHECK( ec.value() == BOOST_ACCESS_ERROR_MACRO );
- BOOST_CHECK( ec.posix() == static_cast<int>(posix::permission_denied) );
- BOOST_CHECK( ec.posix() == posix::permission_denied );
- BOOST_CHECK( posix::permission_denied == ec.posix() );
+ gec = ec.generic_error_code();
+ BOOST_CHECK( gec.value() == static_cast<int>(posix::permission_denied) );
+ BOOST_CHECK( gec.category() == posix_category );
+ BOOST_CHECK( same( gec, error_code( posix::permission_denied, posix_category ) ) );
+ BOOST_CHECK( gec == posix::permission_denied );
+ BOOST_CHECK( posix::permission_denied == gec );
BOOST_CHECK( ec == posix::permission_denied );
BOOST_CHECK( ec.category() == system_category );
BOOST_CHECK( ec.category().name() == "system" );
@@ -103,31 +109,31 @@
ec = error_code( ERROR_FILE_NOT_FOUND, system_category );
BOOST_CHECK( ec.value() == ERROR_FILE_NOT_FOUND );
BOOST_CHECK( ec == posix::no_such_file_or_directory );
- BOOST_CHECK( ec.posix() == posix::no_such_file_or_directory );
+ BOOST_CHECK( ec.generic_error_code().value() == posix::no_such_file_or_directory );
// test the second entry in the decoder table:
ec = error_code( ERROR_PATH_NOT_FOUND, system_category );
BOOST_CHECK( ec.value() == ERROR_PATH_NOT_FOUND );
BOOST_CHECK( ec == posix::no_such_file_or_directory );
- BOOST_CHECK( ec.posix() == posix::no_such_file_or_directory );
+ BOOST_CHECK( ec.generic_error_code().value() == posix::no_such_file_or_directory );
// test the third entry in the decoder table:
ec = error_code( ERROR_ACCESS_DENIED, system_category );
BOOST_CHECK( ec.value() == ERROR_ACCESS_DENIED );
BOOST_CHECK( ec == posix::permission_denied );
- BOOST_CHECK( ec.posix() == posix::permission_denied );
+ BOOST_CHECK( ec.generic_error_code().value() == posix::permission_denied );
// test the last regular entry in the decoder table:
ec = error_code( ERROR_WRITE_PROTECT, system_category );
BOOST_CHECK( ec.value() == ERROR_WRITE_PROTECT );
BOOST_CHECK( ec == posix::permission_denied );
- BOOST_CHECK( ec.posix() == posix::permission_denied );
+ BOOST_CHECK( ec.generic_error_code().value() == posix::permission_denied );
// test not-in-table condition:
ec = error_code( 1234567890, system_category );
BOOST_CHECK( ec.value() == 1234567890 );
BOOST_CHECK( ec == posix::no_posix_equivalent );
- BOOST_CHECK( ec.posix() == posix::no_posix_equivalent );
+ BOOST_CHECK( ec.generic_error_code().value() == posix::no_posix_equivalent );
#else
// TODO: write some POSIX tests
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk