Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
41,991 additions
and 0 deletions.
- +663 −0 ChangeLog
- +204 −0 GpStreamWrapper.pas
- +1,045 −0 GpTextStream.pas
- BIN MSXML2_TLB.dcr
- +9,705 −0 MSXML2_TLB.pas
- +24 −0 OmniXML.inc
- +4,055 −0 OmniXML.pas
- +391 −0 OmniXMLConf.pas
- +572 −0 OmniXMLDatabase.pas
- +768 −0 OmniXMLPersistent.pas
- +1,308 −0 OmniXMLProperties.pas
- +2,796 −0 OmniXMLUtils.pas
- +471 −0 OmniXMLXPath.pas
- +162 −0 OmniXML_Dictionary.pas
- +1,003 −0 OmniXML_JEDI.inc
- +674 −0 OmniXML_LookupTables.pas
- +71 −0 OmniXML_MSXML.pas
- +37 −0 OmniXML_Types.pas
- +173 −0 demo/BioLife/BioLife.bdsproj
- +37 −0 demo/BioLife/BioLife.dpr
- BIN demo/BioLife/BioLife.res
- +165 −0 demo/BioLife/blMain.dfm
- +105 −0 demo/BioLife/blMain.pas
- +173 −0 demo/ErrorInfo/ErrorInfo.bdsproj
- +14 −0 demo/ErrorInfo/ErrorInfo.dpr
- BIN demo/ErrorInfo/ErrorInfo.res
- +112 −0 demo/ErrorInfo/main.dfm
- +212 −0 demo/ErrorInfo/main.pas
- +173 −0 demo/FileList/FileList.bdsproj
- +14 −0 demo/FileList/FileList.dpr
- BIN demo/FileList/FileList.res
- +191 −0 demo/FileList/main.dfm
- +213 −0 demo/FileList/main.pas
- +173 −0 demo/MemTest/MemTest.bdsproj
- +14 −0 demo/MemTest/MemTest.dpr
- BIN demo/MemTest/MemTest.res
- +156 −0 demo/MemTest/main.dfm
- +169 −0 demo/MemTest/main.pas
- +165 −0 demo/MemTest/main.xfm
- +173 −0 demo/Properties/RSSReader.bdsproj
- +14 −0 demo/Properties/RSSReader.dpr
- BIN demo/Properties/RSSReader.res
- +74 −0 demo/Properties/rrMain.dfm
- +104 −0 demo/Properties/rrMain.pas
- +213 −0 demo/Properties/rrRSS.pas
- +81 −0 demo/Properties/summary.xml
- +180 −0 demo/Storage/Storage.bdsproj
- +13 −0 demo/Storage/Storage.dpr
- +111 −0 demo/Storage/Storage.dproj
- BIN demo/Storage/Storage.res
- +139 −0 demo/Storage/main.dfm
- +284 −0 demo/Storage/main.pas
- +173 −0 demo/XPath/XPathDemo.bdsproj
- +14 −0 demo/XPath/XPathDemo.dpr
- BIN demo/XPath/XPathDemo.res
- +147 −0 demo/XPath/XPathDemo1.dfm
- +319 −0 demo/XPath/XPathDemo1.pas
- +173 −0 demo/Xtreme/Xtreme.bdsproj
- +14 −0 demo/Xtreme/Xtreme.dpr
- BIN demo/Xtreme/Xtreme.res
- +110 −0 demo/Xtreme/main.dfm
- +160 −0 demo/Xtreme/main.pas
- BIN demo/doc/animals.xml
- +173 −0 demo/xmlFormatter/xmlFormatter.bdsproj
- +19 −0 demo/xmlFormatter/xmlFormatter.dpr
- BIN demo/xmlFormatter/xmlFormatter.res
- +51 −0 dpk/OmniXMLCore.dpk
- BIN dpk/OmniXMLCore.res
- +173 −0 dpk/OmniXML_d2005.bdsproj
- +48 −0 dpk/OmniXML_d2005.dpk
- BIN dpk/OmniXML_d2005.res
- +44 −0 dpk/OmniXML_d5.dpk
- BIN dpk/OmniXML_d5.res
- +44 −0 dpk/OmniXML_d6.dpk
- BIN dpk/OmniXML_d6.res
- +44 −0 dpk/OmniXML_d7.dpk
- BIN dpk/OmniXML_d7.res
- +12 −0 dpk/define_libsuffix.inc
- +5,631 −0 extras/DSiWin32.pas
- +271 −0 extras/GpSecurity.pas
- +4,256 −0 extras/GpSharedMemory.pas
- +2,352 −0 extras/GpSync.pas
- +168 −0 extras/OmniXMLShared.pas
- +1 −0 extras/readme.txt
@@ -0,0 +1,204 @@ | ||
{ $OmniXML: OmniXML/GpStreamWrapper.pas,v 1.5 2008/06/29 16:50:18 mremec Exp $ } | ||
|
||
{$B-,H+,J+,Q-,T-,X+} | ||
|
||
(*:Some useful stream wrappers. | ||
@author Primoz Gabrijelcic | ||
@desc <pre> | ||
(c) 2006 Primoz Gabrijelcic | ||
Free for personal and commercial use. No rights reserved. | ||
Author : Primoz Gabrijelcic | ||
Creation date : 2001-07-17 | ||
Last modification: 2006-09-21 | ||
Version : 1.04 | ||
</pre> | ||
*)(* | ||
History: | ||
1.04: 2006-09-21 | ||
- TGpStreamWindow class moved to the GpStreams unit. | ||
1.03: 2006-08-31 | ||
- Enable int64-based interface for Delphi 6. | ||
1.02: 2006-04-14 | ||
- Added TGpStreamWindow class. | ||
1.01: 2003-05-16 | ||
- Made Delphi 7 compatible. | ||
1.0: 2001-07-17 | ||
- Released. | ||
*) | ||
|
||
unit GpStreamWrapper; | ||
|
||
{$IFDEF CONDITIONALEXPRESSIONS} | ||
{$IF (RTLVersion >= 14)} // Delphi 6.0 or newer | ||
{$DEFINE D6PLUS} | ||
{$IFEND} | ||
{$ENDIF} | ||
|
||
interface | ||
|
||
uses | ||
Classes; | ||
|
||
type | ||
{:Base stream wrapper class implementing the delayed Seek. | ||
} | ||
TGpStreamWrapper = class(TStream) | ||
private | ||
swDelayedSeek : boolean; | ||
swSeekMode : word; | ||
swSeekOffset : longint; | ||
swStoredPosition: longint; | ||
swStream : TStream; | ||
protected | ||
function GetPosition: {$IFDEF D6PLUS}int64;{$ELSE}longint;{$ENDIF D6PLUS} virtual; | ||
function GetSize: {$IFDEF D6PLUS}int64; override;{$ELSE}longint; virtual;{$ENDIF D6PLUS} | ||
procedure SetPosition(newPosition: {$IFDEF D6PLUS}int64{$ELSE}longint{$ENDIF D6PLUS}); virtual; | ||
procedure SetSize({$IFDEF D6PLUS}const{$ENDIF D6PLUS}newSize: {$IFDEF D6PLUS}int64{$ELSE}longint{$ENDIF D6PLUS}); override; | ||
function WrappedSeek(offset: integer; mode: word): longint; {$IFDEF D6PLUS}overload;{$ENDIF D6PLUS}virtual; | ||
{$IFDEF D6PLUS} | ||
function WrappedSeek(offset: int64; origin: TSeekOrigin): int64; overload; virtual; | ||
{$ENDIF D6PLUS} | ||
public | ||
constructor Create(wrappedStream: TStream); | ||
procedure DelayedSeek; virtual; | ||
function Seek(offset: integer; mode: word): longint; {$IFDEF D6PLUS}overload;{$ENDIF D6PLUS} override; | ||
{:Wrapped (underlying) stream.} | ||
property WrappedStream: TStream read swStream; | ||
end; { TGpStreamWrapper } | ||
|
||
implementation | ||
|
||
{ TGpStreamWrapper } | ||
|
||
constructor TGpStreamWrapper.Create(wrappedStream: TStream); | ||
begin | ||
inherited Create; | ||
swStream := wrappedStream; | ||
end; { TGpStreamWrapper.Create } | ||
|
||
{:Repositions stream pointer in the wrapped stream (if required). Call this | ||
method as a first thing in the descendant Read and Write methods. | ||
} | ||
procedure TGpStreamWrapper.DelayedSeek; | ||
begin | ||
if swDelayedSeek then begin | ||
if (swSeekOffset <> 0) or (swSeekMode <> soFromCurrent) then | ||
WrappedSeek(swSeekOffset,swSeekMode); | ||
swDelayedSeek := false; | ||
end; | ||
end; { TGpStreamWrapper.DelayedSeek } | ||
|
||
{:Returns the position in the wrapping (virtual) stream. Trivial implementation | ||
from this class returns position of the wrapped (underlying) stream. | ||
If descendant overrides this method, it must never call TGpStreamWrapper.Seek | ||
(directly or indirectly). | ||
} | ||
function TGpStreamWrapper.GetPosition: {$IFDEF D6PLUS}int64;{$ELSE}longint;{$ENDIF D6PLUS} | ||
begin | ||
Result := WrappedStream.Position; | ||
end; { TGpStreamWrapper.GetPosition } | ||
|
||
{:Returns the size of the wrapping (virtual) stream. Trivial implementation | ||
from this class returns size of the wrapped (underlying) stream. | ||
If descendant overrides this method, it must never call TGpStreamWrapper.Seek | ||
(directly or indirectly). | ||
} | ||
function TGpStreamWrapper.GetSize: {$IFDEF D6PLUS}int64;{$ELSE}longint;{$ENDIF D6PLUS} | ||
begin | ||
Result := WrappedStream.Size; | ||
end; { TGpStreamWrapper.GetSize } | ||
|
||
{:Repositions stream pointer. Actually only stores this information for later | ||
use (when stream pointer position is really used). | ||
@param offset Offset from start, current position, or end of stream (as set | ||
by the 'mode' parameter) in bytes. | ||
@param mode Specifies starting point for offset calculation | ||
(soFromBeginning, soFromCurrent, soFromEnd). | ||
@returns New position of stream pointer. | ||
} | ||
function TGpStreamWrapper.Seek(offset: longint; mode: word): longint; | ||
begin | ||
// TStream is using following code to get Size of the stream: | ||
// Pos := Seek(0, soFromCurrent); | ||
// Result := Seek(0, soFromEnd); | ||
// Seek(Pos, soFromBeginning); | ||
// This code tries to hack around this stupid behaviour. | ||
if not swDelayedSeek then begin | ||
if (mode = soFromCurrent) and (offset = 0) then begin | ||
// possible GetSize call | ||
swDelayedSeek := true; | ||
swSeekOffset := offset; | ||
swSeekMode := mode; | ||
swStoredPosition := GetPosition; | ||
Result := swStoredPosition; | ||
end | ||
else // not a GetSize call, forward it | ||
Result := WrappedSeek(offset,mode); | ||
end | ||
else begin | ||
if mode = soFromCurrent then | ||
// not a GetSize call; saved Seek can only be (0,fromCurrent) - it is not | ||
// necessary to call DelayedSeek | ||
Result := WrappedSeek(offset,mode) | ||
else if mode = soFromEnd then begin | ||
if swSeekMode = soFromCurrent then begin | ||
// possible GetSize call | ||
swSeekOffset := offset; | ||
swSeekMode := mode; | ||
Result := GetSize; | ||
end | ||
else // not a GetSize call | ||
Result := WrappedSeek(offset,mode); | ||
end | ||
else {if mode = soFromBeginning} begin | ||
if (swSeekMode = soFromEnd) and (swStoredPosition = offset) then begin | ||
// definitely GetSize call | ||
swDelayedSeek := false; | ||
Result := swStoredPosition; | ||
end | ||
else // not a GetSize call | ||
Result := WrappedSeek(offset,mode); | ||
end; | ||
end; | ||
end; { TGpStreamWrapper.Seek } | ||
|
||
{:Sets the position in the wrapping (virtual) stream. Trivial implementation | ||
from this class sets position of the wrapped (underlying) stream. | ||
If descendant overrides this method, it must never call TGpStreamWrapper.Seek | ||
(directly or indirectly). | ||
} | ||
procedure TGpStreamWrapper.SetPosition(newPosition: {$IFDEF D6PLUS}int64{$ELSE}longint{$ENDIF D6PLUS}); | ||
begin | ||
WrappedStream.Position := newPosition; | ||
end; { TGpStreamWrapper.SetPosition } | ||
|
||
{:Sets the size of the wrapping (virtual) stream. Trivial implementation | ||
from this class sets position of the wrapped (underlying) stream. | ||
If descendant overrides this method, it must never call TGpStreamWrapper.Seek | ||
(directly or indirectly). | ||
} | ||
procedure TGpStreamWrapper.SetSize({$IFDEF D6PLUS}const{$ENDIF D6PLUS}newSize: {$IFDEF D6PLUS}int64{$ELSE}longint{$ENDIF D6PLUS}); | ||
begin | ||
WrappedStream.Size := newSize; | ||
end; { TGpStreamWrapper.SetSize } | ||
|
||
{:Implementation of the 'true' Seek. Called only when Seek is really needed. | ||
Trivial implementation from this class calls Seek on the wrapped (underlying) stream. | ||
WrappedSeek must never call TGpStreamWrapper.Seek (directly or indirectly) but use | ||
directly WrappedStream.Seek. | ||
} | ||
function TGpStreamWrapper.WrappedSeek(offset: integer; | ||
mode: word): longint; | ||
begin | ||
Result := WrappedStream.Seek(offset, mode); | ||
end; { TGpStreamWrapper.WrappedSeek } | ||
|
||
{$IFDEF D6PLUS} | ||
function TGpStreamWrapper.WrappedSeek(offset: int64; origin: TSeekOrigin): int64; | ||
begin | ||
Result := WrappedStream.Seek(offset, origin); | ||
end; | ||
{$ENDIF D6PLUS} | ||
|
||
end. |
Oops, something went wrong.