comparison C++/Parser.cpp @ 205:9f22ce5f1b39

Parser: rename getValue, add operator==
author David Demelier <markand@malikania.fr>
date Sun, 16 Feb 2014 12:39:03 +0100
parents 1ffe6d4937b7
children 3b0e276f0866
comparison
equal deleted inserted replaced
204:7086e93bc4ea 205:9f22ce5f1b39
1 /* 1 /*
2 * Parser.h -- config file parser 2 * Parser.h -- config file parser
3 * 3 *
4 * Copyright (c) 2011, 2012, 2013 David Demelier <markand@malikania.fr> 4 * Copyright (c) 2013, 2014 David Demelier <markand@malikania.fr>
5 * 5 *
6 * Permission to use, copy, modify, and/or distribute this software for any 6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above 7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies. 8 * copyright notice and this permission notice appear in all copies.
9 * 9 *
65 } 65 }
66 66
67 Section::Map::const_iterator Section::cend() const 67 Section::Map::const_iterator Section::cend() const
68 { 68 {
69 return m_options.end(); 69 return m_options.end();
70 }
71
72 bool operator==(const Section &s1, const Section &s2)
73 {
74 return s1.m_name == s2.m_name && s1.m_options == s2.m_options;
70 } 75 }
71 76
72 /* -------------------------------------------------------- 77 /* --------------------------------------------------------
73 * Parser private members 78 * Parser private members
74 * -------------------------------------------------------- */ 79 * -------------------------------------------------------- */
208 std::string line; 213 std::string line;
209 int lineno = 1; 214 int lineno = 1;
210 215
211 file.open(m_path.c_str()); 216 file.open(m_path.c_str());
212 if (!file.is_open()) 217 if (!file.is_open())
213 throw std::runtime_error(m_path + std::string(std::strerror(errno))); 218 throw std::runtime_error(m_path + ": " + std::string(std::strerror(errno)));
214 219
215 while (std::getline(file, line)) 220 while (std::getline(file, line))
216 readLine(lineno++, line); 221 readLine(lineno++, line);
217 222
218 file.close(); 223 file.close();
286 291
287 void Parser::log(int number, const std::string &, const std::string &message) 292 void Parser::log(int number, const std::string &, const std::string &message)
288 { 293 {
289 std::cout << "line " << number << ": " << message << std::endl; 294 std::cout << "line " << number << ": " << message << std::endl;
290 } 295 }
296
297 bool operator==(const Parser &p1, const Parser &p2)
298 {
299 return p1.m_sections == p2.m_sections &&
300 p1.m_path == p2.m_path &&
301 p1.m_tuning == p2.m_tuning &&
302 p1.m_commentChar == p2.m_commentChar;
303 }