]> git.donarmstrong.com Git - flightcrew.git/blob - src/FlightCrew/Result.cpp
Imported Upstream version 0.7.2+dfsg
[flightcrew.git] / src / FlightCrew / Result.cpp
1 /************************************************************************\r
2 **\r
3 **  Copyright (C) 2010  Strahinja Markovic\r
4 **\r
5 **  This file is part of FlightCrew.\r
6 **\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
11 **\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
16 **\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
19 **\r
20 *************************************************************************/\r
21 \r
22 #include <stdafx.h>\r
23 #include "Result.h"\r
24 #include "ErrorMessages.h"\r
25 \r
26 namespace FlightCrew\r
27 {\r
28 \r
29 Result::Result( ResultId result_id, xe::NodeLocationInfo node_location )\r
30     :\r
31     m_ResultId( result_id ),\r
32     m_ErrorLine( node_location.LineNumber ),\r
33     m_ErrorColumn( node_location.ColumnNumber )\r
34 {\r
35 \r
36 }\r
37 \r
38 ResultType Result::GetResultType() const\r
39 {\r
40     if ( static_cast< int >( m_ResultId ) < static_cast< int >( ResultType_WARNING ) )\r
41 \r
42         return ResultType_ERROR;\r
43 \r
44     return ResultType_WARNING;\r
45 }\r
46 \r
47 \r
48 ResultId Result::GetResultId() const\r
49 {\r
50     return m_ResultId;\r
51 }\r
52 \r
53 \r
54 Result& Result::SetResultId( ResultId result_id )\r
55 {\r
56     m_ResultId = result_id;\r
57     return *this;\r
58 }\r
59 \r
60 \r
61 int Result::GetErrorLine() const\r
62 {\r
63     return m_ErrorLine;\r
64 }\r
65 \r
66 \r
67 Result& Result::SetErrorLine( int error_line )\r
68 {\r
69     m_ErrorLine = error_line;\r
70     return *this;\r
71 }\r
72 \r
73 \r
74 int Result::GetErrorColumn() const\r
75 {\r
76     return m_ErrorColumn;\r
77 }\r
78 \r
79 \r
80 Result& Result::SetErrorColumn( int error_line )\r
81 {\r
82     m_ErrorColumn = error_line;\r
83     return *this;\r
84 }\r
85 \r
86 \r
87 std::string Result::GetFilepath() const\r
88 {\r
89     return m_Filepath;\r
90 }\r
91 \r
92 \r
93 Result& Result::SetFilepath( const std::string &filepath )\r
94 {\r
95     m_Filepath = filepath;\r
96     return *this;\r
97 }\r
98 \r
99 \r
100 Result& Result::AddMessageArgument( const std::string &message_argument )\r
101 {\r
102     m_MessageArguments.push_back( message_argument );\r
103     return *this;\r
104 }\r
105 \r
106 \r
107 Result& Result::SetMessageArguments( const std::vector< std::string > &message_arguments )\r
108 {\r
109     m_MessageArguments = message_arguments;\r
110     return *this;\r
111 }\r
112 \r
113 \r
114 const std::vector< std::string > & Result::GetMessageArguments() const\r
115 {\r
116     return m_MessageArguments;\r
117 }\r
118 \r
119 \r
120 std::string Result::GetMessage() const\r
121 {\r
122     if ( !m_CustomMessage.empty() )\r
123 \r
124         return m_CustomMessage;\r
125 \r
126     boost::format formatter( ErrorMessages::Instance().MessageForId( m_ResultId ) );\r
127 \r
128     foreach( std::string argument, m_MessageArguments )\r
129     {\r
130         formatter % argument;\r
131     }\r
132 \r
133     return formatter.str();\r
134 }\r
135 \r
136 \r
137 Result& Result::SetCustomMessage( const std::string &custom_message )\r
138 {\r
139     m_CustomMessage = custom_message;\r
140     return *this;\r
141 }\r
142 \r
143 \r
144 bool Result::operator< ( const Result& other ) const\r
145 {\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
152 \r
153     return\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
165 }\r
166 \r
167 \r
168 bool Result::operator==( const Result& other ) const\r
169 {\r
170     return\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
177 }\r
178 \r
179 \r
180 } // namespace FlightCrew\r
181 \r
182 \r