varconf  1.0.3
Configuration library for the Worldforge system.
parse_error.cpp
1 /*
2  * parse_error.cpp - implementation of the parse error handling class
3  * Copyright (C) 2001, Stefanus Du Toit, Joseph Zupko
4  * (C) 2003-2004 Alistair Riddoch
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  * Contact: Joseph Zupko
21  * jaz147@psu.edu
22  *
23  * 189 Reese St.
24  * Old Forge, PA 18518
25  */
26 
27 #include "parse_error.h"
28 
29 #include <cstdio>
30 #include <iostream>
31 
32 #ifdef _WIN32
33 #define snprintf _snprintf
34 #endif
35 
36 namespace varconf {
37 
38 ParseError::ParseError( const ParseError& p)
39 {
40  m_exp = p.m_exp;
41  m_line = p.m_line;
42  m_col = p.m_col;
43 }
44 
45 ParseError::ParseError( const std::string& exp, int line, int col)
46 {
47  m_exp = exp;
48  m_line = line;
49  m_col = col;
50 }
51 
52 ParseError::~ParseError() = default;
53 
54 std::ostream& operator<<( std::ostream& os, const ParseError& p)
55 {
56  return ( os << "ParseError: Expected " << p.m_exp << " at line " << p.m_line
57  << ", column " << p.m_col << "." << std::endl);
58 }
59 
60 ParseError::operator std::string()
61 {
62  char buf[1024];
63  snprintf( buf, 1024, "ParseError: Expected %s at line %d, column %d.",
64  m_exp.c_str(), m_line, m_col);
65  return std::string( buf);
66 }
67 
68 ParseError::operator std::string() const
69 {
70  char buf[1024];
71  snprintf( buf, 1024, "ParseError: Expected %s at line %d, column %d.",
72  m_exp.c_str(), m_line, m_col);
73  return std::string( buf);
74 }
75 
76 } // namespace varconf