Drizzled Public API Documentation

cached_directory.h
Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2008 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; version 2 of the License.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  */
00019 
00028 #pragma once
00029 
00030 #include <iosfwd>
00031 #include <vector>
00032 #include <set>
00033 #include <string>
00034 #include <cstdlib>
00035 #include <cerrno>
00036 
00037 namespace drizzled {
00038 
00045 class CachedDirectory
00046 {
00047 public:
00048   enum FILTER 
00049   {
00050     NONE,
00051     DIRECTORY,
00052     FILE,
00053     MAX
00054   };
00055 
00056   class Entry
00057   {
00058     Entry();
00059   public:
00060     std::string filename;
00061     explicit Entry(std::string in_name)
00062       : filename(in_name)
00063     {}
00064   };
00065   typedef std::vector<Entry *> Entries;
00069   CachedDirectory();
00070       
00077   CachedDirectory(const std::string& in_path); 
00078 
00085   CachedDirectory(const std::string& in_path, std::set<std::string>& allowed_exts);
00086   CachedDirectory(const std::string& in_path, CachedDirectory::FILTER filter, bool use_full_path= false);
00087 
00091   ~CachedDirectory();
00092 
00096   inline bool fail() const 
00097   {
00098     return error != 0;
00099   }
00100 
00105   inline int getError() const
00106   {
00107     return error;
00108   }
00109 
00113   inline const char *getPath() const
00114   {
00115     return path.c_str();
00116   }
00117 
00124   const Entries &getEntries() const
00125   {
00126     return entries;
00127   }
00128 private:
00129   std::string path; 
00130   int error; 
00131   bool use_full_path;
00132   Entries entries; 
00133 
00141   bool open(const std::string &in_path);
00142 
00153   bool open(const std::string &in_path, std::set<std::string> &allowable_exts);
00154   bool open(const std::string &in_path, std::set<std::string> &allowed_exts, CachedDirectory::FILTER filter);
00155 
00156   friend std::ostream& operator<<(std::ostream&, const CachedDirectory&);
00157 };
00158 
00159 } /* namespace drizzled */
00160