Added commonly used error_info typedefs.

Added boost/exception/all.hpp.
Removed tabs from source files.

[SVN r54825]
This commit is contained in:
Emil Dotchevski
2009-07-08 23:44:28 +00:00
parent a0614793b3
commit bd0ed9f83b
18 changed files with 321 additions and 0 deletions

View File

@ -0,0 +1,26 @@
//Copyright (c) 2006-2008 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_316FDA946C0D11DEA9CBAE5255D89593
#define UUID_316FDA946C0D11DEA9CBAE5255D89593
#include <boost/exception/diagnostic_information.hpp>
#include <boost/exception/error_info.hpp>
#include <boost/exception/exception.hpp>
#include <boost/exception/get_error_info.hpp>
#include <boost/exception/info.hpp>
#include <boost/exception/info_tuple.hpp>
#include <boost/exception/errinfo_api_function.hpp>
#include <boost/exception/errinfo_at_line.hpp>
#include <boost/exception/errinfo_errno.hpp>
#include <boost/exception/errinfo_file_handle.hpp>
#include <boost/exception/errinfo_file_name.hpp>
#include <boost/exception/errinfo_file_open_mode.hpp>
#include <boost/exception/errinfo_type_info_name.hpp>
#ifndef BOOST_NO_EXCEPTIONS
#include <boost/exception_ptr.hpp>
#endif
#endif

View File

@ -0,0 +1,22 @@
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_DDFBB4546C1211DEA4659E9055D89593
#define UUID_DDFBB4546C1211DEA4659E9055D89593
#include "boost/exception/error_info.hpp"
namespace
boost
{
//Usage hint:
//if( api_function(....)!=0 )
// BOOST_THROW_EXCEPTION(
// failure() <<
// errinfo_api_function("api_function") );
typedef error_info<struct errinfo_api_function_,char const *> errinfo_api_function;
}
#endif

View File

@ -0,0 +1,18 @@
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_E7255CE26C1211DE85800C9155D89593
#define UUID_E7255CE26C1211DE85800C9155D89593
namespace
boost
{
template <class Tag,class T> class error_info;
//Use with parsing errors exceptions, for example in a XML file parser.
typedef error_info<struct errinfo_at_line_,int> errinfo_at_line;
}
#endif

View File

@ -0,0 +1,34 @@
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_F0EE17BE6C1211DE87FF459155D89593
#define UUID_F0EE17BE6C1211DE87FF459155D89593
#include "boost/exception/info.hpp"
#include <errno.h>
namespace
boost
{
typedef error_info<struct errinfo_errno_,int> errinfo_errno;
//Usage hint:
//if( c_function(....)!=0 )
// BOOST_THROW_EXCEPTION(
// failure() <<
// errinfo_errno(errno) <<
// errinfo_api_function("c_function") );
inline
std::string
to_string( errinfo_errno const & e )
{
std::ostringstream tmp;
int v=e.value();
tmp << v << ", \"" << strerror(v) << "\"";
return tmp.str();
}
}
#endif

View File

@ -0,0 +1,20 @@
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_F79E6EE26C1211DEB26E929155D89593
#define UUID_F79E6EE26C1211DEB26E929155D89593
#include <stdio.h>
namespace
boost
{
template <class> class weak_ptr;
template <class Tag,class T> class error_info;
typedef error_info<struct errinfo_file_handle_,weak_ptr<FILE> > errinfo_file_handle;
}
#endif

View File

@ -0,0 +1,26 @@
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_FEE5120A6C1211DE94E8BC9155D89593
#define UUID_FEE5120A6C1211DE94E8BC9155D89593
#include <string>
namespace
boost
{
template <class Tag,class T> class error_info;
//Usage hint:
//FILE * f=fopen(name,mode);
//if( !f )
// BOOST_THROW_EXCEPTION(
// file_open_error() <<
// errinfo_file_name(name) <<
// errinfo_file_open_mode(mode) );
typedef error_info<struct errinfo_file_name_,std::string> errinfo_file_name;
}
#endif

View File

@ -0,0 +1,26 @@
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_056F1F266C1311DE8E74299255D89593
#define UUID_056F1F266C1311DE8E74299255D89593
#include <string>
namespace
boost
{
template <class Tag,class T> class error_info;
//Usage hint:
//FILE * f=fopen(name,mode);
//if( !f )
// BOOST_THROW_EXCEPTION(
// file_open_error() <<
// errinfo_file_name(name) <<
// errinfo_file_open_mode(mode) );
typedef error_info<struct errinfo_file_open_mode_,std::string> errinfo_file_open_mode;
}
#endif

View File

@ -0,0 +1,23 @@
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
//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)
#ifndef UUID_0E11109E6C1311DEB7EA649255D89593
#define UUID_0E11109E6C1311DEB7EA649255D89593
#include <string>
namespace
boost
{
template <class Tag,class T> class error_info;
//Usage hint:
//BOOST_THROW_EXCEPTION(
// bad_type() <<
// errinfo_type_info_name(typeid(x).name()) );
typedef error_info<struct errinfo_type_info_name_,std::string> errinfo_type_info_name;
}
#endif

View File

@ -35,6 +35,7 @@ run diagnostic_information_test.cpp ;
run refcount_ptr_test.cpp ;
run current_exception_cast_test.cpp ;
run no_exceptions_test.cpp : : : <exception-handling>off ;
run errinfos_test.cpp ;
compile-fail exception_fail.cpp ;
compile-fail throw_exception_fail.cpp ;
@ -49,4 +50,12 @@ compile info_hpp_test.cpp ;
compile info_tuple_hpp_test.cpp ;
compile to_string_hpp_test.cpp ;
compile to_string_stub_hpp_test.cpp ;
compile all_hpp_test.cpp ;
compile current_exception_cast_hpp_test.cpp ;
compile errinfo_api_function_hpp_test.cpp ;
compile errinfo_at_line_hpp_test.cpp ;
compile errinfo_errno_hpp_test.cpp ;
compile errinfo_file_handle_hpp_test.cpp ;
compile errinfo_file_name_hpp_test.cpp ;
compile errinfo_file_open_mode_hpp_test.cpp ;
compile errinfo_type_info_name_hpp_test.cpp ;

7
test/all_hpp_test.cpp Normal file
View File

@ -0,0 +1,7 @@
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
//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)
#include <boost/exception/all.hpp>
#include <boost/exception/all.hpp>

View File

@ -0,0 +1,7 @@
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
//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)
#include <boost/exception/errinfo_api_function.hpp>
#include <boost/exception/errinfo_api_function.hpp>

View File

@ -0,0 +1,7 @@
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
//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)
#include <boost/exception/errinfo_at_line.hpp>
#include <boost/exception/errinfo_at_line.hpp>

View File

@ -0,0 +1,7 @@
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
//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)
#include <boost/exception/errinfo_errno.hpp>
#include <boost/exception/errinfo_errno.hpp>

View File

@ -0,0 +1,7 @@
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
//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)
#include <boost/exception/errinfo_file_handle.hpp>
#include <boost/exception/errinfo_file_handle.hpp>

View File

@ -0,0 +1,7 @@
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
//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)
#include <boost/exception/errinfo_file_name.hpp>
#include <boost/exception/errinfo_file_name.hpp>

View File

@ -0,0 +1,7 @@
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
//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)
#include <boost/exception/errinfo_file_open_mode.hpp>
#include <boost/exception/errinfo_file_open_mode.hpp>

View File

@ -0,0 +1,7 @@
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
//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)
#include <boost/exception/errinfo_type_info_name.hpp>
#include <boost/exception/errinfo_type_info_name.hpp>

61
test/errinfos_test.cpp Normal file
View File

@ -0,0 +1,61 @@
//Copyright (c) 2006-2009 Emil Dotchevski and Reverge Studios, Inc.
//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)
#include <boost/exception/errinfo_api_function.hpp>
#include <boost/exception/errinfo_at_line.hpp>
#include <boost/exception/errinfo_errno.hpp>
#include <boost/exception/errinfo_file_handle.hpp>
#include <boost/exception/errinfo_file_name.hpp>
#include <boost/exception/errinfo_file_open_mode.hpp>
#include <boost/exception/errinfo_type_info_name.hpp>
#include <boost/exception/info.hpp>
#include <boost/exception/get_error_info.hpp>
#include <boost/throw_exception.hpp>
#include <boost/weak_ptr.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <exception>
struct
test_exception:
virtual boost::exception,
virtual std::exception
{
};
int
main()
{
using namespace boost;
try
{
BOOST_THROW_EXCEPTION(
test_exception() <<
errinfo_api_function("failed_api_function") <<
errinfo_at_line(42) <<
errinfo_errno(errno) <<
errinfo_file_handle(weak_ptr<FILE>()) <<
errinfo_file_name("filename.txt") <<
errinfo_file_open_mode("rb") <<
errinfo_type_info_name(typeid(int).name()) );
BOOST_TEST(false);
}
catch(
exception & e )
{
BOOST_TEST(get_error_info<errinfo_api_function>(e) && *get_error_info<errinfo_api_function>(e)==std::string("failed_api_function"));
BOOST_TEST(get_error_info<errinfo_at_line>(e) && *get_error_info<errinfo_at_line>(e)==42);
BOOST_TEST(get_error_info<errinfo_errno>(e) && *get_error_info<errinfo_errno>(e)==0);
BOOST_TEST(get_error_info<errinfo_file_handle>(e) && get_error_info<errinfo_file_handle>(e)->expired());
BOOST_TEST(get_error_info<errinfo_file_name>(e) && *get_error_info<errinfo_file_name>(e)=="filename.txt");
BOOST_TEST(get_error_info<errinfo_file_open_mode>(e) && *get_error_info<errinfo_file_open_mode>(e)=="rb");
BOOST_TEST(get_error_info<errinfo_type_info_name>(e) && *get_error_info<errinfo_type_info_name>(e)==typeid(int).name());
}
catch(
... )
{
BOOST_TEST(false);
}
return boost::report_errors();
}