libvrml1++/position.hh

Go to the documentation of this file.
00001 /* A Bison parser, made by GNU Bison 2.3.  */
00002 
00003 /* Positions for Bison parsers in C++
00004 
00005    Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
00006 
00007    This program is free software; you can redistribute it and/or modify
00008    it under the terms of the GNU General Public License as published by
00009    the Free Software Foundation; either version 2, or (at your option)
00010    any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015    GNU General Public License for more details.
00016 
00017    You should have received a copy of the GNU General Public License
00018    along with this program; if not, write to the Free Software
00019    Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.  */
00021 
00022 /* As a special exception, you may create a larger work that contains
00023    part or all of the Bison parser skeleton and distribute that work
00024    under terms of your choice, so long as that work isn't itself a
00025    parser generator using the skeleton or a modified version thereof
00026    as a parser skeleton.  Alternatively, if you modify or redistribute
00027    the parser skeleton itself, you may (at your option) remove this
00028    special exception, which will cause the skeleton and the resulting
00029    Bison output files to be licensed under the GNU General Public
00030    License without this special exception.
00031 
00032    This special exception was added by the Free Software Foundation in
00033    version 2.2 of Bison.  */
00034 
00040 #ifndef BISON_POSITION_HH
00041 # define BISON_POSITION_HH
00042 
00043 # include <iostream>
00044 # include <string>
00045 
00046 namespace vrml1
00047 {
00049   class position
00050   {
00051   public:
00052 
00054     position ()
00055       : filename (0), line (1), column (0)
00056     {
00057     }
00058 
00059 
00061     inline void initialize (std::string* fn)
00062     {
00063       filename = fn;
00064       line = 1;
00065       column = 0;
00066     }
00067 
00070   public:
00072     inline void lines (int count = 1)
00073     {
00074       column = 0;
00075       line += count;
00076     }
00077 
00079     inline void columns (int count = 1)
00080     {
00081       int leftmost = 0;
00082       int current  = column;
00083       if (leftmost <= current + count)
00084         column += count;
00085       else
00086         column = 0;
00087     }
00090   public:
00092     std::string* filename;
00094     unsigned int line;
00096     unsigned int column;
00097   };
00098 
00100   inline const position&
00101   operator+= (position& res, const int width)
00102   {
00103     res.columns (width);
00104     return res;
00105   }
00106 
00108   inline const position
00109   operator+ (const position& begin, const int width)
00110   {
00111     position res = begin;
00112     return res += width;
00113   }
00114 
00116   inline const position&
00117   operator-= (position& res, const int width)
00118   {
00119     return res += -width;
00120   }
00121 
00123   inline const position
00124   operator- (const position& begin, const int width)
00125   {
00126     return begin + -width;
00127   }
00128 
00133   inline std::ostream&
00134   operator<< (std::ostream& ostr, const position& pos)
00135   {
00136     if (pos.filename)
00137       ostr << *pos.filename << ':';
00138     return ostr << pos.line << '.' << pos.column;
00139   }
00140 
00141 }
00142 #endif // not BISON_POSITION_HH

Generated on Mon Jul 21 23:57:09 2008 for libvrml1++ by  doxygen 1.5.4