Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

more/io/sourceref.h

Go to the documentation of this file.
00001 // Copyright (C) 2001  Petter Urkedal (petter.urkedal@matfys.lth.se)
00002 //
00003 // This file is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This file is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00016 //
00017 // As a special exception, you may use this file as part of a free
00018 // software library without restriction.  Specifically, if other files
00019 // instantiate templates or use macros or inline functions from this
00020 // file, or you compile this file and link it with other files to
00021 // produce an executable, this file does not by itself cause the
00022 // resulting executable to be covered by the GNU General Public
00023 // License.  This exception does not however invalidate any other
00024 // reasons why the executable file might be covered by the GNU General
00025 // Public License.
00026 //
00027 // $Id: sourceref.h,v 1.1 2002/05/30 18:01:37 petter_urkedal Exp $
00028 
00029 
00030 #ifndef MORE_IO_SOURCEREF_H
00031 #define MORE_IO_SOURCEREF_H
00032 
00033 #include <iosfwd>
00034 #include <string>
00035 
00036 
00037 namespace more {
00038 namespace io {
00039 
00040   struct sourceref
00041   {
00042       struct stdin_tag {};
00043 #ifndef stdin
00044       static const stdin_tag stdin;
00045 #endif
00046 
00047       explicit sourceref(stdin_tag, int l = 1, int c = 0)
00048           : m_line(l), m_column(c) {}
00049       explicit sourceref(std::string const& f, int l = 1, int c = 0)
00050           : m_file(f), m_line(l), m_column(c) {}
00051       sourceref()
00052           : m_file("[unknown]"), m_line(-1), m_column(-1) {}
00053 
00054       void next(int n = 1) { m_column += n; }
00055       void tabulator() { m_column = (m_column/8 + 1)*8; }
00056       void newline(int n = 1);
00057       void rewind() { m_line = 1; m_column = 0; }
00058 
00059       bool is_stdin() const { return m_file.empty(); }
00060       bool is_unknown() const { return m_line == -1; }
00061 
00062       std::string const& file_name() const { return m_file; }
00063       void set_file_name(std::string const& f) { m_file = f; }
00064       int line() const { return m_line; }
00065       void set_line(int i) { m_line = i; }
00066       int column() const { return m_column; }
00067       void set_column(int i) { m_column = i; }
00068 
00069       bool operator==(sourceref const& rhs) const
00070       {
00071           return m_file == rhs.m_file
00072               && m_line == rhs.m_line
00073               && m_column == rhs.m_column;
00074       }
00075 
00076   private:
00077       std::string m_file;
00078       int m_line;
00079       int m_column;
00080   };
00081 
00082   template<typename Char, typename Traits>
00083     std::basic_ostream<Char, Traits>&
00084     operator<<(std::basic_ostream<Char, Traits>& os, sourceref const& loc);
00085 
00086 }} // more::io
00087 
00088 #endif

Generated on Sat Sep 7 19:11:16 2002 for more with Doxygen 1.2.13.1. Doxygen 1.2.13.1 is written and copyright 1997-2002 by Dimitri van Heesch.