librostlab-blast  1.0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
blast-parser-position.h
Go to the documentation of this file.
1 /* A Bison parser, made by GNU Bison 2.5. */
2 
3 /* Positions for Bison parsers in C++
4 
5  Copyright (C) 2002-2007, 2009-2011 Free Software Foundation, Inc.
6 
7  This program is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  This program 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 General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 
20 /* As a special exception, you may create a larger work that contains
21  part or all of the Bison parser skeleton and distribute that work
22  under terms of your choice, so long as that work isn't itself a
23  parser generator using the skeleton or a modified version thereof
24  as a parser skeleton. Alternatively, if you modify or redistribute
25  the parser skeleton itself, you may (at your option) remove this
26  special exception, which will cause the skeleton and the resulting
27  Bison output files to be licensed under the GNU General Public
28  License without this special exception.
29 
30  This special exception was added by the Free Software Foundation in
31  version 2.2 of Bison. */
32 
38 #ifndef BISON_ROSTLAB_BLAST_PARSER_POSITION_H
39 # define BISON_ROSTLAB_BLAST_PARSER_POSITION_H
40 
41 # include <iostream>
42 # include <string>
43 # include <algorithm>
44 
45 
46 /* Line 37 of location.cc */
47 #line 22 "blast-parser-parser.ypp"
48 namespace rostlab { namespace blast {
49 
50 /* Line 37 of location.cc */
51 #line 52 "rostlab/blast-parser-position.h"
52 
53  class position
54  {
55  public:
56 
59  : filename (0), line (1), column (1)
60  {
61  }
62 
63 
65  inline void initialize (std::string* fn)
66  {
67  filename = fn;
68  line = 1;
69  column = 1;
70  }
71 
74  public:
76  inline void lines (int count = 1)
77  {
78  column = 1;
79  line += count;
80  }
81 
83  inline void columns (int count = 1)
84  {
85  column = std::max (1u, column + count);
86  }
89  public:
91  std::string* filename;
93  unsigned int line;
95  unsigned int column;
96  };
97 
99  inline const position&
100  operator+= (position& res, const int width)
101  {
102  res.columns (width);
103  return res;
104  }
105 
107  inline const position
108  operator+ (const position& begin, const int width)
109  {
110  position res = begin;
111  return res += width;
112  }
113 
115  inline const position&
116  operator-= (position& res, const int width)
117  {
118  return res += -width;
119  }
120 
122  inline const position
123  operator- (const position& begin, const int width)
124  {
125  return begin + -width;
126  }
127 
129  inline bool
130  operator== (const position& pos1, const position& pos2)
131  {
132  return (pos1.line == pos2.line
133  && pos1.column == pos2.column
134  && (pos1.filename == pos2.filename
135  || (pos1.filename && pos2.filename
136  && *pos1.filename == *pos2.filename)));
137  }
138 
140  inline bool
141  operator!= (const position& pos1, const position& pos2)
142  {
143  return !(pos1 == pos2);
144  }
145 
150  inline std::ostream&
151  operator<< (std::ostream& ostr, const position& pos)
152  {
153  if (pos.filename)
154  ostr << *pos.filename << ':';
155  return ostr << pos.line << '.' << pos.column;
156  }
157 
158 
159 /* Line 144 of location.cc */
160 #line 22 "blast-parser-parser.ypp"
161 } } // rostlab::blast
162 
163 /* Line 144 of location.cc */
164 #line 165 "rostlab/blast-parser-position.h"
165 #endif // not BISON_ROSTLAB_BLAST_PARSER_POSITION_H