1 | // $Id: Parser.h 103 2006-06-27 09:46:00Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2006 Peter Johansson |
---|
5 | |
---|
6 | This file is part of svnstat, http://lev.thep.lu.se/trac/svnstat |
---|
7 | |
---|
8 | svnstat is free software; you can redistribute it and/or modify it |
---|
9 | under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2 of the License, or |
---|
11 | (at your option) any later version. |
---|
12 | |
---|
13 | svnstat is distributed in the hope that it will be useful, but |
---|
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with this program; if not, write to the Free Software |
---|
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
21 | 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | #ifndef _theplu_svnstat_parser_ |
---|
25 | #define _theplu_svnstat_parser_ |
---|
26 | |
---|
27 | #include <fstream> |
---|
28 | #include <vector> |
---|
29 | |
---|
30 | namespace theplu{ |
---|
31 | namespace svnstat{ |
---|
32 | |
---|
33 | /// |
---|
34 | /// Class parsing files |
---|
35 | /// |
---|
36 | class Parser |
---|
37 | { |
---|
38 | public: |
---|
39 | /// |
---|
40 | /// A line is considered empty if it only contains spaces and tabs. |
---|
41 | /// |
---|
42 | /// A line is considered a comment if first and second non-white |
---|
43 | /// space characters are '/'. |
---|
44 | /// |
---|
45 | /// All other lines are considered code. |
---|
46 | /// |
---|
47 | enum line_type { |
---|
48 | empty, |
---|
49 | comment, |
---|
50 | code |
---|
51 | }; |
---|
52 | |
---|
53 | /// |
---|
54 | /// @brief Constructor |
---|
55 | /// |
---|
56 | explicit Parser(std::istream&); |
---|
57 | |
---|
58 | /// |
---|
59 | /// @return const ref to vector with the line types |
---|
60 | /// |
---|
61 | inline const std::vector<line_type>& type(void) const { return type_; } |
---|
62 | |
---|
63 | private: |
---|
64 | /// |
---|
65 | /// Copy constructor (not implemented) |
---|
66 | /// |
---|
67 | Parser(const Parser& other); |
---|
68 | |
---|
69 | std::vector<line_type> type_; |
---|
70 | |
---|
71 | }; |
---|
72 | |
---|
73 | /// |
---|
74 | /// Functor for white space identification |
---|
75 | /// |
---|
76 | /// @return true if @a c is '\t', ' ' or '\n'. |
---|
77 | /// |
---|
78 | struct WhiteSpace : public std::unary_function<char,bool> |
---|
79 | { |
---|
80 | inline bool operator()(const char c) const |
---|
81 | { |
---|
82 | return (c==' ' || c=='\t' || c=='\n'); |
---|
83 | } |
---|
84 | }; |
---|
85 | |
---|
86 | |
---|
87 | |
---|
88 | |
---|
89 | }} // end of namespace svnstat end of namespace theplu |
---|
90 | |
---|
91 | #endif |
---|