position.h

Go to the documentation of this file.
00001 // -*- mode: C++; c-file-style: "stroustrup"; c-basic-offset: 4; indent-tabs-mode: nil; -*-
00002 
00003 /* libutap - Uppaal Timed Automata Parser.
00004    Copyright (C) 2006 Uppsala University and Aalborg University.
00005    
00006    This library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public License
00008    as published by the Free Software Foundation; either version 2.1 of
00009    the License, or (at your option) any later version.
00010 
00011    This library is distributed in the hope that it will be useful, but
00012    WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with this library; if not, write to the Free Software
00018    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00019    USA
00020 */
00021 
00022 #ifndef UTAP_POSITION
00023 #define UTAP_POSITION
00024 
00025 #include "config.h"
00026 
00027 #ifdef HAVE_INTTYPES_H
00028 #include <inttypes.h>
00029 #elif defined(HAVE_STDINT_H)
00030 #include <stdint.h>
00031 #else
00032 #error "No inttypes.h or stdint.h"
00033 #endif
00034 
00035 #include <vector>
00036 #include <string>
00037 #include <iostream>
00038 #include <climits>
00039 
00040 namespace UTAP
00041 {
00042     struct position_t
00043     {
00044         uint32_t start, end;
00045         position_t() : start(0), end(UINT_MAX) {}
00046         position_t(uint32_t start, uint32_t end) : start(start), end(end) {}
00047     };
00048 
00067     class Positions
00068     {
00069     public:
00070         struct line_t
00071         {
00072             uint32_t position;
00073             uint32_t offset;
00074             uint32_t line;    
00075             std::string path;
00076             line_t(uint32_t position, uint32_t offset, uint32_t line, std::string path)
00077                 : position(position), offset(offset), line(line), path(path) {}
00078         };
00079         
00080     private:
00081         std::vector<line_t> elements;
00082         const line_t &find(uint32_t, uint32_t, uint32_t) const;
00083     public:
00085         void add(uint32_t position, uint32_t offset, uint32_t line, std::string path);
00086         
00092         const line_t &find(uint32_t position) const;
00093         
00095         void dump();
00096     };
00097     
00098     
00099     struct error_t
00100     {
00101         Positions::line_t start;
00102         Positions::line_t end;
00103         position_t position;
00104         std::string msg;
00105         error_t(Positions::line_t start, Positions::line_t end, 
00106                 position_t position, std::string msg)
00107             : start(start), end(end), position(position), msg(msg) {}
00108     };
00109 }
00110 
00111 std::ostream &operator <<(std::ostream &out, const UTAP::error_t &);
00112 
00113 #endif

Generated on Thu Feb 22 14:46:52 2007 for libutap by  doxygen 1.4.7