1 /* "CodeWorker":	a scripting language for parsing and generating text.
2 
3 Copyright (C) 1996-1997, 1999-2002 C�dric Lemaire
4 
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9 
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 Lesser General Public License for more details.
14 
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 
19 To contact the author: codeworker@free.fr
20 */
21 
22 #ifndef _UtlDirectory_h_
23 #define _UtlDirectory_h_
24 
25 #include <string>
26 #include <list>
27 
28 #pragma warning(disable : 4251)
29 
30 namespace CodeWorker {
31 #	define CW_PATH_MAX	4096
32 
33 	class UtlDirectory;
34 
35 	class UtlFile {
36 		private:
37 			UtlDirectory* _pParent;
38 			std::string _sFileName;
39 
40 		public:
41 			UtlFile(UtlDirectory& myParent, const std::string& sFileName);
42 			UtlFile(const std::string& sFileName);
43 			~UtlFile();
44 
getFileName()45 			inline const std::string& getFileName() const {return _sFileName;}
46 			std::string getFileNameBody() const;
47 			std::string getFileNameExtension() const;
getDirectory()48 			inline UtlDirectory* getDirectory() const { return _pParent; }
49 
50 			bool remove();
51 	};
52 
53 
54 	class UtlDirectory {
55 		private:
56 			bool _bScanned;
57 			UtlDirectory* _pParent;
58 			std::string _sDirectoryName;
59 			std::list<UtlFile*> _listOfFiles;
60 			std::list<UtlDirectory*> _listOfDirectories;
61 
62 		public:
63 			UtlDirectory();
64 			UtlDirectory(UtlDirectory& myParent, const std::string& sDirectoryName);
65 			UtlDirectory(const std::string& sDirectoryName);
66 			~UtlDirectory();
67 
getDirectories()68 			inline const std::list<UtlDirectory*>& getDirectories() const {return _listOfDirectories;}
getFiles()69 			inline const std::list<UtlFile*>& getFiles() const {return _listOfFiles;}
getDirectoryName()70 			inline const std::string& getDirectoryName() const {return _sDirectoryName;}
setDirectoryName(const std::string & sDirectoryName)71 			inline void setDirectoryName(const std::string& sDirectoryName) {_sDirectoryName = sDirectoryName;}
72 
73 			UtlDirectory* getSubdirectory(const std::string& sDirectoryName) const;
74 
75 			std::string getFullPath() const;
76 			std::string getRelativePath() const;
77 
78 			bool createDirectory(const std::string& sDirectory);
79 
80 			bool scan(const std::string& sExtendedPattern = "");
81 			bool scanRecursively(const std::string& sPattern = "");
82 
83 			bool remove();
84 
85 			static std::string getTmpDirectory() ;
86 
87 		private:
88 			bool matchPatternDirectory(const std::string& sPatternDirectory);
89 	};
90 }
91 
92 #endif
93