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

more/io/directory.h

Go to the documentation of this file.
00001 
00002 //  Copyright (C) 1999--2001  Petter Urkedal (petter.urkedal@matfys.lth.se)
00003 //
00004 //  This file is free software; you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation; either version 2 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This file is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program; if not, write to the Free Software
00016 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 //
00018 //  As a special exception, you may use this file as part of a free
00019 //  software library without restriction.  Specifically, if other files
00020 //  instantiate templates or use macros or inline functions from this
00021 //  file, or you compile this file and link it with other files to
00022 //  produce an executable, this file does not by itself cause the
00023 //  resulting executable to be covered by the GNU General Public
00024 //  License.  This exception does not however invalidate any other
00025 //  reasons why the executable file might be covered by the GNU General
00026 //  Public License.
00027 //
00028 //  $Id: directory.h,v 1.1 2002/05/30 18:01:37 petter_urkedal Exp $
00029 
00030 
00031 #ifndef MORE_IO_DIRECTORY_H
00032 #define MORE_IO_DIRECTORY_H
00033 
00034 
00035 #include <string>
00036 #include <iterator>
00037 #include <more/gen/utility.h>
00038 
00039 namespace more {
00040 namespace io {
00041 
00042   
00043   /** \class directory directory.h more/io/directory.h
00044    ** A type which provides a range over file names in a directory. */
00045   struct directory
00046   {
00047       explicit directory(std::string name_) : name(name_) {}
00048 
00049       struct iterator : std::iterator<std::input_iterator_tag, std::string>
00050       {
00051           explicit iterator(std::string);
00052           iterator() : dir(0) {}
00053           iterator(iterator const& u)
00054               : ic(u.ic), dir(u.dir), entry(u.entry) {}
00055           ~iterator();
00056           iterator& operator++() { getnext(); return *this; }
00057           iterator operator++(int)
00058           { iterator tmp = *this; getnext(); return tmp; }
00059           bool operator==(iterator const& rhs) const
00060           { return dir == 0 && rhs.dir == 0; }
00061           bool operator!=(iterator const& rhs) const
00062           { return !(*this == rhs); }
00063           std::string operator*() const { return entry; }
00064           std::string const* operator->() const { return &entry; }
00065         private:
00066           void getnext();
00067           gen::instance_counter ic;
00068           void* dir;
00069           std::string entry;
00070       };
00071 
00072       iterator begin() { return iterator(name); }
00073       iterator end() { return iterator(); }
00074 
00075     private:
00076       std::string name;
00077   };
00078 
00079 }}
00080 
00081 #endif

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