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

📄 ugenerate.pas

📁 DelphiDoc is a program for automatic generation of documentation on a Delphi-Project. At the momen
💻 PAS
📖 第 1 页 / 共 4 页
字号:
function TGeneratorManager.GetProgress: IProgressInterface;
begin
 Result := FGenerator.Progress;
end;

{Access method to set the interface to show the progress.
~param Value the new object to show the progress }
procedure TGeneratorManager.SetProgress(const Value: IProgressInterface);
begin
 FGenerator.Progress:= Value;
end;








{Access method to get the path to generate the documentaton to.
~result the path of the documentation }
function TGeneratorManager.GetDestPath: String;
begin
 Result := FGenerator.DestPath;
end;

{Access method to set the path to generate the documentaton to.
~param Value the new path of the documentation }
procedure TGeneratorManager.SetDestPath(const Value: String);
begin
 FGenerator.DestPath := Value;
end;

{Access method to get the name/title of the project to include in the
 documentation.
~result the name of the project }
function TGeneratorManager.GetProjectName: String;
begin
 Result := FGenerator.ProjectName;
end;

{Access method to set the name/title of the project to include in the
 documentation.
~param Value the new name of the project }
procedure TGeneratorManager.SetProjectName(const Value: String);
begin
 FGenerator.ProjectName := Value;
end;

{Access method to get the name of the file to generate.
~result the name of the file to generate }
function TGeneratorManager.GetFileName: String;
var      Index            :Cardinal;     //index of the option of the file name
begin                                      //generator generates a main file?
 if FGenerator.GetOptions.GetOptionIndex(OptionNameFileName, otString,
                                         Index) then
  Result := FGenerator.GetOption(Index).StrData    //return its name
 else
  raise Exception.Create('Generator does not support option "FileName"!');
end;

{Access method to set the name of the file to generate.
~param Value the new name of the file to generate }
procedure TGeneratorManager.SetFileName(const Value: String);
var       Index            :Cardinal;    //index of the option of the file name
          OptValue         :TOptionValue;  //to set the option of the file name
begin                                      //generator generates a main file?
 if FGenerator.GetOptions.GetOptionIndex(OptionNameFileName, otString,
                                         Index) then
  begin
   OptValue.StrData := Value;
   FGenerator.SetOption(Index, OptValue);    //set its name
  end
 else
  raise Exception.Create('Generator does not support option "FileName"!');
end;


{Access method to get whether the special characters inside comments are set
 for compatibility with Javadoc.
~result whether compatibility with Javadoc is enabled }
function TGeneratorManager.GetUseJavadocCompatibilityCharacters: TYesNoMaybe;
var      Wrapper          :TOptionWrapper;   //the encapsulating wrapper
         Res              :TYesNoMaybe;      //result of the function

 {Checks the option whether it is compatible.
 ~param OptionName the name of the option to be checked
 ~param Yes        the value it has in case it is compatible
 ~param No         the value it has in case it has the default value
 ~result whether the resulting state is not maybe }
 function CheckOption(const OptionName: String; Yes, No: Char): Boolean;
 var      Index      :Cardinal;         //index of option
          Value      :String;           //the value of the option
 begin
  if Wrapper.GetOptionIndex(OptionName, otString, Index) then
   begin
    Value := Wrapper.Option[Index].StrData;  //get the special character
    if Length(Value) <> 1 then
     raise Exception.Create('Option does not contain a single (special) character!');

    if Value[1] = Yes then                   //is compatible with Javadoc?
     begin
      if Res <> ynmYes then                    //was not previously?
       Res := ynmMaybe                           //it's not compatible with any
     end
    else
     if Value[1] = No then                   //is compatible with DelphiDoc?
      begin
       if Res <> ynmNo then                    //was not previously?
        Res := ynmMaybe                          //it's not compatible with any
      end
     else
      Res := ynmMaybe                          //not  compatible with any
   end;
  Result := Res <> ynmMaybe;                 //still compatible with one?
 end;

var      Index            :Cardinal;         //index of option
         Value            :String;           //the value of the option
begin
 //wrap the wrappers of all options of the different objects
 Wrapper := TCollectionOptionWrapper.Create(AllOptions);
 try
   if not GeneratorUsesCommentExtractors or //generator does not use comments?
      //or extractor has no special character?
      not Wrapper.GetOptionIndex(OptionNameSectionSeparator,
                                 otString, Index) then
    raise Exception.Create('Generator does not use the comments or no special character available!');
   Value := Wrapper.Option[Index].StrData;         //get the special character
   if Length(Value) <> 1 then
    raise Exception.Create('Option does not contain a single (special) character!');

   case Value[1] of                                //check character
     '@': Res := ynmYes;
     DefaultSectionSeparatorChar: Res := ynmNo;
   else
    Res := ynmMaybe;
   end;

   if (Res <> ynmMaybe) and                        //check the other options
      CheckOption(OptionNameCommandChar, '@', DefaultSectionSeparatorChar) and
      CheckOption(OptionNameInlineCommandStartChar, '(',
                  DefaultInlineCommandStart) then
    CheckOption(OptionNameInlineCommandEndChar, ')', DefaultInlineCommandEnd);

 finally
  Wrapper.Free;                                    //free the wrapper
 end;
 Result := Res;
end;

{Access method to set whether the special characters inside comments are set
 for compatibility with Javadoc.
~param Value whether compatibility with Javadoc should be enabled or disabled }
procedure TGeneratorManager.SetUseJavadocCompatibilityCharacters(Value:
                                                                  TYesNoMaybe);
var       Wrapper          :TOptionWrapper;      //the encapsulating wrapper
          OptValue         :TOptionValue;        //to set the options

 {Sets the option to the specified value to be compatible either with Javadoc
  or the default JADD setting.
 ~param OptionName the name of the option to be set
 ~param Yes        the value it should be if it is compatible
 ~param No         the value it should be if it has the default value
 ~result whether the resulting state is not maybe }
 procedure SetOption(const OptionName: String; Yes, No: Char);
 var       Index    :Cardinal;              //index of the option
 begin
  if Wrapper.GetOptionIndex(OptionName, otString, Index) then //has the option?
   begin
    if Value = ynmYes then                    //set value of the option
     OptValue.StrData := Yes
    else
     OptValue.StrData := No;
    Wrapper.Option[Index] := OptValue;        //and set the option
   end;
 end;

var       Index            :Cardinal;            //index of the option
begin
 if Value <> ynmMaybe then                       //compatibility available?
  begin
   //wrap the wrappers of all options of the different objects
   Wrapper := TCollectionOptionWrapper.Create(AllOptions);
   try
     if not GeneratorUsesCommentExtractors or //generator does not use comments
        //or extractor has no special character?
        not Wrapper.GetOptionIndex(OptionNameSectionSeparator,
                                   otString, Index) then
      raise Exception.Create('Generator does not use the comments or no special character available!');

     if Value = ynmYes then                        //set main option
      OptValue.StrData := '@'
     else
      OptValue.StrData := DefaultSectionSeparatorChar;
     Wrapper.Option[Index] := OptValue;
                                                   //set other options
     SetOption(OptionNameCommandChar, '@', DefaultSectionSeparatorChar);
     SetOption(OptionNameInlineCommandStartChar, '(',
                                                 DefaultInlineCommandStart);
     SetOption(OptionNameInlineCommandEndChar, ')', DefaultInlineCommandEnd);
   finally
    Wrapper.Free;                                  //free the wrapper
   end;
 end;
end;














{Returns the highest common class of the objects.
~param Obj1, Obj2 the objects for which the highest common class should be
                  found
~param BaseClass  the lowest common class of the objects
~result the highest common class of the objects }
function TGeneratorManager.GetCommonClass(Obj1, Obj2: TObject;
                                          BaseClass: TClass): TClass;
var       Class2          :TClass;           //the class or ancestor of Obj2
begin
 Result := Obj1.ClassType;                   //get the classes
 Class2 := Obj2.ClassType;
 assert(assigned(Result));
 assert(assigned(Class2));

 //while common class not found
 while (Result <> BaseClass) and (Result <> Class2) do
  begin
   assert(assigned(Result));

   Class2 := Obj2.ClassType;                   //start with highest class
   //run through ancestor list until a common class found or base class reached
   while (Class2 <> BaseClass) and (Class2 <> Result) do
    Class2 := Class2.ClassParent;

   if Result <> Class2 then                    //no common class found?
    Result := Result.ClassParent;                //try the parent class
  end;
 assert(assigned(Result));
 assert((Result = BaseClass) or (Result = Class2));
 assert(Result.InheritsFrom(BaseClass));
end;

{Assigns the options, that are common between it and the generator, of the
 other generator to the generator.
~param Other the other generator whose options should be assigned to the
             generator }
procedure TGeneratorManager.AssignGeneratorOptions(Other: TMakeDoc);
var       i        :Cardinal;          //counter through the common options
begin
 //assign all common options
 for i := 0 to TMakeDocClass(GetCommonClass(FGenerator, Other,
                                            TMakeDoc)).GetOptionCount - 1 do
  FGenerator.SetOption(i, Other.GetOption(i));
end;

{Assigns the options, that are common between it and the extractor, of the
 other extractor to the extractor of comments.
~param Other the other extractor whose options should be assigned to the
            extractor }
procedure TGeneratorManager.AssignExtractorOptions(Other: TCommentExtractor);
var       i        :Cardinal;              //counter through the common options
begin
 //assign all common options
 for i := 0 to TCommentExtractorClass(
                       GetCommonClass(FGenerator.Extractor, Other,
                                      TCommentExtractor)).GetOptionCount - 1 do
  FGenerator.Extractor.SetOption(i, Other.GetOption(i));
end;

{Assigns the options, that are common between it and the evaluator, of the
 other evaluator to the evaluator.
~param Other the other evaluator whose options should be assigned to the
             evaluator }
procedure TGeneratorManager.AssignEvaluatorOptions(Other: TCommentEvaluator);
var       i        :Cardinal;              //counter through the common options
begin
 //assign all common options
 for i := 0 to TCommentEvaluatorClass(
                       GetCommonClass(TCommentDoc(FGenerator).Evaluator, Other,
                                      TCommentEvaluator)).GetOptionCount - 1 do
  TCommentDoc(FGenerator).Evaluator.SetOption(i, Other.GetOption(i));
end;




























{Changes the generator to be used to generate the documentation.
~param Identification the identification of the class of generators to use;
                      if not found, it's searched as the name of the class
~result whether the specified generator class has been found }
function TGeneratorManager.ChangeGeneratorByName(const Identification:
                                                              String): Boolean;
var      i                :Integer;    //index of class of the new generator
         OldGen           :TMakeDoc;   //old generator of the documentation
begin
 //try to find the generator by the identification
 i := GeneratorClasses.Count - 1;
 while (i >= 0) and
       (CompareText(TMakeDocClass(GeneratorClasses.Objects[i]).GetDescription.
                                                                Identification,
                    Identification) <> 0) do
  Dec(i);

 //if not found, fall back to name of class
 if i = -1 then
  i := GeneratorClasses.IndexOf(Identification);

 if (i <> -1) and                       //valid and different class given?
    (not Assigned(FGenerator) or
     (TMakeDocClass(GeneratorClasses.Objects[i]) <> FGenerator.ClassType)) then
  begin
   OldGen := FGenerator;                  //unlink the old generator

⌨️ 快捷键说明

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