home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / OTL-MC7.DMS / in.adf / classes.lha / Classes / DOS / Files.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-31  |  5.2 KB  |  198 lines

  1. #ifndef CPP_DOS_FILES_H
  2. #define CPP_DOS_FILES_H
  3.  
  4. // Datei- und Lockklassen
  5. //
  6. // Autor: Jochen Becher
  7. //
  8. // Historie:
  9. // Version 1.0 am 18. Februar 94
  10.  
  11. #ifndef DOS_DOS_H
  12. #include <dos/dos.h>
  13. #endif
  14.  
  15. #ifndef DOS_DOSEXTENS_H
  16. #include <dos/dosextens.h>
  17. #endif
  18.  
  19. #ifndef CPP_DOS_DOS_H
  20. #include <classes/dos/dos.h>
  21. #endif
  22.  
  23. #ifndef CPP_UTILITY_TAGITEM_H
  24. #include <classes/utility/tagitem.h>
  25. #endif
  26.  
  27. #ifndef CPP_EXEC_SHARE_H
  28. #include <classes/exec/share.h>
  29. #endif
  30.  
  31. #ifndef CPP_DATASTRUCTURES_BUFFER_H
  32. #include <classes/datastructures/buffer.h>
  33. #endif
  34.  
  35. #ifndef CPP_DATASTRUCTURES_STRING_H
  36. #include <classes/datastructures/string.h>
  37. #endif
  38.  
  39. class FileInfoBlockC : public DosObjectC {
  40. public:
  41.     FileInfoBlockC(struct TagItem *tags = NULL) throw (DosObjectX, MemoryX)
  42.         : DosObjectC(DOS_FIB,tags) { };
  43.     FileInfoBlockC(Tag tag1type, ...) throw (DosObjectX, MemoryX)
  44.         : DosObjectC(DOS_FIB,(struct TagItem *) &tag1type) { };
  45.     struct FileInfoBlock *object() const
  46.         { return (struct FileInfoBlock *) DosObjectC::object(); };
  47. };
  48.  
  49. class ExAllControlC : public DosObjectC {
  50. public:
  51.     ExAllControlC(struct TagItem *tags = NULL) throw (DosObjectX, MemoryX)
  52.         : DosObjectC(DOS_EXALLCONTROL,tags) { };
  53.     ExAllControlC(Tag tag1type, ...) throw (DosObjectX, MemoryX)
  54.         : DosObjectC(DOS_EXALLCONTROL,(struct TagItem *) &tag1type) { };
  55.     struct ExAllControl *object() const
  56.         { return (struct ExAllControl *) DosObjectC::object(); };
  57. };
  58.  
  59. class InfoDataC : public DosObjectC {
  60. public:
  61.     InfoDataC() throw (DosObjectX, MemoryX);
  62.     ~InfoDataC();
  63.     InfoDataC &operator= (const InfoDataC &);
  64.     struct InfoData *object() const
  65.         { return (struct InfoData *) DosObjectC::object(); };
  66. };
  67.  
  68. class PathStringC : public StringC {
  69. public:
  70.     PathStringC(LONG initsize) throw (MemoryX);
  71.     PathStringC(const STRPTR = NULL) throw (MemoryX);
  72.     PathStringC(const PathStringC &);
  73.     ~PathStringC();
  74.     PathStringC &operator= (const PathStringC &);
  75.     STRPTR path() const { return (STRPTR) buffer.buffer(); }
  76.     VOID setPath(STRPTR path) throw (MemoryX);
  77.     VOID addPart(STRPTR add) throw (MemoryX);
  78.     VOID addSuffix(STRPTR suffix) throw (MemoryX);
  79.     STRPTR filePart() const;
  80.     VOID cutBeforeFilePart();
  81.     VOID cutBehindPathPart();
  82.     VOID cutSuffix();
  83. };
  84.  
  85. class FileLockC {
  86. public:
  87.     FileLockC();
  88.     FileLockC(const FileLockC &);
  89.     FileLockC(BPTR lock);
  90.     ~FileLockC();
  91.     FileLockC &operator= (const FileLockC &);
  92.     BPTR lock() const { return filelock; };
  93.     BOOL isLocked() const { return filelock != NULL; };
  94.     BOOL lock(STRPTR name, LONG mode);
  95.     BOOL duplicate(FileLockC &fromLock);
  96.     BOOL duplicate(class FileHandleC &fromHandle);
  97.     VOID unlock();
  98.     BOOL changeMode(ULONG mode);
  99.     BOOL sameDevice(FileLockC &other) const;
  100.     BOOL sameLock(FileLockC &other) const;
  101.     BOOL nameOfLock(STRPTR buffer, LONG length) const;
  102.     BOOL nameOfLock(PathStringC &) const;
  103.     BOOL examine(struct FileInfoBlock *) const;
  104.     BOOL examine(FileInfoBlockC &) const;
  105.     BOOL info(struct InfoData *) const;
  106.     BOOL info(InfoDataC &) const;
  107.     static LONG ioErr();
  108. protected:
  109.     BPTR filelock;
  110. };
  111.  
  112. class DirLockC : public FileLockC {
  113. public:
  114.     DirLockC();
  115.     DirLockC(BPTR lock);
  116.     BOOL create(STRPTR name);
  117.     BOOL parentOf(FileLockC &lock);
  118.     BOOL parentOf(class FileHandleC &handle);
  119.     BOOL fromCurrent();
  120.     BOOL fromBootvolume();
  121.     BOOL fromProgramDir();
  122.     BOOL exAll(struct ExAllControl *, APTR buffer, ULONG bufsize, ULONG type);
  123.     BOOL exAll(ExAllControlC &, APTR buffer, ULONG bufsize, ULONG type);
  124.     VOID exAllEnd(struct ExAllControl *, APTR buffer, ULONG bufsize, ULONG type);
  125.     VOID exAllEnd(ExAllControlC &, APTR buffer, ULONG bufsize, ULONG type);
  126.     BOOL exNext(struct FileInfoBlock *);
  127.     BOOL exNext(FileInfoBlockC &);
  128. };
  129.  
  130. class CurrentDirC {
  131. public:
  132.     CurrentDirC();
  133.     CurrentDirC(STRPTR name);
  134.     ~CurrentDirC();
  135.     BOOL makeCurrent(DirLockC &);
  136. private:
  137.     CurrentDirC(const CurrentDirC &);
  138.     CurrentDirC &operator = (const CurrentDirC &);
  139.     BPTR filelock;
  140. };
  141.  
  142. class FileHandleC {
  143. public:
  144.     FileHandleC();
  145.     FileHandleC(const FileHandleC &);
  146.     virtual ~FileHandleC();
  147.     FileHandleC &operator = (const FileHandleC &);
  148.     BPTR handle() const { return filehandle; };
  149.     BOOL open(STRPTR name, LONG mode);
  150.     BOOL open(FileLockC &);
  151.     virtual BOOL close();
  152.     BOOL changeMode(ULONG mode);
  153.     LONG read(APTR buffer, LONG length);
  154.     LONG write(APTR buffer, LONG length);
  155.     LONG seek(LONG position, LONG mode = OFFSET_BEGINNING);
  156.     BOOL eof();
  157.     LONG fGetC();
  158.     BOOL fGets(STRPTR s, ULONG len);
  159.     BOOL fPutC(ULONG c);
  160.     BOOL fPuts(STRPTR s);
  161.     ULONG fRead(APTR buffer, ULONG len, ULONG blocks);
  162.     ULONG fWrite(APTR buffer, ULONG len, ULONG blocks);
  163.     LONG fPrintF(STRPTR s, LONG *args = NULL);
  164.     LONG fPrintF(STRPTR s, ...);
  165.     VOID fWriteF(STRPTR s, LONG *args = NULL);
  166.     VOID fWriteF(STRPTR s, ...);
  167.     VOID unGetC(LONG c = -1);
  168.     BOOL flush();
  169.     BOOL setVBuf(APTR buffer, LONG mode, LONG bufsize);
  170.     BOOL waitForChar(ULONG micros);
  171.     BOOL isInteractive();
  172.     BOOL nameOfHandle(STRPTR buffer, LONG length) const;
  173.     BOOL nameOfHandle(PathStringC &) const;
  174.     BOOL examine(struct FileInfoBlock *) const;
  175.     BOOL examine(FileInfoBlockC &) const;
  176.     LONG setSize(LONG offset, LONG mode);
  177.     static LONG ioErr();
  178. protected:
  179.     BPTR filehandle;
  180.     FileInfoBlockC fib;
  181. };
  182.  
  183. class InputHandleC : public FileHandleC {
  184. public:
  185.     InputHandleC();
  186.     ~InputHandleC();
  187.     BOOL close();
  188. };
  189.  
  190. class OutputHandleC : public FileHandleC {
  191. public:
  192.     OutputHandleC();
  193.     ~OutputHandleC();
  194.     BOOL close();
  195. };
  196.  
  197. #endif
  198.