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