]> git.donarmstrong.com Git - flightcrew.git/blob - src/FlightCrew/Result.h
Imported Upstream version 0.7.2+dfsg
[flightcrew.git] / src / FlightCrew / Result.h
1 /************************************************************************
2 **
3 **  Copyright (C) 2010  Strahinja Markovic
4 **
5 **  This file is part of FlightCrew.
6 **
7 **  FlightCrew is free software: you can redistribute it and/or modify
8 **  it under the terms of the GNU Lesser General Public License as published
9 **  by the Free Software Foundation, either version 3 of the License, or
10 **  (at your option) any later version.
11 **
12 **  FlightCrew is distributed in the hope that it will be useful,
13 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 **  GNU Lesser General Public License for more details.
16 **
17 **  You should have received a copy of the GNU Lesser General Public License
18 **  along with FlightCrew.  If not, see <http://www.gnu.org/licenses/>.
19 **
20 *************************************************************************/
21
22 #pragma once
23 #ifndef RESULT_H
24 #define RESULT_H
25
26 #include <string>
27 #include <vector>
28 #include <NodeLocationInfo.h>
29 #include "ResultId.h"
30 #include "DllExporting.h"
31
32 #if defined(_MSC_VER)
33 // This warning complains that the private members 
34 // of this class that use the STL are not being exported
35 // for use by clients.
36 // Since the clients can't even access the private members 
37 // of this class, it's not a problem.
38 #   pragma warning( disable : 4251 )
39 #endif
40
41 namespace FlightCrew
42 {
43
44 /**
45  * Defines a validation result, usually a warning or error.
46  * Users that just want to consume a prepared Result should 
47  * look at the GetErrorLine, GetErrorColumn and GetMessage 
48  * member functions.
49  */
50 class FC_WIN_DLL_API Result
51 {
52
53 public:
54
55     /**
56      * Constructor.
57      *
58      * @param result_id The ID of the Result.
59      * @param node_location The DOM node location where the result was found.
60      */
61     Result( ResultId result_id = ALL_OK,
62             XercesExt::NodeLocationInfo node_location = XercesExt::NodeLocationInfo() );
63
64     /**
65      * Returns the type of the Result, either a warning or an error.
66      *
67      * @return The type of the Result.
68      */
69     ResultType GetResultType() const;
70
71     /**
72      * Returns the ID of the Result.
73      *
74      * @return The ID.
75      */
76     ResultId GetResultId() const;
77
78     /**
79      * Sets the Result's ID.
80      *
81      * @param result_id The new ID.
82      * @return A reference to this result, for easy function chaining.
83      */
84     Result& SetResultId( ResultId result_id );
85
86     /**
87      * Returns the error line number.
88      *
89      * @return The line number.
90      */
91     int GetErrorLine() const;
92
93     /**
94      * Sets the Result's error line number.
95      *
96      * @param result_id The new line number.
97      * @return A reference to this result, for easy function chaining.
98      */
99     Result& SetErrorLine( int error_line );
100
101     /**
102      * Returns the error column number.
103      *
104      * @return The column number.
105      */
106     int GetErrorColumn() const;
107
108     /**
109      * Sets the Result's error column number.
110      * @note This is usually unreliable information because of the way
111      * Xerces works with XSD's. It's going to be in the ballpark, but
112      * it won't (usually) have the precision you want.
113      *
114      * @param result_id The new column number.
115      * @return A reference to this result, for easy function chaining.
116      */
117     Result& SetErrorColumn( int error_column );
118
119     /**
120      * Returns the path to the file in which this Result occurs.
121      * The path is relative to the root of the epub document.
122      * 
123      * @return The path in UTF-8.
124      */
125     std::string GetFilepath() const;
126
127     /**
128      * Sets the path to the file in which this Result occurs.
129      * The path should be relative to the root of the epub document.
130      *
131      * @param filepath The new path in UTF-8.
132      * @return A reference to this result, for easy function chaining.
133      */
134     Result& SetFilepath( const std::string &filepath );
135
136     /**
137      * Adds a message argument that fills in a placeholder in the  
138      * message that applies to this Result's ID. The order in which
139      * the arguments are added is the order in which they will replace
140      * the placeholders.
141      *
142      * @param message_argument The argument in UTF-8.
143      * @return A reference to this result, for easy function chaining.
144      */
145     Result& AddMessageArgument( const std::string &message_argument );
146
147     /**
148      * Sets all the message arguments that will fill in the placeholders
149      * in the message that applies to this Result's ID. The order in which
150      * the arguments are added is the order in which they will replace
151      * the placeholders.
152      *
153      * @param message_arguments The arguments in UTF-8.
154      * @return A reference to this result, for easy function chaining.
155      */
156     Result& SetMessageArguments( const std::vector< std::string > &message_arguments );
157
158     /**
159      * Returns all the stored message arguments.
160      *
161      * @return The current message arguments.
162      */
163     const std::vector< std::string > &GetMessageArguments() const;
164
165     /**
166      * Returns the error message for this Result with all the
167      * message arguments already applied.
168      */
169     std::string GetMessage() const;
170
171     /**
172      * Sets a custom message for this Result. This overrides the template
173      * message for Results with this ID and ignores all stored message arguments.
174      */
175     Result& SetCustomMessage( const std::string &custom_message );
176     
177     bool operator< ( const Result& other ) const;
178
179     bool operator== ( const Result& other ) const;
180
181 private:
182
183     ///////////////////////////////
184     // PRIVATE MEMBER VARIABLES
185     ///////////////////////////////
186
187     /**
188      * The Result's ID.
189      */
190     ResultId m_ResultId;
191
192     /**
193      * The line where this Result was found in the content document.
194      */
195     int m_ErrorLine;
196
197     /**
198      * The column in the line where this Result was found in the content document.
199      */
200     int m_ErrorColumn;
201
202     /**
203      * The message arguments for the placeholders in the message template.
204      */
205     std::vector< std::string > m_MessageArguments;
206
207     /**
208      * A custom message that overrides the template one.
209      */
210     std::string m_CustomMessage;
211
212     /**
213      * The relative path to the file where the Result was found.
214      */
215     std::string m_Filepath;
216 };
217
218 } // namespace FlightCrew
219
220 #endif // RESULT_H