librostlab-blast  1.0.0
rostlab/blast-parser-position.h
Go to the documentation of this file.
00001 
00002 /* A Bison parser, made by GNU Bison 2.4.1.  */
00003 
00004 /* Positions for Bison parsers in C++
00005    
00006       Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
00007    
00008    This program is free software: you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation, either version 3 of the License, or
00011    (at your option) any later version.
00012    
00013    This program is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017    
00018    You should have received a copy of the GNU General Public License
00019    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00020 
00021 /* As a special exception, you may create a larger work that contains
00022    part or all of the Bison parser skeleton and distribute that work
00023    under terms of your choice, so long as that work isn't itself a
00024    parser generator using the skeleton or a modified version thereof
00025    as a parser skeleton.  Alternatively, if you modify or redistribute
00026    the parser skeleton itself, you may (at your option) remove this
00027    special exception, which will cause the skeleton and the resulting
00028    Bison output files to be licensed under the GNU General Public
00029    License without this special exception.
00030    
00031    This special exception was added by the Free Software Foundation in
00032    version 2.2 of Bison.  */
00033 
00039 #ifndef BISON_ROSTLAB_BLAST_PARSER_POSITION_H
00040 # define BISON_ROSTLAB_BLAST_PARSER_POSITION_H
00041 
00042 # include <iostream>
00043 # include <string>
00044 # include <algorithm>
00045 
00046 
00047 /* Line 38 of location.cc  */
00048 #line 22 "blast-parser-parser.ypp"
00049 namespace rostlab { namespace blast {
00050 
00051 /* Line 38 of location.cc  */
00052 #line 53 "rostlab/blast-parser-position.h"
00053 
00054   class position
00055   {
00056   public:
00057 
00059     position ()
00060       : filename (0), line (1), column (1)
00061     {
00062     }
00063 
00064 
00066     inline void initialize (std::string* fn)
00067     {
00068       filename = fn;
00069       line = 1;
00070       column = 1;
00071     }
00072 
00075   public:
00077     inline void lines (int count = 1)
00078     {
00079       column = 1;
00080       line += count;
00081     }
00082 
00084     inline void columns (int count = 1)
00085     {
00086       column = std::max (1u, column + count);
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 
00130   inline bool
00131   operator== (const position& pos1, const position& pos2)
00132   {
00133     return
00134       (pos1.filename == pos2.filename
00135        || pos1.filename && pos2.filename && *pos1.filename == *pos2.filename)
00136       && pos1.line == pos2.line && pos1.column == pos2.column;
00137   }
00138 
00140   inline bool
00141   operator!= (const position& pos1, const position& pos2)
00142   {
00143     return !(pos1 == pos2);
00144   }
00145 
00150   inline std::ostream&
00151   operator<< (std::ostream& ostr, const position& pos)
00152   {
00153     if (pos.filename)
00154       ostr << *pos.filename << ':';
00155     return ostr << pos.line << '.' << pos.column;
00156   }
00157 
00158 
00159 /* Line 144 of location.cc  */
00160 #line 22 "blast-parser-parser.ypp"
00161 } } // rostlab::blast
00162 
00163 /* Line 144 of location.cc  */
00164 #line 165 "rostlab/blast-parser-position.h"
00165 #endif // not BISON_ROSTLAB_BLAST_PARSER_POSITION_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines