PageRenderTime 11ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 1ms

/Src/Dependencies/Boost/boost/property_tree/detail/file_parser_error.hpp

http://hadesmem.googlecode.com/
C++ Header | 88 lines | 49 code | 17 blank | 22 comment | 1 complexity | e1fadaeb42cebcbeb6e122e0b794a9d0 MD5 | raw file
 1// ----------------------------------------------------------------------------
 2// Copyright (C) 2002-2006 Marcin Kalicinski
 3//
 4// Distributed under the Boost Software License, Version 1.0. 
 5// (See accompanying file LICENSE_1_0.txt or copy at 
 6// http://www.boost.org/LICENSE_1_0.txt)
 7//
 8// For more information, see www.boost.org
 9// ----------------------------------------------------------------------------
10#ifndef BOOST_PROPERTY_TREE_DETAIL_FILE_PARSER_ERROR_HPP_INCLUDED
11#define BOOST_PROPERTY_TREE_DETAIL_FILE_PARSER_ERROR_HPP_INCLUDED
12
13#include <boost/property_tree/ptree.hpp>
14#include <string>
15
16namespace boost { namespace property_tree
17{
18
19    //! File parse error
20    class file_parser_error: public ptree_error
21    {
22
23    public:
24
25        ///////////////////////////////////////////////////////////////////////
26        // Construction & destruction
27
28        // Construct error
29        file_parser_error(const std::string &msg,
30                          const std::string &file,
31                          unsigned long l) :
32            ptree_error(format_what(msg, file, l)),
33            m_message(msg), m_filename(file), m_line(l)
34        {
35        }
36
37        ~file_parser_error() throw()
38            // gcc 3.4.2 complains about lack of throw specifier on compiler
39            // generated dtor
40        {
41        }
42
43        ///////////////////////////////////////////////////////////////////////
44        // Data access
45
46        // Get error message (without line and file - use what() to get
47        // full message)
48        std::string message() const
49        {
50            return m_message;
51        }
52
53        // Get error filename
54        std::string filename() const
55        {
56            return m_filename;
57        }
58
59        // Get error line number
60        unsigned long line() const
61        {
62            return m_line;
63        }
64
65    private:
66
67        std::string m_message;
68        std::string m_filename;
69        unsigned long m_line;
70
71        // Format error message to be returned by std::runtime_error::what()
72        static std::string format_what(const std::string &msg,
73                                       const std::string &file,
74                                       unsigned long l)
75        {
76            std::stringstream stream;
77            stream << (file.empty() ? "<unspecified file>" : file.c_str());
78            if (l > 0)
79                stream << '(' << l << ')';
80            stream << ": " << msg;
81            return stream.str();
82        }
83
84    };
85
86} }
87
88#endif