PageRenderTime 26ms CodeModel.GetById 17ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/components/jcf2/Settings/SetPreProcessor.pas

http://github.com/graemeg/lazarus
Pascal | 153 lines | 85 code | 36 blank | 32 comment | 2 complexity | fdffcdf441659b9291380c330c0fcc90 MD5 | raw file
  1unit SetPreProcessor;
  2
  3{(*}
  4(*------------------------------------------------------------------------------
  5 Delphi Code formatter source code 
  6
  7The Original Code is SetPreprocessor, released 2003
  8The Initial Developer of the Original Code is Anthony Steele.
  9Portions created by Anthony Steele are Copyright (C) 2003-2008 Anthony Steele.
 10All Rights Reserved. 
 11Contributor(s): Anthony Steele. 
 12
 13The contents of this file are subject to the Mozilla Public License Version 1.1
 14(the "License"). you may not use this file except in compliance with the License.
 15You may obtain a copy of the License at http://www.mozilla.org/NPL/
 16
 17Software distributed under the License is distributed on an "AS IS" basis,
 18WITHOUT WARRANTY OF ANY KIND, either express or implied.
 19See the License for the specific language governing rights and limitations 
 20under the License.
 21
 22Alternatively, the contents of this file may be used under the terms of
 23the GNU General Public License Version 2 or later (the "GPL") 
 24See http://www.gnu.org/licenses/gpl.html
 25------------------------------------------------------------------------------*)
 26{*)}
 27
 28{$I JcfGlobal.inc}
 29
 30interface
 31
 32{ settings for preprocessor
 33}
 34
 35uses
 36  { delphi }
 37  Classes,
 38  { local }
 39  JcfSetBase, SettingsStream;
 40
 41type
 42  TSetPreProcessor = class(TSetBase)
 43  private
 44    fbEnabled: boolean;
 45    fcDefinedSymbols: TStringList;
 46    fcDefinedOptions: TStringList;
 47
 48    procedure AddDefaultSymbols;
 49    procedure AddDefaultOptions;
 50  public
 51    constructor Create;
 52    destructor Destroy; override;
 53
 54    procedure WriteToStream(const pcOut: TSettingsOutput); override;
 55    procedure ReadFromStream(const pcStream: TSettingsInput); override;
 56
 57    property Enabled: boolean Read fbEnabled Write fbEnabled;
 58
 59    function OptionIsDefined(const psOption: string): boolean;
 60    function SymbolIsDefined(const psSymbol: string): boolean;
 61
 62    property DefinedSymbols: TStringList Read fcDefinedSymbols Write fcDefinedSymbols;
 63    property DefinedOptions: TStringList Read fcDefinedOptions Write fcDefinedOptions;
 64
 65  end;
 66
 67implementation
 68
 69uses SysUtils;
 70
 71const
 72  REG_ENABLED = 'Enabled';
 73  REG_DEFINED_SYMBOLS = 'DefinedSymbols';
 74  REG_DEFINED_OPTIONS = 'DefinedOptions';
 75
 76{ TSetPreProcessor }
 77
 78constructor TSetPreProcessor.Create;
 79begin
 80  inherited;
 81  SetSection('PreProcessor');
 82
 83  fcDefinedSymbols := TStringList.Create;
 84  //fcDefinedSymbols.Sorted := True;
 85  fcDefinedSymbols.Duplicates := dupIgnore;
 86
 87  fcDefinedOptions := TStringList.Create;
 88  //fcDefinedOptions.Sorted := True;
 89  fcDefinedOptions.Duplicates := dupIgnore;
 90end;
 91
 92destructor TSetPreProcessor.Destroy;
 93begin
 94  FreeAndNil(fcDefinedSymbols);
 95  FreeAndNil(fcDefinedOptions);
 96  inherited;
 97end;
 98
 99procedure TSetPreProcessor.AddDefaultSymbols;
100begin
101  fcDefinedSymbols.Add('MSWINDOWS');
102  fcDefinedSymbols.Add('WIN32');
103  fcDefinedSymbols.Add('DELPHI5_UP');
104end;
105
106procedure TSetPreProcessor.AddDefaultOptions;
107begin
108
109end;
110
111procedure TSetPreProcessor.ReadFromStream(const pcStream: TSettingsInput);
112begin
113  Assert(pcStream <> nil);
114
115  fbEnabled := pcStream.Read(REG_ENABLED, True);
116
117  fcDefinedSymbols.Sorted := False;
118  if not pcStream.Read(REG_DEFINED_SYMBOLS, fcDefinedSymbols) then
119    AddDefaultSymbols;
120
121  fcDefinedSymbols.Sort;
122  fcDefinedSymbols.Sorted := True;
123
124
125  fcDefinedOptions.Sorted := False;
126  if not pcStream.Read(REG_DEFINED_OPTIONS, fcDefinedOptions) then
127    AddDefaultOptions;
128
129  fcDefinedOptions.Sort;
130  fcDefinedOptions.Sorted := True;
131end;
132
133procedure TSetPreProcessor.WriteToStream(const pcOut: TSettingsOutput);
134begin
135  Assert(pcOut <> nil);
136
137  pcOut.Write(REG_ENABLED, fbEnabled);
138  pcOut.Write(REG_DEFINED_SYMBOLS, fcDefinedSymbols);
139  pcOut.Write(REG_DEFINED_OPTIONS, fcDefinedOptions);
140
141end;
142
143function TSetPreProcessor.OptionIsDefined(const psOption: string): boolean;
144begin
145  Result := fcDefinedOptions.IndexOf(psOption) >= 0;
146end;
147
148function TSetPreProcessor.SymbolIsDefined(const psSymbol: string): boolean;
149begin
150  Result := fcDefinedSymbols.IndexOf(psSymbol) >= 0;
151end;
152
153end.