44 Log::error(
"MemoryDirectory::setPath() given an empty path.\n");
53 std::map< String, ref<MemoryFile> > file_map;
59 Log::warning(
Say(
"MemoryDirectory::setPath() : invalid path file '%s'.\n") << p );
63 it->second->setPath(root + p);
64 file_map[it->second->path()] = it->second;
75 Log::error(
"VirtualDirectory::path() must not be empty!\n" );
108 std::map< String, ref<MemoryFile> >::const_iterator it =
mFiles.find(p);
114 mem_file->operator=(*it->second);
115 return mem_file.
get();
124 Log::error(
"VirtualDirectory::path() must not be empty!\n" );
129 if (!it->first.startsWith(
path()))
131 file_list.push_back( it->first );
141 Log::error(
"VirtualDirectory::path() must not be empty!\n" );
144 std::set<String> sub_dirs;
151 while(p.startsWith(
'/'))
154 if (p.length()>3 && p[1] ==
':' && p[2] ==
'/')
156 drive_letter = p.
left(3);
161 std::vector<String> tokens;
162 p.
split(
'/',tokens,
true);
164 sub_dirs.insert(
path() + tokens[0]);
166 for(std::set<String>::const_iterator it = sub_dirs.begin(); it != sub_dirs.end(); ++it)
175 Log::error(
"VirtualDirectory::path() must not be empty!\n" );
181 if (it->first.startsWith(p+
'/'))
201 Log::error(
"VirtualDirectory::path() must not be empty!\n" );
206 if (it->first.extractPath().left(-1) ==
path())
207 file_list.push_back( it->first );
215 std::vector<String> file_list;
217 for(
unsigned i=0; i<file_list.size(); ++i)
bool addFile(MemoryFile *file)
The string file->path() must contain the full path including the MemoryDirectory's path() ...
A simple String formatting class.
static void warning(const String &message)
Use this function to provide information about situations that might lead to errors or loss of data...
void listSubDirs(std::vector< String > &dirs, bool append=false) const
The String class implements an advanced UTF16 (Unicode BMP) string manipulation engine.
void listFiles(std::vector< String > &file_list, bool append=false) const
static void error(const String &message)
Use this function to provide information about run-time errors: file not found, out of memory...
ref< MemoryDirectory > memorySubDir(const String &subdir_name) const
String extractPath() const
If the String contains a file path the function returns the path with trailing slash, without the file name.
MemoryDirectory(const String &path=".")
String left(int count) const
Returns the count leftmost caracters of a String. If count is negative the function returns all but t...
String & normalizeSlashes()
Transform \ slashes in / slashes and removes duplicates.
String & trim(wchar_t ch)
Removes the specified character ch from the beginning and the end of the String.
const String & path() const
Returns the path of the file.
Visualization Library main namespace.
virtual const String & path() const
virtual ref< VirtualFile > file(const String &name) const
Returns the VirtualFile with the given name if any, NULL otherwise.
A VirtualFile to manipulate files stored in memory.
void clone(VirtualDirectory *directory, const String &match="*")
Clones the content of another directory (empty directories are never cloned).
virtual void listFilesRecursive(std::vector< String > &file_list) const =0
Returns the list of files contained in the VirtualDirectory.
Abstact class representing a directory of files.
bool empty() const
Returns true if length() == 0.
void split(wchar_t separator, std::vector< String > &fields, bool remove_empty_fields=false) const
Splits a String into a set of fields. The fields are separated by the specified separator and are ret...
bool startsWith(const String &str) const
Returns true if a String starts with the specified String str.
void setPath(const String &name)
Changes the path bound to a VirtualFile. Use carefully this function, you shouldn't rename a VirtualF...
bool removeFile(MemoryFile *file)
The string file->path() must contain the full path including the MemoryDirectory's path() ...
The ref<> class is used to reference-count an Object.
String right(int count) const
Returns the count rightmost caracters of a String. If count is negative the function returns all but ...
bool endsWith(const String &str) const
Returns true if a String ends with the specified String str.
ref< MemoryFile > memoryFile(const String &name) const
std::map< String, ref< MemoryFile > > mFiles
void copy(VirtualFile *file)
Copies the data of any kind of VirtualFile.
String translatePath(const String &p) const
void listFilesRecursive(std::vector< String > &file_list) const
Returns the list of files contained in the VirtualDirectory.
virtual ref< VirtualFile > file(const String &name) const =0
Returns the VirtualFile with the given name if any, NULL otherwise.
virtual bool setPath(const String &name)
Changes the path name of a VirtualDirectory. Must not be an empty string.