00001 /* 00002 * Filename.h 00003 * 00004 * Smalltalk like class library for C++ 00005 * File name handler and tools. Header. 00006 * 00007 * Copyright (c) 2004 Milan Cermak 00008 */ 00009 /* 00010 * This library is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 2.1 of the License, or (at your option) any later version. 00014 * 00015 * This library is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public 00021 * License along with this library; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 */ 00024 #ifndef __FILENAME_H 00025 #define __FILENAME_H 00026 00027 #include <stlib/Object.h> 00028 00029 #include <stlib/ByteArray.h> 00030 #include <stlib/ExternalReadStream.h> 00031 #include <stlib/ExternalReadAppendStream.h> 00032 #include <stlib/ExternalWriteStream.h> 00033 #include <stlib/FileAccessor.h> 00034 #include <stlib/OrderedCollection.h> 00035 #include <stlib/Stream.h> 00036 #include <stlib/String.h> 00037 00038 namespace Tools { 00039 00040 class FileEncodedStreamFactory; 00041 00042 class Filename : public Core::Object 00043 { 00044 protected: 00045 String *public_name; 00046 char *local_name; 00047 00048 public: 00049 Filename(String *name); 00050 Filename(const char *name); 00051 virtual ~Filename(void); 00052 00053 /* Class-accessing protocol */ 00054 virtual String *className(void) const; 00055 00056 /* Instance creation protocol */ 00057 virtual Filename *construct(String *extra); 00058 virtual Filename *construct(const char *extra); 00059 virtual Filename *construct(Filename *extra); 00060 virtual String *constructString(String *extra); 00061 00062 /* Class-constants protocol */ 00063 static Character *separator(void); 00064 00065 /* Class-defaults protocol */ 00069 static Filename *currentDirectory(void); 00070 static String *currentDirectoryString(void); 00071 00072 /* Class-utilities protocol */ 00073 static OrderedCollection *filesMatching(String *pattern); 00074 00075 /* Class-testing protocol */ 00076 static bool isCaseSensitive(void); 00077 00078 /* Accessing protocol */ 00079 virtual const char *localName(void) const; 00080 00081 /* Comparing protocol */ 00082 virtual long hash(void) const; 00083 virtual bool isEqual(const Object *) const; 00084 virtual bool isEqual(const Object &object) const 00085 { return Object::isEqual(object); } 00086 00087 /* Converting protocol */ 00088 virtual Filename *asFilename(void); 00089 virtual String *asString(void) const; 00090 00091 /* File utilities protocol */ 00092 virtual void beCurrentDirectory(void); 00093 virtual void copyTo(Filename *destName); 00094 virtual void copyTo(String *destName); 00095 virtual OrderedCollection *directoryContents(void); 00099 virtual void erase(void); 00100 virtual long fileSize(void); 00101 virtual void makeDirectory(void); 00102 virtual void moveTo(Filename *destName); 00103 virtual void moveTo(String *destName); 00104 virtual void renameTo(Filename *destName); 00105 virtual void renameTo(String *destName); 00106 00107 /* Parsing protocol */ 00108 static Filename *baseDirectoryForList(OrderedCollection *list); 00109 static String *readBaseLocationFromStream(PositionableStream *stream); 00110 virtual OrderedCollection *components(void); 00111 static OrderedCollection *components(String *name); 00112 virtual Filename *directory(void); 00113 virtual String *extension(void); 00114 virtual String *head(void); 00115 virtual String *tail(void); 00116 00117 /* Printing protocol */ 00118 virtual void printOn(Stream *stream); 00119 00120 /* Stream creation protocol */ 00121 virtual FileEncodedStreamFactory *withEncoding(String *encoding); 00122 virtual FileEncodedStreamFactory *withEncoding(const char *encoding); 00123 virtual ExternalWriteStream *appendStream(void); 00124 virtual ExternalReadStream *readStream(void); 00125 virtual ExternalReadAppendStream *readAppendStream(void); 00126 virtual ExternalWriteStream *writeStream(void); 00127 00128 /* Testing protocol */ 00129 virtual bool exists(void); 00130 virtual bool isAbsolute(void); 00131 virtual bool isDirectory(void); 00132 virtual bool isReadable(void); 00133 virtual bool isRelative(void); 00134 virtual bool isWritable(void); 00135 00136 /* Utilities protocol */ 00137 virtual ByteArray *contentOfEntireFile(void); 00138 00139 /* Private protocol */ 00140 virtual OrderedCollection *filesMatchingAccessList(OrderedCollection *list, 00141 OrderedCollection *result); 00142 virtual long lastSeparatorIndex(void); 00143 virtual void privateCopy(FileAccessor *read, FileAccessor *write); 00144 virtual OrderedCollection *privFilesMatchingAccessList(OrderedCollection *list, 00145 OrderedCollection *result); 00146 static void setCurrentDirectory(Filename *directory); 00147 }; 00148 00149 }; 00150 00151 #endif /* __FILENAME_H */