home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 April / macformat-023.iso / Shareware City / Developers / NeoPersist 3.0.8 folder / NeoIncludes / Macintosh / NeoMacintosh.h next >
Encoding:
C/C++ Source or Header  |  1994-10-13  |  10.4 KB  |  339 lines  |  [TEXT/KAHL]

  1.  /************************************************************
  2.  *
  3.  *    Created: Thursday, December 3, 1992 11:57:00 AM
  4.  *    NeoMacintosh.h
  5.  *    Macintosh-specific definitions for NeoLogic products
  6.  *
  7.  *    Copyright © Neologic Systems 1992-1994. All Rights Reserved.
  8.  *    All rights reserved
  9.  *
  10.  ***********************************************************/
  11. #pragma once
  12. #ifndef __NeoMacintosh__
  13. #define __NeoMacintosh__ 1
  14.  
  15. #if defined(__powerc) || defined(powerc)
  16. #define qNeoPowerPC 1
  17. #else
  18. #undef  qNeoPowerPC
  19. #endif
  20.  
  21. #define CNeoAppH                "CNeoApp.h"
  22. #define CNeoArrayH                "CNeoArray.h"
  23. #define CNeoBlobH                "CNeoBlob.h"
  24. #define CNeoClassH                "CNeoClass.h"
  25. #define CNeoDatabaseH            "CNeoDatabase.h"
  26. #define CNeoDocH                "CNeoDoc.h"
  27. #define CNeoFileStreamH            "CNeoFileStream.h"
  28. #define CNeoIndexIteratorH        "CNeoIndexIterator.h"
  29. #define CNeoFreeListH            "CNeoFreeList.h"
  30. #define CNeoIDIndexH            "CNeoIDIndex.h"
  31. #define CNeoIDListH                "CNeoIDList.h"
  32. #define CNeoIOBlockH            "CNeoIOBlock.h"
  33. #define CNeoIteratorH            "CNeoIterator.h"
  34. #define CNeoInodeH                "CNeoInode.h"
  35. #define CNeoMetaClassH            "CNeoMetaClass.h"
  36. #define CNeoNamedOffspringH        "CNeoNamedOffspring.h"
  37. #define CNeoNodeH                "CNeoNode.h"
  38. #define CNeoObjectH                "CNeoObject.h"
  39. #define CNeoOffspringH            "CNeoOffspring.h"
  40. #define CNeoParentIndexH        "CNeoParentIndex.h"
  41. #define CNeoParentNNameIndexH    "CNeoParentNNameIndex.h"
  42. #define CNeoPartListIteratorH    "CNeoPartListIterator.h"
  43. #define CNeoPartMgrH            "CNeoPartMgr.h"
  44. #define CNeoPersistH            "CNeoPersist.h"
  45. #define CNeoSelectH                "CNeoSelect.h"
  46. #define CNeoContainerStreamH    "CNeoContainerStream.h"
  47. #define CNeoStreamH                "CNeoStream.h"
  48. #define CNeoSubclassH            "CNeoSubclass.h"
  49. #define CNeoSwizzlerH            "CNeoSwizzler.h"
  50. #define CNeoTransactionH        "CNeoTransaction.h"
  51. #define NeoFailureH                "NeoFailure.h"
  52.  
  53. #define NeoTime                    time_t
  54.  
  55. #ifdef CallGrowZoneProc
  56. #define qNeoUniversalHeaders    1
  57. #else
  58. #undef qNeoUniversalHeaders
  59. #endif
  60.  
  61. // !@#$ Apple! Make a change but don't tell anybody until it's on our doorstep!
  62. //
  63. // So, Apple has decided that they want to change the DisposHandle (and friends)
  64. // to DisposeHandle in Memory.h. All these jirations below is our attempt to use
  65. // the right symbol given all possible header file combinations.
  66. //
  67. // The logic here is: If qNeoUniversalHeaders is defined, then these are the new
  68. // headers with the changed names. We undef first just in case.
  69. #ifdef qNeoUniversalHeaders
  70. #undef DisposPtr
  71. #undef DisposHandle
  72. #undef ReallocHandle
  73.  
  74. #define DisposPtr(p) DisposePtr(p)
  75. #define DisposHandle(h) DisposeHandle(h)
  76. #define ReallocHandle(h, byteCount) ReallocateHandle(h, byteCount)
  77. #endif
  78.  
  79. #define qNeoMacintosh             1
  80.  
  81. #define NeoIOParams                ParamBlockRec
  82.  
  83. enum {kNeoCacheSize                = 0x80000};
  84.  
  85. const unsigned char kNeoLeafMask =  0x80;        // Mask for determining if node is a leaf
  86.  
  87. #define Neo4CharConst(p1, p2)    ((((unsigned long)(p1))<<16) | ((unsigned short)(p2)))
  88.  
  89. #define NeoSize                    Size
  90.  
  91. typedef SignedByte                NeoPerms;
  92.  
  93. #define NeoStreamRefNum            short
  94. #define NeoFileSpec                FSSpec
  95. #define NeoReadPerm                fsRdPerm
  96. #define NeoWritePerm            fsWrPerm
  97. #define NeoReadWritePerm        fsRdWrPerm
  98. #define NeoReadWriteSharedPerm    fsRdPerm
  99.  
  100. // Macros for dealing with files
  101. #define NeoGetFileName(n)        (n) = (unsigned char *)fFileSpec.name
  102. #define NeoGetFilePath(n)        (n) = (unsigned char *)fFileSpec.name
  103. #define NeoCreateFile(c, t)        FailOSErr(FSpCreate(&fFileSpec, (c), (t), smCurrentScript))
  104. #define NeoDeleteFile()            FSpDelete(&fFileSpec)
  105. #define NeoOpenFile(p)            FailOSErr(FSpOpenDF(&fFileSpec, (p), &fRefNum))
  106. #define NeoCloseFile()            FailOSErr(FSClose(fRefNum)); fRefNum = 0
  107. #define NeoGetFileLength(l)        FailOSErr(GetEOF(fRefNum, &(l)))
  108. #define NeoSetFileLength(l)        FailOSErr(SetEOF(fRefNum, (l)))
  109. #define NeoGetFileMark(m)        FailOSErr(GetFPos(fRefNum, &(m)))
  110. #define NeoSetFileMark(m)        FailOSErr(SetFPos(fRefNum, fsFromStart, (m)))
  111. #define NeoReadFile(b, l)        FailOSErr(FSRead(fRefNum, &(l), (b)))
  112. #define NeoWriteFile(b, l)        FailOSErr(FSWrite(fRefNum, &(l), (b)))
  113. #define NeoGetFileSpecName(n)    NeoStringCopy(fFileSpec.name, (unsigned char *)(n))
  114. #define NeoGetFileSpecPath(p)    NeoStringCopy(fFileSpec.name, (unsigned char *)(p))
  115. #define NeoSetFileSpecPath(p)    NeoStringCopy((unsigned char *)(p), fFileSpec.name)
  116. #define NeoFileExists(b)        {    \
  117.                                     FInfo    fileInfo;    \
  118.                                     b = (::HGetFInfo(fFileSpec.vRefNum, fFileSpec.parID, fFileSpec.name,  &fileInfo) == kNeoNoErr); \
  119.                                 }
  120. #define NeoFlushFile()            if (fRefNum) { \
  121.                                     IOParam    pb; \
  122.                                     pb.ioCompletion = nil; \
  123.                                     pb.ioRefNum = fRefNum; \
  124.                                     FailOSErr(PBFlushFile((ParmBlkPtr)&pb, FALSE)); \
  125.                                 }
  126. #define NeoCompareFileSpec(s1, s2) \
  127.                                 ((s1).vRefNum == (s2).vRefNum && \
  128.                                  (s1).parID == (s2).parID && \
  129.                                  IUEqualPString((s1).name, (s2).name, nil) == 0) \
  130.  
  131. #define NeoSwapShort(x)
  132. #define NeoSwapShortInto(s, d) ((* (short *) (&(d)) = (* (short *) (&(s)))))
  133. #define NeoSwapLong(x)
  134. #define NeoSwapLongInto(s, d)  ((* (long *) (&(d)) = (* (long *) (&(s)))))
  135.  
  136. #define kNeoNullName            "\p"
  137.  
  138. #define NeoBlob                    void **
  139. #define NeoBlobGetPtr(b)        ((Ptr)*(b))
  140. #define NeoBlobMalloc(n)        ((NeoBlob)NewHandle(n))
  141. #define NeoBlobFree(p)            DisposHandle((Handle)(p))
  142. #define NeoBlobGetSize(x)        GetHandleSize((Handle)(x))
  143.  
  144. #ifdef qNeoUniversalHeaders
  145. // #include <TextUtils.h>
  146. #endif
  147.  
  148. #include                        "NeoMacMetro.h"
  149.  
  150. #include                        <AppleEvents.h>
  151. #include                        <AERegistry.h>
  152.  
  153. const NeoTag kNeoBooleanType        = typeBoolean;
  154. const NeoTag kNeoDoubleType            = 'dbl ';            // really should be typeLongFloat
  155. const NeoTag kNeoFloatType            = typeFloat;
  156. const NeoTag kNeoLongType            = typeLongInteger;
  157. const NeoTag kNeoLongDoubleType        = typeExtended;
  158. const NeoTag kNeoNativeStringType    = typeChar;
  159. const NeoTag kNeoShortType            = typeShortInteger;
  160. const NeoTag kNeoStringType            = 'text';            // really should be type Char
  161.  
  162. #define pNeoID                    pID
  163. #define pNeoClassID                Neo4CharConst('pc', 'ID')
  164. #define pNeoName                pName
  165. #define pNeoParentID            Neo4CharConst('pp', 'ar')
  166. #define pNeoMark                Neo4CharConst('ma', 'rk')
  167. #define pNeoLength                Neo4CharConst('pl', 'en')
  168.  
  169. #ifdef qNeoPowerPC
  170. #define    BreakStrToSourceDebugger_(s)    DebugStr(s)
  171. #else
  172. #define    BreakStrToSourceDebugger_(s)    SysBreakStr(s)
  173. #endif
  174.  
  175. // Macros for making debugging assertions
  176. #ifdef qNeoDebug
  177. #if defined(qNeoPowerPC) || defined(__SC__)    // PowerPC and THINK Debugger both like DebugStr
  178. #define    NeoDebugStr(s)            DebugStr((ConstStr255Param)(s))
  179. #else
  180. #define    NeoDebugStr(s)            SysBreakStr((ConstStr255Param)(s))
  181. #endif
  182. #define NeoAssert(condition)    (condition) ? 0 : (NeoDebugStr("\pAssertion Failed!"), 0)
  183. #else
  184. #define NeoDebugStr(s)
  185. #define NeoAssert(condition)
  186. #endif
  187.  
  188. // Macro for getting the # of seconds since 1/1/1970 00:00:00
  189. #define NeoGetCurrentTime()        (time(nil) - 0x7C321500)
  190.  
  191. // Macros for dealing with pointer-based blocks
  192. #define NeoNewPtr(n)            NewPtr((Size)(n))
  193. #define NeoFreePtr(x)            DisposePtr((Ptr)(x))
  194. #define NeoBlockMove(s, d, l)    BlockMove((s), (d), (l))
  195. #define NeoStringCopy(s, d)        NeoBlockMove((s), (d), (s)[0] +1)
  196.  
  197. // Macros for dealing with handle-based blocks
  198. #define NeoNewHandle(x)            NewHandle((Size)(x))
  199. #define NeoFreeHandle(x)        DisposHandle((Handle)(x))
  200. #define NeoResizeHandle(x, l)    SetHandleSize((Handle)(x), (l))
  201.  
  202. // Routines that deal with blocks of the default type
  203. #define kNeoNoErr                noErr
  204. #define kNeoMemFull                memFullErr
  205. #define kNeoNotFound            resNotFound
  206. #define kNeoUnknownType            invalidTranslationPathErr
  207.  
  208. #define NeoFree(p)                DisposePtr((Ptr)(p))
  209. #define NeoMalloc(n)            ((void *)NewPtr((Size)(n)))
  210. #define NeoRealloc(p, l)        SetPtrSize((Ptr)(p), (Size)(l))
  211. #define NeoGetSize(x)            GetPtrSize((Ptr)(x))
  212.  
  213. #if USES68KINLINES
  214. #pragma parameter __D0 NeoGetA0
  215. extern pascal long NeoGetA0(void)    ONEWORDINLINE(0x2008);
  216.  
  217. #pragma parameter __D0 NeoGetA1
  218. extern pascal long NeoGetA1(void)    ONEWORDINLINE(0x2009);
  219.  
  220. #pragma parameter NeoSetD0(__D1)
  221. extern pascal void NeoSetD0(long aD0)    ONEWORDINLINE(0x2049);
  222. #endif
  223.  
  224. #define NeoNewInherit
  225. #define NeoDeleteInherit
  226.  
  227. class CNeoString {
  228. public:
  229.                         CNeoString(void);
  230.                         CNeoString(const unsigned char *aSrc);
  231.                         operator char *(void) const;
  232.                         operator unsigned char *(void) const;
  233.     unsigned char        operator[](const int aIndex) const;
  234.     unsigned char &        operator[](const int aIndex);
  235.     CNeoString &        operator=(const CNeoString &aSrc);
  236.     int                    operator>(const CNeoString &aOther) const;
  237.     int                    operator>=(const CNeoString &aOther) const;
  238.     int                    operator<(const CNeoString &aOther) const;
  239.     int                    operator<=(const CNeoString &aOther) const;
  240.     int                    operator==(const CNeoString &aOther) const;
  241.     short                getLength(void) const;
  242.  
  243. protected:
  244.     unsigned char        fString[128];
  245. };
  246.  
  247. #ifndef qNeoDebug
  248. inline CNeoString::CNeoString(void)
  249. {
  250.     fString[0] = 0;
  251. }
  252.  
  253. inline CNeoString::CNeoString(const unsigned char *aSrc)
  254. {
  255.     unsigned char    length    = (aSrc)[0] +1;
  256.  
  257.     NeoBlockMove((aSrc), fString, length);
  258.     fString[length] = 0;
  259. }
  260.  
  261. inline CNeoString::operator char *(void) const
  262. {
  263.     return (char *)&fString[1];
  264. }
  265.  
  266. inline CNeoString::operator unsigned char *(void) const
  267. {
  268.     return (unsigned char *)&fString[0];
  269. }
  270.  
  271. inline unsigned char CNeoString::operator[](const int aIndex) const
  272. {
  273.     return fString[aIndex];
  274. }
  275.  
  276. inline unsigned char & CNeoString::operator[](const int aIndex)
  277. {
  278.     return fString[aIndex];
  279. }
  280.  
  281. inline CNeoString & CNeoString::operator=(const CNeoString &aSrc)
  282. {
  283.     unsigned char    length    = (aSrc)[0] +1;
  284.  
  285.     NeoBlockMove((unsigned char *)(aSrc), fString, length);
  286.     fString[length] = 0;
  287.  
  288.     return *this;
  289. }
  290.  
  291. inline int CNeoString::operator>(const CNeoString &aOther) const
  292. {
  293.     return (IUCompString(fString, aOther.fString) == 1);
  294. }
  295.  
  296. inline int CNeoString::operator>=(const CNeoString &aOther) const
  297. {
  298.     return (IUCompString(fString, aOther.fString) != -1);
  299. }
  300.  
  301. inline int CNeoString::operator<(const CNeoString &aOther) const
  302. {
  303.     return (IUCompString(fString, aOther.fString) == -1);
  304. }
  305.  
  306. inline int CNeoString::operator<=(const CNeoString &aOther) const
  307. {
  308.     return (IUCompString(fString, aOther.fString) != 1);
  309. }
  310.  
  311. inline int CNeoString::operator==(const CNeoString &aOther) const
  312. {
  313.     return (IUCompString(fString, aOther.fString) == 0);
  314. }
  315.  
  316. inline short CNeoString::getLength(void) const
  317. {
  318.     return (short)(fString)[0];
  319. }
  320.  
  321. #endif
  322.  
  323. extern Boolean NeoAsk(Str255 aComplaint, Str255 aQuestion);
  324. #define NeoAskID                501
  325. #define NeoCancelID                2
  326.  
  327. // NeoAccess class names
  328. #define kNeoPersistName             "\pCNeoPersist"
  329. #define kNeoClassName            "\pCNeoClass"
  330. #define kNeoSubclassName        "\pCNeoSubclass"
  331. #define kNeoFreeListName        "\pCNeoFreeList"
  332. #define kNeoInodeName            "\pCNeoInode"
  333. #define kNeoIDIndexName            "\pCNeoIDIndex"
  334. #define kNeoIDListName            "\pCNeoIDList"
  335. #define kNeoParentIndexName        "\pCNeoParentIndex"
  336. #define kNeoPartMgrName            "\pCNeoPartMgr"
  337.  
  338. #endif
  339.