Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members

ltlparse/position.hh

Go to the documentation of this file.
00001 /* A Bison parser, made by GNU Bison 1.875c.  */
00002 
00003 /* Position class for Bison C++ parsers,
00004    Copyright (C) 2002, 2003 Free Software Foundation, Inc.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 2, or (at your option)
00009    any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program; if not, write to the Free Software
00018    Foundation, Inc., 59 Temple Place - Suite 330,
00019    Boston, MA 02111-1307, USA.  */
00020 
00026 #ifndef BISON_POSITION_HH
00027 # define BISON_POSITION_HH
00028 
00029 # include <iostream>
00030 # include <string>
00031 
00032 namespace yy
00033 {
00035   class Position
00036   {
00037   public:
00039     static const unsigned int initial_column = 0;
00041     static const unsigned int initial_line = 1;
00042 
00045   public:
00047     Position () :
00048       filename (),
00049       line (initial_line),
00050       column (initial_column)
00051     {
00052     }
00058   public:
00060     inline void lines (int count = 1)
00061     {
00062       column = initial_column;
00063       line += count;
00064     }
00065 
00067     inline void columns (int count = 1)
00068     {
00069       int leftmost = initial_column;
00070       int current  = column;
00071       if (leftmost <= current + count)
00072         column += count;
00073       else
00074         column = initial_column;
00075     }
00078   public:
00080     std::string filename;
00082     unsigned int line;
00084     unsigned int column;
00085   };
00086 
00088   inline const Position&
00089   operator+= (Position& res, const int width)
00090   {
00091     res.columns (width);
00092     return res;
00093   }
00094 
00096   inline const Position
00097   operator+ (const Position& begin, const int width)
00098   {
00099     Position res = begin;
00100     return res += width;
00101   }
00102 
00104   inline const Position&
00105   operator-= (Position& res, const int width)
00106   {
00107     return res += -width;
00108   }
00109 
00111   inline const Position
00112   operator- (const Position& begin, const int width)
00113   {
00114     return begin + -width;
00115   }
00116 
00121   inline std::ostream&
00122   operator<< (std::ostream& ostr, const Position& pos)
00123   {
00124     if (!pos.filename.empty ())
00125       ostr << pos.filename << ':';
00126     return ostr << pos.line << '.' << pos.column;
00127   }
00128 
00129 }
00130 #endif // not BISON_POSITION_HH

Generated on Mon Mar 8 23:31:01 2004 for spot by doxygen 1.3.5