home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Headers / misckit / MiscFile.h < prev    next >
Encoding:
Text File  |  1995-12-05  |  4.2 KB  |  122 lines

  1. /************************************************************************
  2.   CLASS:            MiscFile
  3.   INHERITS FROM:    MiscGraphNode
  4.   CONFORMS TO:        None
  5.   PROGRAMMER:        Todd Thomas, Copyright 1994, 1995.
  6.   BEGAN:            June 6, 1994
  7.   LAST CHANGED:        December 6, 1995 <alastair@csarc.otago.ac.nz>
  8.   CHANGES:            See end of implementation file.
  9.   VERSION:            0.7        
  10.  
  11.   The MiscFile just adds enough to MiscGraphNode so we can represent 
  12.   a single file or a heirarchy of files from the filesystem. Some of
  13.   the more relevant features include:  only one instance per pathname 
  14.   (though there is reference counting), a class delegate for all 
  15.   instances of MiscFile, and creating children of different classes 
  16.   (several different ways, see +setDefaultFileClass: 
  17.   +setDefaultFileClass:forClass:  +registerFileClass:forExtension:).
  18.   See the documentation for this class and it's categories for more
  19.   information. Also check out the FileBrowser example.
  20.   
  21.   For those that are wondering why you cannot create a MiscFile that
  22.   contains just "me.tiff" (since by default, the pathname must exist) 
  23.   is that the rest of the methods in this class would not make much 
  24.   sense. Use a string class or subclass for that.
  25.   
  26.   I also had much help from others when designing this class and it's
  27.   categories. They are listed in MiscFile's documentation. Thanks very much.
  28.   
  29.   This object is included in the MiscKit by permission from the author
  30.   and its use is governed by the MiscKit license, found in the file
  31.   "LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
  32.   for a list of all applicable permissions and restrictions.
  33.   
  34.  *************************************************************************/
  35.  
  36. #import <sys/stat.h>
  37. #import <misckit/MiscFileDefs.h>
  38. #import <misckit/MiscGraphNode.h>
  39.  
  40. @class List;
  41.  
  42.  
  43. @interface MiscFile : MiscGraphNode
  44. {
  45.     char  *path;            // The path the MiscFile represents
  46.     struct stat  *st;        // Each MiscFile has it's own space for stat info
  47.     short  errorCode;        // Same as errno (see man 2 intro)
  48.     short  refCount;        // Use reference counting to count instances
  49.     struct __mfFlags        
  50.     {
  51.         unsigned int  childrenLoaded:1;        // are the children already loaded?
  52.         unsigned int  useExtensions:1;        // to determine child class
  53.         unsigned int  displayAsLeaf:1;        // display as leaf or node
  54.         unsigned int  childrenInherit:1;    // inherit parent's attributes?
  55.         unsigned int  visited:1;            // stop circular searching
  56.         unsigned int  enableCaching:1;        // cache the stat struct?
  57.         unsigned int  lastStat:1;            // using stat or lstat?
  58.      } mfFlags;    
  59. }
  60.  
  61. // Methods for setting the class that any of the MiscFile's children
  62. // will be instantiated from.
  63. + setDefaultFileClass: classId;
  64. + setDefaultFileClass: classId forClass:aClass;
  65. + registerFileClass: classId forExtension: (const char *)extension;
  66. + lookupClassForFilename: (const char *)filenameOrPath;
  67.  
  68. // Stats the given path and returns YES if it exists.
  69. + (BOOL)isPathValid: (const char *)fullPath;
  70.  
  71. // Class methods for the class delegate.
  72. + setClassDelegate: aDelegate;
  73. + classDelegate;
  74.  
  75. // Methods for initialization and destruction.
  76. + initialize;
  77. - initWithPath: (const char *)fullPath;
  78. - initWithName: (const char *)filename inDirectory: (const char *)directory;
  79. - free;
  80.  
  81. - setLeaf: (BOOL)isALeaf;
  82. - (BOOL)displayAsLeaf;
  83. - setDisplayAsLeaf: (BOOL)asLeaf;
  84.  
  85. - (const char *)fullPath;
  86. - (const char *)filename;
  87. - (const char *)extension;
  88.  
  89. - children;
  90. - (List *)updateChildren;
  91. - loadChildrenFromFilesystem;
  92. - (BOOL)childrenLoaded;
  93.  
  94. - (BOOL)createChildrenUsingExtensions;
  95. - setCreateChildrenUsingExtensions: (BOOL)useExts;
  96.  
  97. // Methods for passing on attributes to your children.
  98. - (BOOL)childrenInherit;
  99. - setChildrenInherit: (BOOL)inherit;
  100. - passOnTraits: parent;
  101.  
  102. // Internally used method to return the class that a child should be
  103. // instantiated from depending upon if it should use the file extensions
  104. // or what the default class is set to.
  105. - _childrensClassGivenFilename: (const char *)filenameOrPath;
  106.  
  107. // Archiving methods
  108. - awake;
  109. - read: (NXTypedStream *)stream;
  110. - write: (NXTypedStream *)stream;
  111.  
  112. @end
  113.  
  114.  
  115. // Include the categories anywhere someone wants MiscFile.h.
  116. #import "MiscFile+Creation.h"
  117. #import "MiscFile+Info.h"
  118. #import "MiscFile+Modification.h"
  119. #import "MiscFile+Searching.h"
  120. #import "MiscFile+Unix.h"
  121.  
  122.