osbfileutil.h

Go to the documentation of this file.
00001 // OSB library ********************************************* -*- C++ -*-
00006 /*
00007   AUTHOR(S): Stephan Broennimann (vb)
00008 
00009   RCS information
00010    $Name: OSB_060808 $
00011    $Revision: 1.17 $
00012 
00013   License
00014    OSB rating and billing library for communication networks
00015    Copyright (C) 2004, 2005, 2006  OSB systems
00016 
00017    This file may be distributed and/or modify under the terms of the
00018    GNU General Public License (GPL) as published by the Free Software
00019    Foundation which is provided in the file LICENSE.GPL included in the
00020    packaging of this file.
00021 
00022    The file is distributed in the hope that it will be useful, but WITHOUT
00023    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00024    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00025    for more details.
00026 
00027    Holders of a OSB Commercial License may use this file under the terms
00028    and conditions of this commercial license.
00029  */
00030 #ifndef _OSBFILEUTIL_H_
00031 #define _OSBFILEUTIL_H_
00032 
00033 // *********************************************************************
00034 // included header files
00035 // + standard includes
00036 #include <string>
00037 #include <list>
00038 #include <dirent.h>                     // struct dirent
00039 #include <ios>
00040 
00041 // + local headers
00042 
00043 // *********************************************************************
00044 // namespace extensions
00045 namespace OSB_LIB {
00046 
00047 // *********************************************************************
00048 // class definitions
00049 
00069     class CloseFile {
00070     public:
00072         CloseFile(
00073             FILE* file,
00074             bool  doClose = true
00075         );
00076     private:
00078         CloseFile(const CloseFile&);
00079     public:
00086         ~CloseFile();
00097         bool release();
00099         bool doClose() const { return doClose_ && file_ != 0; }
00100     private:
00102         bool  doClose_;
00104         FILE* file_;
00105     };
00106 
00110     class ScanDir {
00111     public:
00112         // Base class to select directory entries.
00113         class Select;
00115         typedef std::list<std::string> Result;
00116 
00117     public:
00124         ScanDir(const std::string& dirPath);
00126         ~ScanDir();
00127     private:
00129         ScanDir(const ScanDir&);
00131         ScanDir& operator=(const ScanDir&);
00132 
00133     public:
00135         const std::string& dirPath() const;
00137         Result result_;
00146         void setPath(const std::string& dirPath);
00171         size_t scan(Select& select);
00172 
00173     private:
00175         std::string dirPath_;
00182         dirent*     curEntry_;
00184         size_t      entrySize_;
00185 
00186     private:
00203         dirent* mkEntry(size_t s) const;
00211         void delEntry(dirent*& entry) const;
00213         void mkCurEntry();
00214     };                                  // class ScanDir
00215 
00221     class ScanDir::Select {
00222     public:
00224         virtual ~Select() {}
00240         virtual int operator()(
00241             const std::string& dir,
00242             const std::string& name
00243         ) = 0;
00244     };                                  // class ScanDir::Select
00245 
00246 // *********************************************************************
00247 // free functions
00251     std::string dirName(const std::string& path);
00255     std::string baseName(const std::string& path);
00273     int mkDir(
00274         const std::string& path,
00275               bool         mkParents = false
00276     );
00277 
00290     bool fileExists(
00291         const std::string& path,
00292               bool         ct = false
00293     );
00294 
00307     bool dirExists(
00308         const std::string& path,
00309               bool         ct = false
00310     );
00311 
00322     bool openStream(
00323               std::fstream&           stream,
00324         const std::string&            path,
00325               std::ios_base::openmode openMode
00326     );
00327 
00342     int fileOpenError(
00343         const std::string& path,
00344         const std::string& mode
00345     );
00346 }                                       // namespace OSB_LIB
00347 #endif                                  // #ifndef _OSBFILEUTIL_H_

Generated on Sat Sep 2 14:06:33 2006 for OSB Library by  doxygen 1.4.7