# gdcmDirectory.h

Go to the documentation of this file.

    00001 /*=========================================================================
    00002
    00003   Program: GDCM (Grassroots DICOM). A DICOM library
    00004   Module:  $URL$
    00005
    00006   Copyright (c) 2006-2010 Mathieu Malaterre
    00007   All rights reserved.
    00008   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
    00009
    00010      This software is distributed WITHOUT ANY WARRANTY; without even
    00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
    00012      PURPOSE.  See the above copyright notice for more information.
    00013
    00014 =========================================================================*/
    00015 #ifndef GDCMDIRECTORY_H
    00016 #define GDCMDIRECTORY_H
    00017
    00018 #include "gdcmTypes.h"
    00019
    00020 #include <string>
    00021 #include <vector>
    00022 #include <iostream>
    00023 #include <assert.h>
    00024
    00025 namespace gdcm
    00026 {
    00042 //-----------------------------------------------------------------------------
    00043 class GDCM_EXPORT Directory
    00044 {
    00045   friend std::ostream& operator<<(std::ostream &_os, const Directory &d);
    00046 public :
    00047   Directory() {}
    00048   ~Directory() {}
    00049   typedef std::string FilenameType;
    00050   typedef std::vector<FilenameType> FilenamesType;
    00051
    00053   void Print(std::ostream &os = std::cout) const;
    00054
    00056   FilenameType const &GetToplevel() const { return Toplevel; }
    00057
    00059   FilenamesType const &GetFilenames() const {
    00060     assert( !(Toplevel.empty()) && "Need to call Explore first" );
    00061     return Filenames; }
    00062
    00064   FilenamesType const &GetDirectories() const { return Directories; }
    00065
    00068   unsigned int Load(FilenameType const &name, bool recursive = false) {
    00069     Filenames.clear(); // clear previous
    00070     Directories.clear(); // clear previous
    00071     Toplevel = name;
    00072     return Explore( Toplevel, recursive );
    00073   }
    00074   // \todo later: GLOB
    00075   // The glob() function searches for all the pathnames matching pattern according to
    00076   // the rules used by the shell (see glob(7)).  No tilde expansion or parameter
    00077   // substitution is done; if you want these, use wordexp(3).
    00078   // int Glob(...);
    00079
    00080 protected:
    00082   unsigned int Explore(FilenameType const &name, bool recursive);
    00083
    00084 private :
    00086   FilenamesType Filenames;
    00087   FilenamesType Directories;
    00088
    00090   FilenameType Toplevel;
    00091 };
    00092 //-----------------------------------------------------------------------------
    00093 inline std::ostream& operator<<(std::ostream &os, const Directory &d)
    00094 {
    00095   d.Print( os );
    00096   return os;
    00097 }
    00098
    00099 } // end namespace gdcm
    00100 //-----------------------------------------------------------------------------
    00101 #endif //GDCMDIRECTORY_H