librostlab-blast  1.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
blast-parser-position.h
Go to the documentation of this file.
1 
2 /* A Bison parser, made by GNU Bison 2.4.1. */
3 
4 /* Positions for Bison parsers in C++
5 
6  Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU 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, see <http://www.gnu.org/licenses/>. */
20 
21 /* As a special exception, you may create a larger work that contains
22  part or all of the Bison parser skeleton and distribute that work
23  under terms of your choice, so long as that work isn't itself a
24  parser generator using the skeleton or a modified version thereof
25  as a parser skeleton. Alternatively, if you modify or redistribute
26  the parser skeleton itself, you may (at your option) remove this
27  special exception, which will cause the skeleton and the resulting
28  Bison output files to be licensed under the GNU General Public
29  License without this special exception.
30 
31  This special exception was added by the Free Software Foundation in
32  version 2.2 of Bison. */
33 
39 #ifndef BISON_ROSTLAB_BLAST_PARSER_POSITION_H
40 # define BISON_ROSTLAB_BLAST_PARSER_POSITION_H
41 
42 # include <iostream>
43 # include <string>
44 # include <algorithm>
45 
46 
47 /* Line 38 of location.cc */
48 #line 22 "blast-parser-parser.ypp"
49 namespace rostlab { namespace blast {
50 
51 /* Line 38 of location.cc */
52 #line 53 "rostlab/blast-parser-position.h"
53 
54  class position
55  {
56  public:
57 
60  : filename (0), line (1), column (1)
61  {
62  }
63 
64 
66  inline void initialize (std::string* fn)
67  {
68  filename = fn;
69  line = 1;
70  column = 1;
71  }
72 
75  public:
77  inline void lines (int count = 1)
78  {
79  column = 1;
80  line += count;
81  }
82 
84  inline void columns (int count = 1)
85  {
86  column = std::max (1u, column + count);
87  }
90  public:
92  std::string* filename;
94  unsigned int line;
96  unsigned int column;
97  };
98 
100  inline const position&
101  operator+= (position& res, const int width)
102  {
103  res.columns (width);
104  return res;
105  }
106 
108  inline const position
109  operator+ (const position& begin, const int width)
110  {
111  position res = begin;
112  return res += width;
113  }
114 
116  inline const position&
117  operator-= (position& res, const int width)
118  {
119  return res += -width;
120  }
121 
123  inline const position
124  operator- (const position& begin, const int width)
125  {
126  return begin + -width;
127  }
128 
130  inline bool
131  operator== (const position& pos1, const position& pos2)
132  {
133  return
134  (pos1.filename == pos2.filename
135  || pos1.filename && pos2.filename && *pos1.filename == *pos2.filename)
136  && pos1.line == pos2.line && pos1.column == pos2.column;
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