1 /*
2  Copyright (C) 2010-2014 Kristian Duske
3 
4  This file is part of TrenchBroom.
5 
6  TrenchBroom is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  TrenchBroom 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
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "ParserStatus.h"
21 #include "Exceptions.h"
22 
23 namespace TrenchBroom {
24     namespace IO {
ParserStatus(Logger * logger)25         ParserStatus::ParserStatus(Logger* logger) :
26         m_logger(logger) {}
27 
~ParserStatus()28         ParserStatus::~ParserStatus() {}
29 
progress(const double progress)30         void ParserStatus::progress(const double progress) {
31             assert(progress >= 0.0 && progress <= 1.0);
32             doProgress(progress);
33         }
34 
debug(const size_t line,const size_t column,const String & str)35         void ParserStatus::debug(const size_t line, const size_t column, const String& str) {
36             log(Logger::LogLevel_Debug, line, column, str);
37         }
38 
info(const size_t line,const size_t column,const String & str)39         void ParserStatus::info(const size_t line, const size_t column, const String& str) {
40             log(Logger::LogLevel_Debug, line, column, str);
41         }
42 
warn(const size_t line,const size_t column,const String & str)43         void ParserStatus::warn(const size_t line, const size_t column, const String& str) {
44             log(Logger::LogLevel_Debug, line, column, str);
45         }
46 
error(const size_t line,const size_t column,const String & str)47         void ParserStatus::error(const size_t line, const size_t column, const String& str) {
48             log(Logger::LogLevel_Debug, line, column, str);
49         }
50 
errorAndThrow(size_t line,size_t column,const String & str)51         void ParserStatus::errorAndThrow(size_t line, size_t column, const String& str) {
52             error(line, column, str);
53             throw ParserException(buildMessage(line, column, str));
54         }
55 
log(const Logger::LogLevel level,const size_t line,const size_t column,const String & str)56         void ParserStatus::log(const Logger::LogLevel level, const size_t line, const size_t column, const String& str) {
57             if (m_logger != NULL)
58                 m_logger->log(level, buildMessage(line, column, str));
59         }
60 
buildMessage(const size_t line,const size_t column,const String & str) const61         String ParserStatus::buildMessage(const size_t line, const size_t column, const String& str) const {
62             StringStream msg;
63             msg << str << " (line " << line << ", column " << column << ")";
64             return msg.str();
65         }
66     }
67 }
68