home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l044 / 2.ddi / INTRFACE.ZIP / OBJECTS.INT < prev    next >
Encoding:
Text File  |  1990-10-23  |  9.8 KB  |  372 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Turbo Pascal Version 6.0                        }
  5. {       Turbo Pascal Standard Objects Unit              }
  6. {                                                       }
  7. {       Copyright (c) 1990 Borland International        }
  8. {                                                       }
  9. {*******************************************************}
  10.  
  11. unit Objects;
  12.  
  13. {$F+,O+,S-}
  14.  
  15. interface
  16.  
  17. const
  18.  
  19. { TStream access modes }
  20.  
  21.   stCreate    = $3C00;           { Create new file }
  22.   stOpenRead  = $3D00;           { Read access only }
  23.   stOpenWrite = $3D01;           { Write access only }
  24.   stOpen      = $3D02;           { Read and write access }
  25.  
  26. { TStream error codes }
  27.  
  28.   stOk         =  0;              { No error }
  29.   stError      = -1;              { Access error }
  30.   stInitError  = -2;              { Cannot initialize stream }
  31.   stReadError  = -3;              { Read beyond end of stream }
  32.   stWriteError = -4;              { Cannot expand stream }
  33.   stGetError   = -5;              { Get of unregistered object type }
  34.   stPutError   = -6;              { Put of unregistered object type }
  35.  
  36. { Maximum TCollection size }
  37.  
  38.   MaxCollectionSize = 65520 div SizeOf(Pointer);
  39.  
  40. { TCollection error codes }
  41.  
  42.   coIndexError = -1;              { Index out of range }
  43.   coOverflow   = -2;              { Overflow }
  44.  
  45. type
  46.  
  47. { Type conversion records }
  48.  
  49.   WordRec = record
  50.     Lo, Hi: Byte;
  51.   end;
  52.  
  53.   LongRec = record
  54.     Lo, Hi: Word;
  55.   end;
  56.  
  57.   PtrRec = record
  58.     Ofs, Seg: Word;
  59.   end;
  60.  
  61. { String pointers }
  62.  
  63.   PString = ^String;
  64.   PChar = ^Char;
  65.  
  66. { General arrays }
  67.  
  68.   PByteArray = ^TByteArray;
  69.   TByteArray = array[0..32767] of Byte;
  70.  
  71.   PWordArray = ^TWordArray;
  72.   TWordArray = array[0..16383] of Word;
  73.  
  74. { TObject base object }
  75.  
  76.   PObject = ^TObject;
  77.   TObject = object
  78.     constructor Init;
  79.     procedure Free;
  80.     destructor Done; virtual;
  81.   end;
  82.  
  83. { TStreamRec }
  84.  
  85.   PStreamRec = ^TStreamRec;
  86.   TStreamRec = record
  87.     ObjType: Word;
  88.     VmtLink: Word;
  89.     Load: Pointer;
  90.     Store: Pointer;
  91.     Next: Word;
  92.   end;
  93.  
  94. { TStream }
  95.  
  96.   PStream = ^TStream;
  97.   TStream = object(TObject)
  98.     Status: Integer;
  99.     ErrorInfo: Integer;
  100.     procedure CopyFrom(var S: TStream; Count: Longint);
  101.     procedure Error(Code, Info: Integer); virtual;
  102.     procedure Flush; virtual;
  103.     function Get: PObject;
  104.     function GetPos: Longint; virtual;
  105.     function GetSize: Longint; virtual;
  106.     procedure Put(P: PObject);
  107.     procedure Read(var Buf; Count: Word); virtual;
  108.     function ReadStr: PString;
  109.     procedure Reset;
  110.     procedure Seek(Pos: Longint); virtual;
  111.     procedure Truncate; virtual;
  112.     procedure Write(var Buf; Count: Word); virtual;
  113.     procedure WriteStr(P: PString);
  114.   end;
  115.  
  116. { DOS file name string }
  117.  
  118.   FNameStr = string[79];
  119.  
  120. { TDosStream }
  121.  
  122.   PDosStream = ^TDosStream;
  123.   TDosStream = object(TStream)
  124.     Handle: Word;
  125.     constructor Init(FileName: FNameStr; Mode: Word);
  126.     destructor Done; virtual;
  127.     function GetPos: Longint; virtual;
  128.     function GetSize: Longint; virtual;
  129.     procedure Read(var Buf; Count: Word); virtual;
  130.     procedure Seek(Pos: Longint); virtual;
  131.     procedure Truncate; virtual;
  132.     procedure Write(var Buf; Count: Word); virtual;
  133.   end;
  134.  
  135. { TBufStream }
  136.  
  137.   PBufStream = ^TBufStream;
  138.   TBufStream = object(TDosStream)
  139.     Buffer: Pointer;
  140.     BufSize: Word;
  141.     BufPtr: Word;
  142.     BufEnd: Word;
  143.     constructor Init(FileName: FNameStr; Mode, Size: Word);
  144.     destructor Done; virtual;
  145.     procedure Flush; virtual;
  146.     function GetPos: Longint; virtual;
  147.     function GetSize: Longint; virtual;
  148.     procedure Read(var Buf; Count: Word); virtual;
  149.     procedure Seek(Pos: Longint); virtual;
  150.     procedure Truncate; virtual;
  151.     procedure Write(var Buf; Count: Word); virtual;
  152.   end;
  153.  
  154. { TEmsStream }
  155.  
  156.   PEmsStream = ^TEmsStream;
  157.   TEmsStream = object(TStream)
  158.     Handle: Word;
  159.     PageCount: Word;
  160.     Size: Longint;
  161.     Position: Longint;
  162.     constructor Init(MinSize, MaxSize: Longint);
  163.     destructor Done; virtual;
  164.     function GetPos: Longint; virtual;
  165.     function GetSize: Longint; virtual;
  166.     procedure Read(var Buf; Count: Word); virtual;
  167.     procedure Seek(Pos: Longint); virtual;
  168.     procedure Truncate; virtual;
  169.     procedure Write(var Buf; Count: Word); virtual;
  170.   end;
  171.  
  172. { TCollection types }
  173.  
  174.   PItemList = ^TItemList;
  175.   TItemList = array[0..MaxCollectionSize - 1] of Pointer;
  176.  
  177. { TCollection object }
  178.  
  179.   PCollection = ^TCollection;
  180.   TCollection = object(TObject)
  181.     Items: PItemList;
  182.     Count: Integer;
  183.     Limit: Integer;
  184.     Delta: Integer;
  185.     constructor Init(ALimit, ADelta: Integer);
  186.     constructor Load(var S: TStream);
  187.     destructor Done; virtual;
  188.     function At(Index: Integer): Pointer;
  189.     procedure AtDelete(Index: Integer);
  190.     procedure AtFree(Index: Integer);
  191.     procedure AtInsert(Index: Integer; Item: Pointer);
  192.     procedure AtPut(Index: Integer; Item: Pointer);
  193.     procedure Delete(Item: Pointer);
  194.     procedure DeleteAll;
  195.     procedure Error(Code, Info: Integer); virtual;
  196.     function FirstThat(Test: Pointer): Pointer;
  197.     procedure ForEach(Action: Pointer);
  198.     procedure Free(Item: Pointer);
  199.     procedure FreeAll;
  200.     procedure FreeItem(Item: Pointer); virtual;
  201.     function GetItem(var S: TStream): Pointer; virtual;
  202.     function IndexOf(Item: Pointer): Integer; virtual;
  203.     procedure Insert(Item: Pointer); virtual;
  204.     function LastThat(Test: Pointer): Pointer;
  205.     procedure Pack;
  206.     procedure PutItem(var S: TStream; Item: Pointer); virtual;
  207.     procedure SetLimit(ALimit: Integer); virtual;
  208.     procedure Store(var S: TStream);
  209.   end;
  210.  
  211. { TSortedCollection object }
  212.  
  213.   PSortedCollection = ^TSortedCollection;
  214.   TSortedCollection = object(TCollection)
  215.     Duplicates: Boolean;
  216.     constructor Load(var S: TStream);
  217.     function Compare(Key1, Key2: Pointer): Integer; virtual;
  218.     function IndexOf(Item: Pointer): Integer; virtual;
  219.     procedure Insert(Item: Pointer); virtual;
  220.     function KeyOf(Item: Pointer): Pointer; virtual;
  221.     function Search(Key: Pointer; var Index: Integer): Boolean; virtual;
  222.     procedure Store(var S: TStream);
  223.   end;
  224.  
  225. { TStringCollection object }
  226.  
  227.   PStringCollection = ^TStringCollection;
  228.   TStringCollection = object(TSortedCollection)
  229.     function Compare(Key1, Key2: Pointer): Integer; virtual;
  230.     procedure FreeItem(Item: Pointer); virtual;
  231.     function GetItem(var S: TStream): Pointer; virtual;
  232.     procedure PutItem(var S: TStream; Item: Pointer); virtual;
  233.   end;
  234.  
  235. { TResourceCollection object }
  236.  
  237.   PResourceCollection = ^TResourceCollection;
  238.   TResourceCollection = object(TStringCollection)
  239.     procedure FreeItem(Item: Pointer); virtual;
  240.     function GetItem(var S: TStream): Pointer; virtual;
  241.     function KeyOf(Item: Pointer): Pointer; virtual;
  242.     procedure PutItem(var S: TStream; Item: Pointer); virtual;
  243.   end;
  244.  
  245. { TResourceFile object }
  246.  
  247.   PResourceFile = ^TResourceFile;
  248.   TResourceFile = object(TObject)
  249.     Stream: PStream;
  250.     Modified: Boolean;
  251.     constructor Init(AStream: PStream);
  252.     destructor Done; virtual;
  253.     function Count: Integer;
  254.     procedure Delete(Key: String);
  255.     procedure Flush;
  256.     function Get(Key: String): PObject;
  257.     function KeyAt(I: Integer): String;
  258.     procedure Put(Item: PObject; Key: String);
  259.     function SwitchTo(AStream: PStream; Pack: Boolean): PStream;
  260.   end;
  261.  
  262. { TStringList object }
  263.  
  264.   TStrIndexRec = record
  265.     Key, Count, Offset: Word;
  266.   end;
  267.  
  268.   PStrIndex = ^TStrIndex;
  269.   TStrIndex = array[0..9999] of TStrIndexRec;
  270.  
  271.   PStringList = ^TStringList;
  272.   TStringList = object(TObject)
  273.     constructor Load(var S: TStream);
  274.     destructor Done; virtual;
  275.     function Get(Key: Word): String;
  276.   end;
  277.  
  278. { TStrListMaker object }
  279.  
  280.   PStrListMaker = ^TStrListMaker;
  281.   TStrListMaker = object(TObject)
  282.     constructor Init(AStrSize, AIndexSize: Word);
  283.     destructor Done; virtual;
  284.     procedure Put(Key: Word; S: String);
  285.     procedure Store(var S: TStream);
  286.   end;
  287.  
  288. { TPoint object }
  289.  
  290.   TPoint = object
  291.     X, Y: Integer;
  292.   end;
  293.  
  294. { Rectangle object }
  295.  
  296.   TRect = object
  297.     A, B: TPoint;
  298.     procedure Assign(XA, YA, XB, YB: Integer);
  299.     procedure Copy(R: TRect);
  300.     procedure Move(ADX, ADY: Integer);
  301.     procedure Grow(ADX, ADY: Integer);
  302.     procedure Intersect(R: TRect);
  303.     procedure Union(R: TRect);
  304.     function Contains(P: TPoint): Boolean;
  305.     function Equals(R: TRect): Boolean;
  306.     function Empty: Boolean;
  307.   end;
  308.  
  309. { Dynamic string handling routines }
  310.  
  311. function NewStr(S: String): PString;
  312. procedure DisposeStr(P: PString);
  313.  
  314. { Longint routines }
  315.  
  316. function LongMul(X, Y: Integer): Longint;
  317. inline($5A/$58/$F7/$EA);
  318.  
  319. function LongDiv(X: Longint; Y: Integer): Integer;
  320. inline($59/$58/$5A/$F7/$F9);
  321.  
  322. { Stream routines }
  323.  
  324. procedure RegisterType(var S: TStreamRec);
  325.  
  326. { Abstract notification procedure }
  327.  
  328. procedure Abstract;
  329.  
  330. { Objects registration procedure }
  331.  
  332. procedure RegisterObjects;
  333.  
  334. const
  335.  
  336. { Stream error procedure }
  337.  
  338.   StreamError: Pointer = nil;
  339.  
  340. { EMS stream state variables }
  341.  
  342.   EmsCurHandle: Word = $FFFF;
  343.   EmsCurPage: Word = $FFFF;
  344.  
  345. const
  346.  
  347. { Stream registration records }
  348.  
  349.   RCollection: TStreamRec = (
  350.     ObjType: 50;
  351.     VmtLink: Ofs(TypeOf(TCollection)^);
  352.     Load: @TCollection.Load;
  353.     Store: @TCollection.Store);
  354.  
  355.   RStringCollection: TStreamRec = (
  356.     ObjType: 51;
  357.     VmtLink: Ofs(TypeOf(TStringCollection)^);
  358.     Load: @TStringCollection.Load;
  359.     Store: @TStringCollection.Store);
  360.  
  361.   RStringList: TStreamRec = (
  362.     ObjType: 52;
  363.     VmtLink: Ofs(TypeOf(TStringList)^);
  364.     Load: @TStringList.Load;
  365.     Store: nil);
  366.  
  367.   RStrListMaker: TStreamRec = (
  368.     ObjType: 52;
  369.     VmtLink: Ofs(TypeOf(TStrListMaker)^);
  370.     Load: nil;
  371.     Store: @TStrListMaker.Store);
  372.