home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 14 / MA_Cover_14.iso / source / c / pegase_src / amigaos.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-14  |  13.2 KB  |  413 lines

  1. #ifndef _AMIGAOS_HPP
  2. #define _AMIGAOS_HPP 1
  3. /*
  4. **
  5. ** AmigaOS.hpp
  6. **
  7. ** (c) 1998 Didier Levet
  8. **
  9. ** AmigaOS class
  10. **
  11. ** $Revision: 1.1 $
  12. ** $State: Exp $
  13. ** $Date: 1998/10/05 19:55:18 $
  14. **
  15. ** $Log: AmigaOS.hpp $
  16. ** Revision 1.1  1998/10/05 19:55:18  kakace
  17. ** AmigaOS stubs (namespace emulation)
  18. **
  19. **
  20. */
  21.  
  22.  
  23. //----------------------------------------------------------------------------------------------------
  24. //============================================= INCLUDES =============================================
  25. //----------------------------------------------------------------------------------------------------
  26.  
  27. /// Includes
  28.  
  29. #ifndef  _INCLUDE_STRING_H
  30. #include <string.h>
  31. #endif
  32.  
  33. #ifndef  CLIB_EXEC_PROTOS_H
  34. #include <clib/exec_protos.h>
  35. #endif
  36.  
  37. #ifndef  CLIB_DOS_PROTOS_H
  38. #include <clib/dos_protos.h>
  39. #endif
  40.  
  41. #ifndef  CLIB_INTUITION_PROTOS_H
  42. #include <clib/intuition_protos.h>
  43. #endif
  44.  
  45. #ifndef  CLIB_ICON_PROTOS_H
  46. #include <clib/icon_protos.h>
  47. #endif
  48.  
  49. #ifndef  CLIB_LOCALE_PROTOS_H
  50. #include <clib/locale_protos.h>
  51. #endif
  52.  
  53. #ifndef  CLIB_ASL_PROTOS_H
  54. #include <clib/asl_protos.h>
  55. #endif
  56.  
  57. #ifndef  _STRING_CLASS_HPP
  58. #include "StringClass.hpp"
  59. #endif
  60.  
  61. ///
  62.  
  63.  
  64. // These classes are used to emulate the "namespace" system for AmigaOS functions.
  65. // Most functions are inlined, and some of them may contains bug fixes.
  66.  
  67.  
  68. extern "ASM"
  69. {
  70.     void PutCharProc();
  71. };
  72.  
  73.  
  74. //----------------------------------------------------------------------------------------------------
  75. //========================================== class ExecLib ===========================================
  76. //----------------------------------------------------------------------------------------------------
  77.  
  78. struct ExecLib
  79. {
  80.     static STRING       RawDoFmt(STRING patternString, void *dataStream);
  81.  
  82.     static const Task * FindTask(STRING name = NULL)
  83.                         {
  84.                             return ::FindTask((UBYTE *) name);
  85.                         }
  86.  
  87.     static BYTE         SetTaskPri(BYTE priority = 0)
  88.                         {
  89.                             return ::SetTaskPri( (Task *) ::FindTask(NULL), priority);
  90.                         }
  91.  
  92.     //===== Private area =============================================================================
  93.  
  94.     private:
  95.  
  96.     static void         PutCharProc(register __d0 char c);
  97.  
  98.     static char fmt_buffer[350];        // Buffer for all "RawDoFmt" calls.
  99.     static char *fmt_ptr;
  100. };
  101.  
  102.  
  103. //----------------------------------------------------------------------------------------------------
  104. //=========================================== class DOSLib ===========================================
  105. //----------------------------------------------------------------------------------------------------
  106.  
  107. struct DOSLib
  108. {
  109.     static int          GetProgramName(CString& progName);
  110.     static int          NameFromLock(BPTR lock, CString& buffer);
  111.     static int          NameFromFH(BPTR fileHandle, CString& buffer);
  112.     static int          AddPart(CString& dirName, STRING fileName);
  113.     static int          MatchPatternNoCase(const CString& pattern, STRING str);
  114.  
  115.     static LONG         IoErr()                     {return ::IoErr();}
  116.     static LONG         SetIoErr(LONG errCode)      {return ::SetIoErr(errCode);}
  117.     static BPTR         Output()                    {return ::Output();}
  118.     static BPTR         GetProgramDir()             {return ::GetProgramDir();}
  119.     static BPTR         CurrentDir(BPTR lock)       {return ::CurrentDir(lock);}
  120.  
  121.     // The following functions make use of CString objects so that modifying the returned
  122.     // string can't change the original string.
  123.  
  124.     static CString      FilePart(STRING path)       {return ::FilePart( (STRPTR) path);}
  125.     static CString      PathPart(STRING path)
  126.                         {
  127.                             CString s = path;
  128.                             if (s != CString::EMPTY)
  129.                             {
  130.                                 s[::PathPart(s) - s.string()] = '\0';
  131.                             }
  132.                             return s;
  133.                         }
  134.  
  135.     static int          PrintFault(ULONG error, STRING header)          // V36
  136.                         {
  137.                             return ::PrintFault(error, (STRPTR) header);
  138.                         }
  139.  
  140.     //===== Private area =============================================================================
  141.  
  142.     private:
  143.  
  144.     static LONG         GetProgramName(BPTR dummy, STRPTR name, LONG len)
  145.                                                     {return :: GetProgramName(name, len);}
  146.  
  147.     static int          AutoExtend(BPTR handle, CString &buffer, ULONG step, LONG (*func)(BPTR, STRPTR, LONG));
  148. };
  149.  
  150.  
  151. //----------------------------------------------------------------------------------------------------
  152. //======================================== class IntuitionLib ========================================
  153. //----------------------------------------------------------------------------------------------------
  154.  
  155. struct IntuitionLib
  156. {
  157.     static LONG         EasyRequestArgs(Window *window, EasyStruct *easyStruct, ULONG *idcmpPtr, APTR args)
  158.                         {
  159.                             return ::EasyRequestArgs(window, easyStruct, idcmpPtr, args);
  160.                         }
  161. };
  162.  
  163.  
  164. //----------------------------------------------------------------------------------------------------
  165. //========================================= Special objects ==========================================
  166. //----------------------------------------------------------------------------------------------------
  167. //
  168. // These classes are used to allocate/use/free AmigaOS related stuff in a manner that is compatible
  169. // with exceptions. Once an object is passed to an instance of these classes (or when it is allocated
  170. // by one of these instances), it becomes part of the instance. This means that this object will die
  171. // when the instance will be deleted.
  172. //----------------------------------------------------------------------------------------------------
  173.  
  174.  
  175. //----------------------------------------------------------------------------------------------------
  176. //=========================================== class CFile ============================================
  177. //----------------------------------------------------------------------------------------------------
  178.  
  179. class CFile
  180. {
  181.     public:
  182.  
  183.         enum EMode{READWRITE = 1004, OLDFILE, NEWFILE};
  184.  
  185.         CFile() : fh(0)     {}
  186.         ~CFile()            {if (fh != 0) ::Close(fh);}
  187.  
  188.         BPTR Open(STRING name, EMode accessMode)
  189.         {
  190.             return (fh = ::Open( (STRPTR) name, accessMode));
  191.         }
  192.  
  193.         LONG Read(void *buffer, LONG length)
  194.         {
  195.             return ::Read(fh, buffer, length);
  196.         }
  197.  
  198.         operator BPTR() const       {return fh;}
  199.  
  200.     protected:
  201.  
  202.         CFile(const CFile &);                   // Not implemented.
  203.         CFile& operator =(const CFile &);       // Ditto.
  204.  
  205.         BPTR    fh;
  206. };
  207.  
  208.  
  209. //----------------------------------------------------------------------------------------------------
  210. //=========================================== class CMatch ===========================================
  211. //----------------------------------------------------------------------------------------------------
  212.  
  213. class CMatch
  214. {
  215.     public:
  216.  
  217.         // Constructor. An AnchorPath structure may be passed to it and is adopted
  218.         // by the object (the destructor will destroy it later).
  219.         CMatch(AnchorPath *anchor = NULL) : pAnchor(anchor), CloseMe(FALSE) {}
  220.  
  221.         ~CMatch()
  222.         {
  223.             if (CloseMe != FALSE) ::MatchEnd(pAnchor);
  224.             delete pAnchor;                     // Delete the AnchorPath structure.
  225.         }
  226.  
  227.         // Matching initialization. If an AnchorPath structure is given, it is adopted
  228.         // and it will be destroyed by the instance's destructor.
  229.         LONG First(STRING pattern, AnchorPath *anchor = NULL);
  230.  
  231.         LONG Next()
  232.         {
  233.             return ::MatchNext(pAnchor);
  234.         }
  235.  
  236.         // Accessor. A CMatch object can be used as an AnchorPath pointer.
  237.         operator AnchorPath *() const   {return pAnchor;}
  238.  
  239.     protected:
  240.  
  241.         CMatch(const CMatch &);                 // Not implemented.
  242.         CMatch& operator =(const CMatch &);     // Ditto.
  243.  
  244.         AnchorPath *pAnchor;
  245.         int         CloseMe;                    // TRUE if First() has been run.
  246. };
  247.  
  248.  
  249. //----------------------------------------------------------------------------------------------------
  250. //========================================= class CDOSObject =========================================
  251. //----------------------------------------------------------------------------------------------------
  252.  
  253. class CDOSObject
  254. {
  255.     public:
  256.  
  257.         enum ETypes{FILEHANDLE, EXALLCONTROL, FIB, STDPKT, CLI, RDARGS};
  258.  
  259.         CDOSObject() : pAddr(NULL)          {}
  260.         ~CDOSObject()                       {if (pAddr != NULL) ::FreeDosObject(iType, pAddr);}
  261.  
  262.         void *Allocate(ETypes type, TagItem *tags = NULL)
  263.         {
  264.             iType = type;
  265.             return (pAddr = ::AllocDosObject(type, tags));
  266.         }
  267.  
  268.         void *Allocate(ETypes type, Tag tag1, ...) {return Allocate(type, (TagItem *) &tag1);}
  269.  
  270.     protected:
  271.  
  272.         CDOSObject(const CDOSObject &);             // Not implemented.
  273.         CDOSObject& operator =(const CDOSObject &); // Ditto.
  274.  
  275.         ETypes  iType;
  276.         void   *pAddr;
  277. };
  278.  
  279.  
  280. //----------------------------------------------------------------------------------------------------
  281. //========================================== class CRDArgs ===========================================
  282. //----------------------------------------------------------------------------------------------------
  283.  
  284. class CRDArgs
  285. {
  286.     public:
  287.  
  288.         CRDArgs() : pArgs(NULL)     {}
  289.         ~CRDArgs()                  {if (pArgs != NULL) ::FreeArgs(pArgs);}
  290.  
  291.         RDArgs *ReadArgs(STRING argTemplate, LONG *array, RDArgs *args = NULL)
  292.         {
  293.             return (pArgs = ::ReadArgs((STRPTR) argTemplate, array, args));
  294.         }
  295.  
  296.     protected:
  297.  
  298.         CRDArgs(const CRDArgs &);                   // Not implemented.
  299.         CRDArgs& operator =(const CRDArgs &);       // Ditto.
  300.  
  301.         RDArgs *pArgs;
  302. };
  303.  
  304.  
  305. //----------------------------------------------------------------------------------------------------
  306. //=========================================== class CLock ============================================
  307. //----------------------------------------------------------------------------------------------------
  308.  
  309. class CLock
  310. {
  311.     public:
  312.  
  313.         enum ETypes{WRITE = -1, EXCLUSIVE = -1, READ = -2, SHARED = -2};
  314.  
  315.         CLock() : lock(0)               {}
  316.         ~CLock()                        {if (lock != 0) ::UnLock(lock);}
  317.  
  318.         CLock(const CLock& l)           {lock = ::DupLock(l.lock);}
  319.         CLock& operator =(const CLock& l)
  320.         {
  321.             if (&l != this)
  322.                 lock = ::DupLock(l.lock);
  323.             return *this;
  324.         }
  325.  
  326.         operator BPTR() const   {return lock;}
  327.  
  328.         BPTR Lock(STRING name, ETypes type)
  329.         {
  330.             return (lock = ::Lock((STRPTR) name, type));
  331.         }
  332.  
  333.         int  NameFromLock(CString& buffer) // V36
  334.         {
  335.             return DOSLib::NameFromLock(lock, buffer);
  336.         }
  337.  
  338.     protected:
  339.  
  340.         BPTR lock;
  341. };
  342.  
  343.  
  344. //----------------------------------------------------------------------------------------------------
  345. //======================================== class CDiskObject =========================================
  346. //----------------------------------------------------------------------------------------------------
  347.  
  348. class CDiskObject
  349. {
  350.     public:
  351.  
  352.         CDiskObject() : dobj(NULL)      {}
  353.         ~CDiskObject()                  {release();}
  354.  
  355.         DiskObject *Load(STRING name = NULL);
  356.  
  357.         STRING FindToolType(STRING typeName)
  358.         {
  359.             return (STRING) ::FindToolType( (UBYTE **) dobj->do_ToolTypes, (UBYTE *) typeName);
  360.          // return (STRING) ::FindToolType( (STRPTR *) dobj->do_ToolTypes, (UBYTE *) typeName);
  361.         }
  362.  
  363.     protected:
  364.  
  365.         CDiskObject(const CDiskObject &);               // Not implemented.
  366.         CDiskObject& operator =(const CDiskObject &);   // Ditto.
  367.  
  368.         DiskObject *dobj;
  369.  
  370.         void release()                  {if (dobj != NULL) ::FreeDiskObject(dobj);}
  371. };
  372.  
  373.  
  374. //----------------------------------------------------------------------------------------------------
  375. //======================================== class CFileRequest ========================================
  376. //----------------------------------------------------------------------------------------------------
  377.  
  378. class CFileRequest
  379. {
  380.     public:
  381.  
  382.         CFileRequest() : fr(NULL)       {}
  383.         ~CFileRequest()                 {if (fr != NULL) ::FreeAslRequest(fr);}
  384.  
  385.         FileRequester *Init(TagItem *tagList = NULL)
  386.         {
  387.             return (fr = (FileRequester *) ::AllocAslRequest(ASL_FileRequest, tagList));
  388.         }
  389.  
  390.         FileRequester *Request(Tag tag1, ...)
  391.         {
  392.             return Request((TagItem *) &tag1);
  393.         }
  394.  
  395.         FileRequester *Request(TagItem *tagList)
  396.         {
  397.             return (fr != NULL && ::AslRequest(fr, tagList) ? fr : NULL);
  398.         }
  399.  
  400.     protected:
  401.  
  402.         CFileRequest(const CFileRequest &);             // Not implemented.
  403.         CFileRequest& operator =(const CFileRequest &); // Ditto.
  404.  
  405.         FileRequester *fr;
  406. };
  407.  
  408.  
  409. //----------------------------------------------------------------------------------------------------
  410.  
  411. #endif  // !_AMIGAOS_HPP
  412.  
  413.