1 /************************************************************************
\r
3 ** Copyright (C) 2010 Strahinja Markovic
\r
5 ** This file is part of FlightCrew.
\r
7 ** FlightCrew is free software: you can redistribute it and/or modify
\r
8 ** it under the terms of the GNU Lesser General Public License as published
\r
9 ** by the Free Software Foundation, either version 3 of the License, or
\r
10 ** (at your option) any later version.
\r
12 ** FlightCrew is distributed in the hope that it will be useful,
\r
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 ** GNU Lesser General Public License for more details.
\r
17 ** You should have received a copy of the GNU Lesser General Public License
\r
18 ** along with FlightCrew. If not, see <http://www.gnu.org/licenses/>.
\r
20 *************************************************************************/
\r
24 #include "ErrorMessages.h"
\r
26 namespace FlightCrew
\r
29 Result::Result( ResultId result_id, xe::NodeLocationInfo node_location )
\r
31 m_ResultId( result_id ),
\r
32 m_ErrorLine( node_location.LineNumber ),
\r
33 m_ErrorColumn( node_location.ColumnNumber )
\r
38 ResultType Result::GetResultType() const
\r
40 if ( static_cast< int >( m_ResultId ) < static_cast< int >( ResultType_WARNING ) )
\r
42 return ResultType_ERROR;
\r
44 return ResultType_WARNING;
\r
48 ResultId Result::GetResultId() const
\r
54 Result& Result::SetResultId( ResultId result_id )
\r
56 m_ResultId = result_id;
\r
61 int Result::GetErrorLine() const
\r
67 Result& Result::SetErrorLine( int error_line )
\r
69 m_ErrorLine = error_line;
\r
74 int Result::GetErrorColumn() const
\r
76 return m_ErrorColumn;
\r
80 Result& Result::SetErrorColumn( int error_line )
\r
82 m_ErrorColumn = error_line;
\r
87 std::string Result::GetFilepath() const
\r
93 Result& Result::SetFilepath( const std::string &filepath )
\r
95 m_Filepath = filepath;
\r
100 Result& Result::AddMessageArgument( const std::string &message_argument )
\r
102 m_MessageArguments.push_back( message_argument );
\r
107 Result& Result::SetMessageArguments( const std::vector< std::string > &message_arguments )
\r
109 m_MessageArguments = message_arguments;
\r
114 const std::vector< std::string > & Result::GetMessageArguments() const
\r
116 return m_MessageArguments;
\r
120 std::string Result::GetMessage() const
\r
122 if ( !m_CustomMessage.empty() )
\r
124 return m_CustomMessage;
\r
126 boost::format formatter( ErrorMessages::Instance().MessageForId( m_ResultId ) );
\r
128 foreach( std::string argument, m_MessageArguments )
\r
130 formatter % argument;
\r
133 return formatter.str();
\r
137 Result& Result::SetCustomMessage( const std::string &custom_message )
\r
139 m_CustomMessage = custom_message;
\r
144 bool Result::operator< ( const Result& other ) const
\r
146 // Yes, this is ugly but it also needs to be fast.
\r
147 // We need to make sure that all private vars are
\r
148 // included because some STL algos uses two "<"
\r
149 // operations to check for equality. Since this is
\r
150 // called freaking everywhere, we have to make sure
\r
151 // only the required comparisons are made, and no more.
\r
154 m_Filepath != other.m_Filepath ?
\r
155 m_Filepath < other.m_Filepath :
\r
156 m_ErrorLine != other.m_ErrorLine ?
\r
157 m_ErrorLine < other.m_ErrorLine :
\r
158 m_ErrorColumn != other.m_ErrorColumn ?
\r
159 m_ErrorColumn < other.m_ErrorColumn :
\r
160 m_ResultId != other.m_ResultId ?
\r
161 m_ResultId < other.m_ResultId :
\r
162 m_CustomMessage != other.m_CustomMessage ?
\r
163 m_CustomMessage < other.m_CustomMessage :
\r
164 m_MessageArguments < other.m_MessageArguments;
\r
168 bool Result::operator==( const Result& other ) const
\r
171 m_ResultId == other.m_ResultId &&
\r
172 m_ErrorLine == other.m_ErrorLine &&
\r
173 m_ErrorColumn == other.m_ErrorColumn &&
\r
174 m_Filepath == other.m_Filepath &&
\r
175 m_CustomMessage == other.m_CustomMessage &&
\r
176 m_MessageArguments == other.m_MessageArguments;
\r
180 } // namespace FlightCrew
\r