H3D API  2.4.1
position.hh
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_POSITION_HH
40 # define BISON_POSITION_HH
41 
42 # include <iostream>
43 # include <string>
44 # include <algorithm>
45 
46 
47 #undef max
48 
49 /* Line 38 of location.cc */
50 #line 1 "[Bison:b4_percent_define_default]"
51 
52 namespace yy {
53 
54 /* Line 38 of location.cc */
55 #line 54 "position.hh"
57  class position
58  {
59  public:
60 
63  : filename (0), line (1), column (1)
64  {
65  }
66 
67 
69  inline void initialize (std::string* fn)
70  {
71  filename = fn;
72  line = 1;
73  column = 1;
74  }
75 
78  public:
80  inline void lines (int count = 1)
81  {
82  column = 1;
83  line += count;
84  }
85 
87  inline void columns (int count = 1)
88  {
89  column = std::max (1u, column + count);
90  }
93  public:
95  std::string* filename;
97  unsigned int line;
99  unsigned int column;
100  };
101 
103  inline const position&
104  operator+= (position& res, const int width)
105  {
106  res.columns (width);
107  return res;
108  }
109 
111  inline const position
112  operator+ (const position& begin, const int width)
113  {
114  position res = begin;
115  return res += width;
116  }
117 
119  inline const position&
120  operator-= (position& res, const int width)
121  {
122  return res += -width;
123  }
124 
126  inline const position
127  operator- (const position& begin, const int width)
128  {
129  return begin + -width;
130  }
131 
133  inline bool
134  operator== (const position& pos1, const position& pos2)
135  {
136  return
137  (pos1.filename == pos2.filename
138  || (pos1.filename && pos2.filename && *pos1.filename == *pos2.filename))
139  && pos1.line == pos2.line && pos1.column == pos2.column;
140  }
141 
143  inline bool
144  operator!= (const position& pos1, const position& pos2)
145  {
146  return !(pos1 == pos2);
147  }
148 
153  inline std::ostream&
154  operator<< (std::ostream& ostr, const position& pos)
155  {
156  if (pos.filename)
157  ostr << *pos.filename << ':';
158  return ostr << pos.line << '.' << pos.column;
159  }
160 
161 
162 /* Line 144 of location.cc */
163 #line 1 "[Bison:b4_percent_define_default]"
164 
165 } // yy
166 
167 /* Line 144 of location.cc */
168 #line 167 "position.hh"
169 #endif // not BISON_POSITION_HH
Abstract a position.
Definition: position.hh:58
void initialize(std::string *fn)
Initialization.
Definition: position.hh:69
void lines(int count=1)
(line related) Advance to the COUNT next lines.
Definition: position.hh:80
std::string * filename
File name to which this position refers.
Definition: position.hh:95
unsigned int line
Current line number.
Definition: position.hh:97
void columns(int count=1)
(column related) Advance to the COUNT next columns.
Definition: position.hh:87
unsigned int column
Current column number.
Definition: position.hh:99
position()
Construct a position.
Definition: position.hh:62