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#include <sstream>
16
17namespace boost { namespace property_tree
18{
19
20 //! File parse error
21 class file_parser_error: public ptree_error
22 {
23
24 public:
25
26 ///////////////////////////////////////////////////////////////////////
27 // Construction
28
29 // Construct error
30 file_parser_error(const std::string &msg,
31 const std::string &file,
32 unsigned long l) :
33 ptree_error(format_what(msg, file, l)),
34 m_message(msg), m_filename(file), m_line(l)
35 {
36 }
37
38 ///////////////////////////////////////////////////////////////////////
39 // Data access
40
41 // Get error message (without line and file - use what() to get
42 // full message)
43 std::string message() const
44 {
45 return m_message;
46 }
47
48 // Get error filename
49 std::string filename() const
50 {
51 return m_filename;
52 }
53
54 // Get error line number
55 unsigned long line() const
56 {
57 return m_line;
58 }
59
60 private:
61
62 std::string m_message;
63 std::string m_filename;
64 unsigned long m_line;
65
66 // Format error message to be returned by std::runtime_error::what()
67 static std::string format_what(const std::string &msg,
68 const std::string &file,
69 unsigned long l)
70 {
71 std::stringstream stream;
72 stream << (file.empty() ? "<unspecified file>" : file.c_str());
73 if (l > 0)
74 stream << '(' << l << ')';
75 stream << ": " << msg;
76 return stream.str();
77 }
78
79 };
80
81} }
82
83#endif
84

source code of boost/libs/property_tree/include/boost/property_tree/detail/file_parser_error.hpp