librostlab-blast  1.0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
blast-parser-location.h
Go to the documentation of this file.
1 /* A Bison parser, made by GNU Bison 2.5. */
2 
3 /* Locations 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_LOCATION_H
39 # define BISON_ROSTLAB_BLAST_PARSER_LOCATION_H
40 
41 # include <iostream>
42 # include <string>
44 
45 
46 /* Line 162 of location.cc */
47 #line 22 "blast-parser-parser.ypp"
48 namespace rostlab { namespace blast {
49 
50 /* Line 162 of location.cc */
51 #line 52 "rostlab/blast-parser-location.h"
52 
54  class location
55  {
56  public:
57 
60  : begin (), end ()
61  {
62  }
63 
64 
66  inline void initialize (std::string* fn)
67  {
68  begin.initialize (fn);
69  end = begin;
70  }
71 
74  public:
76  inline void step ()
77  {
78  begin = end;
79  }
80 
82  inline void columns (unsigned int count = 1)
83  {
84  end += count;
85  }
86 
88  inline void lines (unsigned int count = 1)
89  {
90  end.lines (count);
91  }
95  public:
100  };
101 
103  inline const location operator+ (const location& begin, const location& end)
104  {
105  location res = begin;
106  res.end = end.end;
107  return res;
108  }
109 
111  inline const location operator+ (const location& begin, unsigned int width)
112  {
113  location res = begin;
114  res.columns (width);
115  return res;
116  }
117 
119  inline location& operator+= (location& res, unsigned int width)
120  {
121  res.columns (width);
122  return res;
123  }
124 
126  inline bool
127  operator== (const location& loc1, const location& loc2)
128  {
129  return loc1.begin == loc2.begin && loc1.end == loc2.end;
130  }
131 
133  inline bool
134  operator!= (const location& loc1, const location& loc2)
135  {
136  return !(loc1 == loc2);
137  }
138 
145  inline std::ostream& operator<< (std::ostream& ostr, const location& loc)
146  {
147  position last = loc.end - 1;
148  ostr << loc.begin;
149  if (last.filename
150  && (!loc.begin.filename
151  || *loc.begin.filename != *last.filename))
152  ostr << '-' << last;
153  else if (loc.begin.line != last.line)
154  ostr << '-' << last.line << '.' << last.column;
155  else if (loc.begin.column != last.column)
156  ostr << '-' << last.column;
157  return ostr;
158  }
159 
160 
161 /* Line 271 of location.cc */
162 #line 22 "blast-parser-parser.ypp"
163 } } // rostlab::blast
164 
165 /* Line 271 of location.cc */
166 #line 167 "rostlab/blast-parser-location.h"
167 
168 #endif // not BISON_ROSTLAB_BLAST_PARSER_LOCATION_H