COPASI API  4.16.103
CDirEntry.h
Go to the documentation of this file.
1 /* Begin CVS Header
2  $Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/utilities/CDirEntry.h,v $
3  $Revision: 1.12 $
4  $Name: $
5  $Author: shoops $
6  $Date: 2009/07/17 17:24:57 $
7  End CVS Header */
8 
9 // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
11 // and The University of Manchester.
12 // All rights reserved.
13 
14 // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual
15 // Properties, Inc. and EML Research, gGmbH.
16 // All rights reserved.
17 
18 #ifndef COPASI_CDirEntry
19 #define COPASI_CDirEntry
20 
21 #include <string>
22 #include <vector>
23 
24 /**
25  * This class provides an OS independent interface to directory entries
26  * such as files and directories.
27  */
28 class CDirEntry
29 {
30 public:
31  /**
32  * The character used to separate directory entries.
33  */
34  static const std::string Separator;
35 
36  /**
37  * Check whether the directory entry specified by 'path' is
38  * a file.
39  * @param const std::string & path
40  * @return bool isFile
41  */
42  static bool isFile(const std::string & path);
43 
44  /**
45  * Check whether the directory entry specified by 'path' is
46  * is a directory.
47  * @param const std::string & path
48  * @return bool isDir
49  */
50  static bool isDir(const std::string & path);
51 
52  /**
53  * Check whether the directory entry specified by 'path' exists.
54  * @param const std::string & path
55  * @return bool exist
56  */
57  static bool exist(const std::string & path);
58 
59  /**
60  * Check whether the directory entry specified by 'path' is
61  * is readable.
62  * @param const std::string & path
63  * @return bool isReadable
64  */
65  static bool isReadable(const std::string & path);
66 
67  /**
68  * Check whether the directory entry specified by 'path' is
69  * writable.
70  * @param const std::string & path
71  * @return bool isWritable
72  */
73  static bool isWritable(const std::string & path);
74 
75  /**
76  * Returns the base name, i.e., the directory path and the
77  * the suffix are removed from 'path'.
78  * @param const std::string & path
79  * @return std::string baseName
80  */
81  static std::string baseName(const std::string & path);
82 
83  /**
84  * Returns the file name, i.e., the directory path is removed from 'path'.
85  * @param const std::string & path
86  * @return std::string fileName
87  */
88  static std::string fileName(const std::string & path);
89 
90  /**
91  * Returns the directory path to the parent directoryu, i.e.,
92  * the file name or directory name are removed from 'path'.
93  * @param const std::string & path
94  * @return std::string dirName
95  */
96  static std::string dirName(const std::string & path);
97 
98  /**
99  * Returns the suffix, i.e., the directory path and the
100  * the base name are removed from 'path'.
101  * @param const std::string & path
102  * @return std::string basename
103  */
104  static std::string suffix(const std::string & path);
105 
106  /**
107  * Create the directory 'dir' in the parent directory 'parent'.
108  * @param const std::string & dir
109  * @param const std::string & parent (Default: current working directory)
110  * @return bool success
111  */
112  static bool createDir(const std::string & dir,
113  const std::string & parent = "");
114 
115  /**
116  * Create a name for a temporary directory entry. The directory entry
117  * will be located in the directory given
118  * @param const std::string & dir
119  * @param const std::string & suffix
120  * @return std::string tmpName
121  */
122  static std::string createTmpName(const std::string & dir,
123  const std::string & suffix);
124 
125  /**
126  * Move a file from. If to is the directory the filename of from is
127  * appended.
128  * @param const std::string & from
129  * @param const std::string & to
130  * @return bool success
131  */
132  static bool move(const std::string & from,
133  const std::string & to);
134 
135  /**
136  * Removes a file or directory specified by path.
137  * @param const std::string & path
138  * @return bool success
139  */
140  static bool remove(const std::string & path);
141 
142  /**
143  * Remove files or directories matching the pattern in directory dir.
144  * @param const std::string & pattern
145  * @param const std::string & dir
146  * @return bool success
147  */
148  static bool removeFiles(const std::string & pattern,
149  const std::string & dir);
150 
151  /**
152  * Compiles the pattern to a patternList. Valid wildcards in the pattern are:
153  * '*' matches any number of characters and '?' matches exactly one character.
154  * @param const std::string & pattern
155  * @return std::vector< std::string > patternList
156  */
157  static std::vector< std::string > compilePattern(const std::string & pattern);
158 
159  /**
160  * Compare the name against the pattern list and returns whether the
161  * name matches. The patternList can be created from a pattern by the
162  * compilePattern method.
163  * @param const std::string & name
164  * @param const std::vector< std::string > & patternList
165  * @return bool match
166  */
167  static bool match(const std::string & name,
168  const std::vector< std::string > & patternList);
169 
170  /**
171  * Checks whether the given path is relative
172  * @return bool isRelative
173  */
174  static bool isRelativePath(const std::string & path);
175 
176  /**
177  * Makes the absolute path relative to the path given in relativeTo
178  * @param std::string & absolutePath
179  * @param const std::string & relativeTo
180  * @return bool success
181  */
182  static bool makePathRelative(std::string & absolutePath,
183  const std::string & relativeTo);
184 
185  /**
186  * Makes the relative path absolute to the path given in absoluteTo
187  * @param std::string & relativePath
188  * @param const std::string & absoluteTo
189  * @return bool success
190  */
191  static bool makePathAbsolute(std::string & relativePath,
192  const std::string & absoluteTo);
193 
194  /**
195  * This method normalizes the path, i.e.,
196  * it converts all '\' to '/' (only on WIN32)
197  * and collapses '^./' to '^', '/./' to '/', and '[^/]+/../' to '/'
198  * @param const std::string & path
199  * @return std::string normalizedPath
200  */
201  static std::string normalize(const std::string & path);
202 
203 private:
204  /**
205  * This private methods checks whether the active section matches the
206  * secified patter. The section is automatically advanced to allow
207  * repeated calls. On the first call 'at' must be 0. The parameters
208  * 'at' and 'after' must not be changed outside this method.
209  * @param const std::string & name
210  * @param const std::string pattern
211  * @param std::string::size_type & at
212  * @param std::string::size_type & after
213  * @return bool match
214  */
215  static bool matchInternal(const std::string & name,
216  const std::string pattern,
217  std::string::size_type & at,
218  std::string::size_type & after);
219 };
220 
221 #endif // COPASI_CDirEntry
static bool isFile(const std::string &path)
Definition: CDirEntry.cpp:52
static bool isDir(const std::string &path)
Definition: CDirEntry.cpp:65
static bool move(const std::string &from, const std::string &to)
Definition: CDirEntry.cpp:233
static bool isRelativePath(const std::string &path)
Definition: CDirEntry.cpp:414
static bool match(const std::string &name, const std::vector< std::string > &patternList)
Definition: CDirEntry.cpp:398
static std::string fileName(const std::string &path)
Definition: CDirEntry.cpp:119
static bool removeFiles(const std::string &pattern, const std::string &dir)
Definition: CDirEntry.cpp:290
static std::string baseName(const std::string &path)
Definition: CDirEntry.cpp:98
static bool matchInternal(const std::string &name, const std::string pattern, std::string::size_type &at, std::string::size_type &after)
Definition: CDirEntry.cpp:506
static std::string dirName(const std::string &path)
Definition: CDirEntry.cpp:135
static bool createDir(const std::string &dir, const std::string &parent="")
Definition: CDirEntry.cpp:180
static bool exist(const std::string &path)
Definition: CDirEntry.cpp:78
static const std::string Separator
Definition: CDirEntry.h:34
static bool isWritable(const std::string &path)
Definition: CDirEntry.cpp:95
static std::string createTmpName(const std::string &dir, const std::string &suffix)
Definition: CDirEntry.cpp:202
static std::vector< std::string > compilePattern(const std::string &pattern)
Definition: CDirEntry.cpp:372
static std::string normalize(const std::string &path)
Definition: CDirEntry.cpp:560
static bool isReadable(const std::string &path)
Definition: CDirEntry.cpp:92
static bool makePathAbsolute(std::string &relativePath, const std::string &absoluteTo)
Definition: CDirEntry.cpp:481
static bool makePathRelative(std::string &absolutePath, const std::string &relativeTo)
Definition: CDirEntry.cpp:434
static std::string suffix(const std::string &path)
Definition: CDirEntry.cpp:159