Statistics
| Branch: | Tag: | Revision:

root / MulProvider / URadarProvider.pas @ 119:66352054ce4d

History | View | Annotate | Download (2.7 kB)

1
(*
2
 * CDDL HEADER START
3
 *
4
 * The contents of this file are subject to the terms of the
5
 * Common Development and Distribution License, Version 1.0 only
6
 * (the "License").  You may not use this file except in compliance
7
 * with the License.
8
 *
9
 * You can obtain a copy of the license at
10
 * http://www.opensource.org/licenses/cddl1.php.
11
 * See the License for the specific language governing permissions
12
 * and limitations under the License.
13
 *
14
 * When distributing Covered Code, include this CDDL HEADER in each
15
 * file and include the License file at
16
 * http://www.opensource.org/licenses/cddl1.php.  If applicable,
17
 * add the following below this CDDL HEADER, with the fields enclosed
18
 * by brackets "[]" replaced with your own identifying * information:
19
 *      Portions Copyright [yyyy] [name of copyright owner]
20
 *
21
 * CDDL HEADER END
22
 *
23
 *
24
 *      Portions Copyright 2009 Andreas Schneider
25
 *)
26
unit URadarProvider;
27
28
{$mode objfpc}{$H+}
29
30
interface
31
32
uses
33
  SysUtils, Classes, UBufferedStreams;
34
35
type
36
37
  { TRadarProvider }
38
39
  TRadarProvider = class
40
    constructor Create; overload; virtual;
41
    constructor Create(AData: TStream; AReadOnly: Boolean = False); overload; virtual;
42
    constructor Create(AData: string; AReadOnly: Boolean = False); overload; virtual;
43
    destructor Destroy; override;    
44
  protected
45
    FData: TBufferedReader;
46
    FReadOnly: Boolean;
47
  public
48
    function GetColor(AID: Integer): Word;
49
    procedure SetColor(AID: Integer; AColor: Word);
50
  end;
51
52
implementation
53
54
{ TRaderProvider }
55
56
constructor TRadarProvider.Create;
57
begin
58
  inherited Create;
59
end;
60
61
constructor TRadarProvider.Create(AData: TStream; AReadOnly: Boolean);
62
begin
63
  Create;
64
  FData := TBufferedReader.Create(AData, False);
65
  FReadOnly := AReadOnly;
66
end;
67
68
constructor TRadarProvider.Create(AData: string; AReadOnly: Boolean);
69
var
70
  mode: Word;
71
begin
72
  Create;
73
  if AReadOnly then
74
    mode := fmOpenRead or fmShareDenyWrite
75
  else
76
    mode := fmOpenReadWrite or fmShareDenyWrite;
77
  FData := TBufferedReader.Create(TFileStream.Create(AData, mode), True);
78
  FReadOnly := AReadOnly;
79
end;
80
81
destructor TRadarProvider.Destroy;
82
begin
83
  FreeAndNil(FData);
84
  inherited Destroy;
85
end;
86
87
function TRadarProvider.GetColor(AID: Integer): Word;
88
begin
89
  Result := 0;
90
  if (AID >= 0) and (AID < $10000) then
91
  begin
92
    FData.Position := SizeOf(Word) * AID;
93
    FData.Read(Result, SizeOf(Word));
94
  end;
95
end;
96
97
procedure TRadarProvider.SetColor(AID: Integer; AColor: Word);
98
begin
99
  if (not FReadOnly) and (AID >= 0) and (AID < $10000) then
100
  begin
101
    FData.Position := SizeOf(Word) * AID;
102
    FData.Write(AColor, SizeOf(Word));
103
  end;
104
end;
105
106
end.