filesystem.h

00001 /*
00002  * filesystem.h
00003  * This file is part of dbPager Classes Library (DCL)
00004  *
00005  * Copyright (c) 2008 Dennis Prochko <wolfsoft@mail.ru>
00006  *
00007  * DCL is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation version 3.
00010  *
00011  * DCL is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with DCL; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor,
00019  * Boston, MA  02110-1301  USA
00020  */
00021 
00022 #ifndef _FILESYSTEM_H_
00023 #define _FILESYSTEM_H_
00024 
00025 #include <iterator>
00026 #include <string>
00027 
00028 namespace dbp {
00029 
00031 
00034 class filesystem {
00035         friend class const_iterator;
00036         friend class filefs;
00037 public:
00039         class const_iterator: public std::iterator<
00040           std::forward_iterator_tag,
00041           std::string> {
00042                 friend class filesystem;
00043         public:
00044                 const_iterator& operator++() {
00045                         _rownum++;
00046                         if (!_fs) {
00047                                 _rownum = 0;
00048                         }
00049                         else
00050                         if (!_fs->find_next_file(_filename)) {
00051                                 _rownum = 0;
00052                         }
00053                         return *this;
00054                 };
00055                 const_iterator operator++(int) {
00056                         const_iterator save = *this;
00057                         ++*this;
00058                         return save;
00059                 };
00060                 const std::string* operator->() const {
00061                         return &**this;
00062                 };
00063                 const std::string& operator*() const {
00064                         return _filename;
00065                 };
00066                 bool operator==(const const_iterator &value) const {
00067                         return (_rownum == value._rownum);
00068                 };
00069                 bool operator!=(const const_iterator &value) const {
00070                         return (_rownum != value._rownum);
00071                 };
00072         private:
00073                 int _rownum;
00074                 std::string _filename;
00075                 filesystem *_fs;
00076                 const_iterator(): _rownum(0), _fs(NULL) { };
00077                 const_iterator(filesystem *fs, const std::string &pattern):
00078                   _rownum(0), _fs(fs) {
00079                         if (_fs->find_first_file(pattern, _filename))
00080                                 _rownum++;
00081                 };
00082         };
00084         virtual ~filesystem() { };
00086 
00090         virtual std::string get_path_delimiter() const = 0;
00092 
00095         virtual std::string get_current_dir() const = 0;
00097 
00100         virtual void set_current_dir(const std::string &name) const = 0;
00102 
00106         virtual std::string get_temp_dir() const = 0;
00108 
00111         virtual std::string get_home_dir() const = 0;
00113 
00116         virtual std::string get_locale_dir() const = 0;
00118 
00121         virtual std::string get_system_config_dir() const = 0;
00123 
00127         virtual std::string get_data_dir() const = 0;
00129 
00136         const_iterator find(const std::string &pattern) {
00137                 return const_iterator(&*this, pattern);
00138         }
00140 
00145         const_iterator end() {
00146                 return const_iterator();
00147         }
00148 protected:
00149         virtual bool find_first_file(const std::string &pattern,
00150           std::string &filename) = 0;
00151         virtual bool find_next_file(std::string &filename) = 0;
00152 };
00153 
00154 }
00155 
00156 #endif /*FILESYSTEM_H_*/
00157 

 
Support This Project
SourceForge.net Logo