// -*- mode: c++; indent-tabs-mode: nil; c-basic-offset: 4 -*- // $Header: /srv/cvs/sources/mpak/mpak/include/mpak/Attic/parser.hh,v 1.1 2003/07/14 15:53:33 pbgavin Exp $ // mpak - the advanced package manager // ecstacy - extended c++ portable operating system interface library // Copyright (C) 2003 Peter Gavin // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include #include #include namespace mpak { template > class basic_parser { public: class failure : public std::runtime_error { public: inline failure (void) throw ECSTACY_THROW_SPEC (()) { } }; typedef char_type_ char_type; typedef typename traits_type_::int_type int_type; typedef traits_type_ traits_type; typedef std::basic_streambuf streambuf_type; protected: std::string filename_; bool inlined_; mutable streambuf_type *buf_; mutable bool initialized_; mutable ecstacy::size_type line_, column_; private: inline int_type get_char (void) const ECSTACY_THROW_SPEC (()) { int_type_ c = this->buf_->sgetc (); ++this->column_; if (traits_type::eq (c, this->buf_->widen ('\n'))) { ++this->line_; } } inline int_type unget_char () const ECSTACY_THROW_SPEC (()) { this->buf_->unget (); --this->column_; if (traits_type::eq (c, this->buf_->widen ('\n'))) { --this->line_; } } protected: inline parser (void) ECSTACY_THROW_SPEC (()) : inlined_ (0), initialized_ (false), buf_ (0), line_ (0), column_ (1) { } inline parser (const parser &parser) ECSTACY_THROW_SPEC (()) : inlined_ (parser.inlined_), initialized_ (parser.initialized_) { } inline parser (streambuf_type *buf, std::string filename, ecstacy::size_type line = 0, ecstacy::size_type column = 1) : filename_ (filename), inlined_ (true), buf_ (buf), initialized_ (false), line_ (line), column_ (column) { this->init (); } inline parser (std::string filename) : filename_ (filename), inlined_ (false), buf_ (0), initialized_ (false), line_ (0), column_ (1) { } virtual ~parser (void) ECSTACY_THROW_SPEC (()); inline parser & operator= (const parser &parser) ECSTACY_THROW_SPEC (()) { this->filename_ = parser.filename_; this->inlined_ = parser.inlined_; this->buf_ = parser.buf_; this->initialized_ = parser.initialized_; this->line_ = parser.line_; this->column = parser.column_; return *this; } inline init () const { if (this->buf_ == 0) { } } }; }