home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- CLASS: MiscFile
- INHERITS FROM: MiscGraphNode
- CONFORMS TO: None
- PROGRAMMER: Todd Thomas, Copyright 1994, 1995.
- BEGAN: June 6, 1994
- LAST CHANGED: December 6, 1995 <alastair@csarc.otago.ac.nz>
- CHANGES: See end of implementation file.
- VERSION: 0.7
-
- The MiscFile just adds enough to MiscGraphNode so we can represent
- a single file or a heirarchy of files from the filesystem. Some of
- the more relevant features include: only one instance per pathname
- (though there is reference counting), a class delegate for all
- instances of MiscFile, and creating children of different classes
- (several different ways, see +setDefaultFileClass:
- +setDefaultFileClass:forClass: +registerFileClass:forExtension:).
- See the documentation for this class and it's categories for more
- information. Also check out the FileBrowser example.
-
- For those that are wondering why you cannot create a MiscFile that
- contains just "me.tiff" (since by default, the pathname must exist)
- is that the rest of the methods in this class would not make much
- sense. Use a string class or subclass for that.
-
- I also had much help from others when designing this class and it's
- categories. They are listed in MiscFile's documentation. Thanks very much.
-
- This object is included in the MiscKit by permission from the author
- and its use is governed by the MiscKit license, found in the file
- "LICENSE.rtf" in the MiscKit distribution. Please refer to that file
- for a list of all applicable permissions and restrictions.
-
- *************************************************************************/
-
- #import <sys/stat.h>
- #import <misckit/MiscFileDefs.h>
- #import <misckit/MiscGraphNode.h>
-
- @class List;
-
-
- @interface MiscFile : MiscGraphNode
- {
- char *path; // The path the MiscFile represents
- struct stat *st; // Each MiscFile has it's own space for stat info
- short errorCode; // Same as errno (see man 2 intro)
- short refCount; // Use reference counting to count instances
- struct __mfFlags
- {
- unsigned int childrenLoaded:1; // are the children already loaded?
- unsigned int useExtensions:1; // to determine child class
- unsigned int displayAsLeaf:1; // display as leaf or node
- unsigned int childrenInherit:1; // inherit parent's attributes?
- unsigned int visited:1; // stop circular searching
- unsigned int enableCaching:1; // cache the stat struct?
- unsigned int lastStat:1; // using stat or lstat?
- } mfFlags;
- }
-
- // Methods for setting the class that any of the MiscFile's children
- // will be instantiated from.
- + setDefaultFileClass: classId;
- + setDefaultFileClass: classId forClass:aClass;
- + registerFileClass: classId forExtension: (const char *)extension;
- + lookupClassForFilename: (const char *)filenameOrPath;
-
- // Stats the given path and returns YES if it exists.
- + (BOOL)isPathValid: (const char *)fullPath;
-
- // Class methods for the class delegate.
- + setClassDelegate: aDelegate;
- + classDelegate;
-
- // Methods for initialization and destruction.
- + initialize;
- - initWithPath: (const char *)fullPath;
- - initWithName: (const char *)filename inDirectory: (const char *)directory;
- - free;
-
- - setLeaf: (BOOL)isALeaf;
- - (BOOL)displayAsLeaf;
- - setDisplayAsLeaf: (BOOL)asLeaf;
-
- - (const char *)fullPath;
- - (const char *)filename;
- - (const char *)extension;
-
- - children;
- - (List *)updateChildren;
- - loadChildrenFromFilesystem;
- - (BOOL)childrenLoaded;
-
- - (BOOL)createChildrenUsingExtensions;
- - setCreateChildrenUsingExtensions: (BOOL)useExts;
-
- // Methods for passing on attributes to your children.
- - (BOOL)childrenInherit;
- - setChildrenInherit: (BOOL)inherit;
- - passOnTraits: parent;
-
- // Internally used method to return the class that a child should be
- // instantiated from depending upon if it should use the file extensions
- // or what the default class is set to.
- - _childrensClassGivenFilename: (const char *)filenameOrPath;
-
- // Archiving methods
- - awake;
- - read: (NXTypedStream *)stream;
- - write: (NXTypedStream *)stream;
-
- @end
-
-
- // Include the categories anywhere someone wants MiscFile.h.
- #import "MiscFile+Creation.h"
- #import "MiscFile+Info.h"
- #import "MiscFile+Modification.h"
- #import "MiscFile+Searching.h"
- #import "MiscFile+Unix.h"
-
-