Boost logo

Boost-Commit :

From: bdawes_at_[hidden]
Date: 2007-08-30 15:16:19


Author: bemandawes
Date: 2007-08-30 15:16:17 EDT (Thu, 30 Aug 2007)
New Revision: 39078
URL: http://svn.boost.org/trac/boost/changeset/39078

Log:
Add error_condition::operator<, error_code::operator<, minor code cleanups, add BOOST_ERROR_CODE_HEADER_ONLY, header_only_test.cpp
Added:
   branches/libs/system/system/test/header_only_test.cpp (contents, props changed)
Text files modified:
   branches/libs/system/boost/system/error_code.hpp | 40 +++++++++++++++++++++++++++++++---------
   branches/libs/system/system/test/error_code_test.cpp | 6 +++++-
   2 files changed, 36 insertions(+), 10 deletions(-)

Modified: branches/libs/system/boost/system/error_code.hpp
==============================================================================
--- branches/libs/system/boost/system/error_code.hpp (original)
+++ branches/libs/system/boost/system/error_code.hpp 2007-08-30 15:16:17 EDT (Thu, 30 Aug 2007)
@@ -233,8 +233,17 @@
                                      const error_condition & rhs )
       {
         return lhs.m_cat == rhs.m_cat && lhs.m_val == rhs.m_val;
+ }
+
+ inline friend bool operator<( const error_condition & lhs,
+ const error_condition & rhs )
+ // the more symmetrical non-member syntax allows enum
+ // conversions work for both rhs and lhs.
+ {
+ return lhs.m_cat < rhs.m_cat
+ || (lhs.m_cat == rhs.m_cat && lhs.m_val < rhs.m_val);
       }
-
+
     private:
       int m_val;
       const error_category * m_cat;
@@ -312,6 +321,15 @@
       {
         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 )
+ // the more symmetrical non-member syntax allows enum
+ // conversions work for both rhs and lhs.
+ {
+ return lhs.m_cat < rhs.m_cat
+ || (lhs.m_cat == rhs.m_cat && lhs.m_val < rhs.m_val);
+ }
                   
       private:
       int m_val;
@@ -333,11 +351,11 @@
       return !(lhs == rhs);
     }
 
- inline bool operator==( const error_code & lhs,
- const error_condition & rhs )
+ inline bool operator==( const error_code & code,
+ const error_condition & condition )
     {
- return lhs.category().equivalent( lhs.value(), rhs )
- || rhs.category().equivalent( lhs, rhs.value() );
+ return code.category().equivalent( code.value(), condition )
+ || condition.category().equivalent( code, condition.value() );
     }
                 
     inline bool operator!=( const error_code & lhs,
@@ -346,11 +364,11 @@
       return !(lhs == rhs);
     }
                 
- inline bool operator==( const error_condition & lhs,
- const error_code & rhs )
+ inline bool operator==( const error_condition & condition,
+ const error_code & code )
     {
- return lhs.category().equivalent( rhs, lhs.value() )
- || rhs.category().equivalent( rhs.value(), lhs );
+ return condition.category().equivalent( code, condition.value() )
+ || code.category().equivalent( code.value(), condition );
     }
                 
     inline bool operator!=( const error_condition & lhs,
@@ -632,6 +650,10 @@
 
 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
 
+# ifdef BOOST_ERROR_CODE_HEADER_ONLY
+# include <boost/../libs/system/src/error_code.cpp>
+# endif
+
 #endif // BOOST_ERROR_CODE_HPP
 
 

Modified: branches/libs/system/system/test/error_code_test.cpp
==============================================================================
--- branches/libs/system/system/test/error_code_test.cpp (original)
+++ branches/libs/system/system/test/error_code_test.cpp 2007-08-30 15:16:17 EDT (Thu, 30 Aug 2007)
@@ -10,7 +10,7 @@
 //----------------------------------------------------------------------------//
 
 // VC++ 8.0 warns on usage of certain Standard Library and API functions that
-// can be cause buffer overruns or no_posix_equivalent possible security issues if misused.
+// can be cause buffer overruns or other possible security issues if misused.
 // See http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx
 // But the wording of the warning is misleading and unsettling, there are no
 // portable altersystem functions, and VC++ 8.0's own libraries use the
@@ -69,6 +69,10 @@
   BOOST_CHECK( ec == posix::success );
   BOOST_CHECK( ec.category() == system_category );
   BOOST_CHECK( ec.category().name() == "system" );
+ BOOST_CHECK( !(ec < error_code( 0, system_category )) );
+ BOOST_CHECK( !(error_code( 0, system_category ) < ec) );
+ BOOST_CHECK( ec < error_code( 1, system_category ) );
+ BOOST_CHECK( !(error_code( 1, system_category ) < ec) );
 
   error_code ec_0_system( 0, system_category );
   BOOST_CHECK( !ec_0_system );

Added: branches/libs/system/system/test/header_only_test.cpp
==============================================================================
--- (empty file)
+++ branches/libs/system/system/test/header_only_test.cpp 2007-08-30 15:16:17 EDT (Thu, 30 Aug 2007)
@@ -0,0 +1,31 @@
+// error_code_test.cpp -----------------------------------------------------//
+
+// Copyright Beman Dawes 2006
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See library home page at http://www.boost.org/libs/system
+
+//----------------------------------------------------------------------------//
+
+// VC++ 8.0 warns on usage of certain Standard Library and API functions that
+// can be cause buffer overruns or other possible security issues if misused.
+// See http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx
+// But the wording of the warning is misleading and unsettling, there are no
+// portable altersystem functions, and VC++ 8.0's own libraries use the
+// functions in question. So turn off the warnings.
+#define _CRT_SECURE_NO_DEPRECATE
+#define _SCL_SECURE_NO_DEPRECATE
+
+#define BOOST_ERROR_CODE_HEADER_ONLY
+
+#include <boost/test/minimal.hpp>
+
+#include <boost/system/error_code.hpp>
+
+int test_main( int, char*[] )
+{
+ boost::system::error_code ec( 0, boost::system::system_category );
+ return 0;
+}
\ No newline at end of file


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