⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usavedatadoc.pas

📁 DelphiDoc is a program for automatic generation of documentation on a Delphi-Project. At the momen
💻 PAS
字号:
{  JADD - Just Another DelphiDoc: Documentation from Delphi Source Code

Copyright (C) 2005-2008   Gerold Veith

This file is part of JADD - Just Another DelphiDoc.

DelphiDoc is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License version 3 as
published by the Free Software Foundation.

DelphiDoc is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
}


unit USaveDataDoc;

{Contains the generator-class ~[link TSaveDataDoc] to save the parsed data to a
 file. }

interface

uses UOptions, UMakeDoc;



const DDDFileExtension = '.ddd';   //default extension of files of parsed data
      //default name of the file to save the parsed data to
      DefaultDDDFileName = 'DelphiDoc' + DDDFileExtension;


type

   { * * *  ***  * * *  ***   TSaveDataDoc   ***  * * *  ***  * * *  }

  {Extends its base class to save the parsed data to a file.~[br]
   The parsed data can be loaded again, for instance to create other
   documentation about it or compare it with the current source code. }
  TSaveDataDoc = class(TMakeDoc)
  private
    //the name of the file to save the parsed data to
    FFileName: String;
  protected
    //Process parsed data; extract the source code into files.
    function DoGenerateDocumentation: Boolean; override;
  public

    //Returns a description of the documentation of the generator.
    class function GetDescription: TGeneratorDescription; override;


    //Returns the number of available options in this class.
    class function GetOptionCount: Cardinal; override;
    //Gets a description of an option.
    class procedure GetOptionDescription(Index: Cardinal;
                                         var Desc: TOptionDescription);
                                                                      override;
    //Gets the value of an option.
    function GetOption(Index: Cardinal): TOptionValue; override;
    //Sets the value of an option.
    procedure SetOption(Index: Cardinal; const Value: TOptionValue); override;
  end;



implementation

uses Classes, SysUtils,
     General,
     USaveParsed;




   { * * *  ***  * * *  ***   TSaveDataDoc   ***  * * *  ***  * * *  }


{Returns a description of the documentation of the generator.
~result a description of the documentation of the generator }
class function TSaveDataDoc.GetDescription: TGeneratorDescription;
begin
 Result.Name := 'Save Data';
 Result.Identification := 'SavaData';
 Result.Description := 'Saves the parsed data to a file.' + LineDelimiter +
  'The parsed data can be loaded again, for instance to create other documentation about it or compare it with the current source code.';
end;






{Returns the number of available options in this class.
~result the number of available options }
class function TSaveDataDoc.GetOptionCount: Cardinal;
begin
 Result := inherited GetOptionCount + 1;
end;

{Gets a description of an option.
~param Index index of the option to get data of
~param Desc  out: the description of the option (name, type, default value,
                  etc.)
~see GetOptionCount }
class procedure TSaveDataDoc.GetOptionDescription(Index: Cardinal;
                                                 var Desc: TOptionDescription);
var             PreOptionCount :Cardinal;       //number of inherited options
begin
 PreOptionCount := inherited GetOptionCount;    //get number of inherited ones
 if Index < PreOptionCount then                 //asked for inherited option?
  inherited GetOptionDescription(Index, Desc)     //forward to parent class
 else
  begin
   ClearDescription(Desc);               //clear structure
   case Index - PreOptionCount of        //depending on index of option
     0: begin                            //set the values describing the option
         Desc.Name := 'FileName';
         Desc.Category := '';
         Desc.Description := 'The name of the file to save the parsed data to.';
         Desc.DataType := otString;
        end;
   else
    assert(Index >= GetOptionCount);
    raise EInvalidOption.Create('Invalid index for option supplied!');
   end;
 end;
end;



{Gets the value of an option. Call ~[link GetOptionDescription] to get the type
 and the meaning of the option.
~param Index index of the option to get the value of
~result the value of the option }
function TSaveDataDoc.GetOption(Index: Cardinal): TOptionValue;
var      PreOptionCount :Cardinal;              //number of inherited options
begin
 PreOptionCount := inherited GetOptionCount;    //get number of inherited ones
 if Index < PreOptionCount then                 //asked for inherited option?
  Result := inherited GetOption(Index)            //forward to parent class
 else
  begin
   case Index - PreOptionCount of               //depending on index of option
     0: Result.StrData := FFileName;              //get the value
   else
    assert(Index >= GetOptionCount);
    raise EInvalidOption.Create('Invalid index for option supplied!');
   end;
  end;
end;

{Sets the value of an option. Call ~[link GetOptionDescription] to get the type
 and the meaning of the option.
~param Index index of the option to set the value
~param Value the new value of the option }
procedure TSaveDataDoc.SetOption(Index: Cardinal; const Value: TOptionValue);
var       PreOptionCount   :Cardinal;         //number of inherited options
begin
 PreOptionCount := inherited GetOptionCount;  //get number of inherited ones
 if Index < PreOptionCount then               //asked for inherited option?
  inherited SetOption(Index, Value)             //forward to parent class
 else
  case Index - PreOptionCount of                //depending on index of option
    0: FFileName := Value.StrData;                //set the option to the value
  else
   assert(Index >= GetOptionCount);
   raise EInvalidOption.Create('Invalid index for option supplied!');
  end;
end;













{Process parsed data; i.e. in this case save the parsed data to a file.
~result whether the file has been successfully saved and it hasn't been
        aborted }
function TSaveDataDoc.DoGenerateDocumentation: Boolean;
var      FileName    :String;            //the name of the file to save to
begin
 CreateDocumentationDirectory;           //create path of the main directory

 Progress.Reset;
 Progress.SetThrowExceptionOnStepIfAbort(True);

 Progress.SetWorkText('Saving parsed data...');
 Progress.SetProgressText('');
 Progress.SetProcessText('');

 Progress.SetMaximum(1);



 FileName := FFileName;
 if TrimLeft(FileName) = '' then         //no name for the file specified?
  FileName := DefaultDDDFileName;          //use default
 //no extension or at least not the correct one?
 if LowerCase(ExtractFileExt(FileName)) <> DDDFileExtension then
  FileName := FileName + DDDFileExtension; //add the extension



 WriteDataToFile(FDestPath + FileName, FFiles);   //save the parsed data


 Progress.StepProgress;

 Progress.Reset;
 Progress.SetWorkText('Finished writing file!');
 Progress.SetProgressText('Finished!');
 Progress.SetProcessText('');
 Progress.SetMaximum(1);
 Progress.StepProgress;

 Result := True;
end;






initialization
{$IFOPT C+}
 TSaveDataDoc.Create.Destroy;       //generate warning, if class is abstract
{$ENDIF}
 AddGeneratorClass(TSaveDataDoc);   //register generator class

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -