sbuild  1.5.4
sbuild-mntstream.h
00001 /* Copyright © 2003,2006-2008  Roger Leigh <rleigh@debian.org>
00002  *
00003  * schroot is free software: you can redistribute it and/or modify it
00004  * under the terms of the GNU General Public License as published by
00005  * the Free Software Foundation, either version 3 of the License, or
00006  * (at your option) any later version.
00007  *
00008  * schroot is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * 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, see
00015  * <http://www.gnu.org/licenses/>.
00016  *
00017  *********************************************************************/
00018 
00019 #ifndef SBUILD_MNTSTREAM_H
00020 #define SBUILD_MNTSTREAM_H
00021 
00022 #include <sbuild/sbuild-custom-error.h>
00023 
00024 #include <iostream>
00025 #include <deque>
00026 #include <string>
00027 
00028 #include <stdio.h>
00029 #include <sys/types.h>
00030 #include <mntent.h>
00031 
00032 namespace sbuild
00033 {
00034 
00046   class mntstream
00047     {
00048     public:
00050       enum error_code
00051         {
00052           MNT_OPEN, 
00053           MNT_READ  
00054         };
00055 
00057       typedef sbuild::custom_error<error_code> error;
00058 
00065       struct mntentry
00066       {
00068         mntentry ()
00069         {};
00070 
00076         mntentry (struct mntent const&  entry);
00077 
00079         std::string  filesystem_name;
00081         std::string  directory;
00083         std::string  type;
00085         std::string  options;
00087         int          dump_frequency;
00089         int          fsck_pass;
00090       };
00091 
00097       mntstream(std::string const& file);
00098 
00100       virtual ~mntstream();
00101 
00112       void open(std::string const& file);
00113 
00121       void close();
00122 
00130       bool eof() const;
00131 
00139       bool bad() const;
00140 
00147       operator bool ();
00148 
00155       bool
00156       operator ! ();
00157 
00158       friend mntstream&
00159       operator >> (mntstream& stream,
00160                    mntentry&  entry);
00161 
00162     private:
00173       void read (int quantity=1);
00174 
00176       std::string file;
00177 
00179       FILE *mntfile;
00180 
00185       std::deque<mntentry> data;
00186 
00188       bool error_status;
00189 
00191       bool eof_status;
00192   };
00193 
00202   mntstream&
00203   operator >> (mntstream&            stream,
00204                mntstream::mntentry&  entry);
00205 
00206 }
00207 
00208 #endif /* SBUILD_MNTSTREAM_H */
00209 
00210 /*
00211  * Local Variables:
00212  * mode:C++
00213  * End:
00214  */