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

📄 dglintf.inc_h

📁 Delphi Generic Algorytms library - Maps, Lists, Hashmaps, Datastructures.
💻 INC_H
📖 第 1 页 / 共 3 页
字号:
(*
 * DGL(The Delphi Generic Library)
 *
 * Copyright (c) 2004
 * HouSisong@263.net
 *
 * This material is provided "as is", with absolutely no warranty expressed
 * or implied. Any use is at your own risk.
 *
 * Permission to use or copy this software for any purpose is hereby granted
 * without fee, provided the above notices are retained on all copies.
 * Permission to modify the code and to distribute modified code is granted,
 * provided the above notices are retained, and a notice that the code was
 * modified is included with the above copyright notice.
 *
 *)
       
//------------------------------------------------------------------------------
// DGL库中的接口(interface)的声明
// Create by HouSisong, 2004.08.31
//------------------------------------------------------------------------------

//DGLIntf.inc_h ; DGLIntf.inc_pas

{$ifndef  __DGLIntf_inc_h_}
{$define  __DGLIntf_inc_h_}

  {$I DGLCfg.inc_h}   //

  type
    _PValueType      = ^_ValueType;
    _TValueDArray = array of _ValueType;

   //如果_DGL_Compare和_DGL_Compare_Value中有一个没有定义,而另一个定义了,那么使他们等价
  {$ifdef _DGL_Compare}
    {$ifndef _DGL_Compare_Value}
    {$define _DGL_Compare_Value}
      type
        _TIsEqual_Value = function (const a,b: _ValueType):boolean;
        _TIsLess_Value  = function (const a,b: _ValueType):boolean;
      const
        _IsEqual_Value :_TIsEqual_Value  = _IsEqual;
        _IsLess_Value  :_TIsLess_Value   = _IsLess;
    {$endif}
  {$else}
    {$ifdef _DGL_Compare_Value}
      {$define _DGL_Compare}
      type
        _TIsEqual_Value = function (const a,b: _ValueType):boolean;
        _TIsLess_Value  = function (const a,b: _ValueType):boolean;
      const
        _IsEqual       :_TIsEqual_Value  = _IsEqual_Value;
        _IsLess        :_TIsLess_Value   = _IsLess_Value;
    {$endif}
  {$endif}

  //如果_DGL_ObjValue和_DGL_ObjValue_Value中有一个没有定义,而另一个定义了,那么使他们等价
  {$ifdef _DGL_ObjValue}
    {$ifndef _DGL_ObjValue_Value}
    {$define _DGL_ObjValue_Value}
      type
        _TFree_Value           = procedure (Value: _ValueType);
        _TCopyCreateNew_Value  = function  (const Value: _ValueType):_ValueType;
        _TCreateNew_Value      = function  ():_ValueType;
        _TAssign_Value         = procedure (DestValue:_ValueType;const SrcValue: _ValueType);
      const
        _Free_Value          :_TFree_Value           = _Free;
        _CopyCreateNew_Value :_TCopyCreateNew_Value  = _CopyCreateNew;
        _CreateNew_Value     :_TCreateNew_Value      = _CreateNew;
        _Assign_Value        :_TAssign_Value         = _Assign;
    {$endif}
  {$else}
    {$ifdef _DGL_ObjValue_Value}
      {$define _DGL_ObjValue}
      type
        _TFree_Value           = procedure (Value: _ValueType);
        _TCopyCreateNew_Value  = function  (const Value: _ValueType):_ValueType;
        _TCreateNew_Value      = function  ():_ValueType;
        _TAssign_Value         = procedure (DestValue:_ValueType;const SrcValue: _ValueType);
      const
        _Free                :_TFree_Value           = _Free_Value;
        _CopyCreateNew       :_TCopyCreateNew_Value  = _CopyCreateNew_Value;
        _CreateNew           :_TCreateNew_Value      = _CreateNew_Value;
        _Assign              :_TAssign_Value         = _Assign_Value;
    {$endif}
  {$endif}


  {$ifdef __DGL_KeyType_Is_ValueType}
        type
          //预处理使Key和Value完全等价
          _KeyType         = _ValueType;  //_ValueType==_KeyType
          _PKeyType        = _PValueType;
          _TKeyArrayType   = _TValueDArray;


           type
             _TIsEqual_Key_Value = function (const a,b: _ValueType):boolean;
             _TIsLess_Key_Value  = function (const a,b: _ValueType):boolean;
          {$ifdef _DGL_Compare}
            {$define _DGL_Compare_Key}
              const
                _IsEqual_Key   :_TIsEqual_Key_Value  = _IsEqual;
                _IsLess_Key    :_TIsLess_Key_Value   = _IsLess;
          {$else}
            {$ifdef _DGL_Compare_Value}
              {$define _DGL_Compare_Key}
                const
                  _IsEqual_Key   :_TIsEqual_Key_Value  = _IsEqual_Value;
                  _IsLess_Key    :_TIsLess_Key_Value   = _IsLess_Value;
            {$endif}
          {$endif}

          type
            _TFree_Key_Value           = procedure (Key: _KeyType);
            _TCopyCreateNew_Key_Value  = function  (const Key: _KeyType):_KeyType;
            _TCreateNew_Key_Value      = function  ():_KeyType;
            _TAssign_Key_Value         = procedure (DestValue:_ValueType;const SrcValue: _ValueType);
          {$ifdef _DGL_ObjValue}
            {$define _DGL_ObjValue_Key}
              const
                _Free_Key            :_TFree_Key_Value           = _Free;
                _CopyCreateNew_Key   :_TCopyCreateNew_Key_Value  = _CopyCreateNew;
                _CreateNew_Key       :_TCreateNew_Key_Value      = _CreateNew;
                _Assign_Key          :_TAssign_Key_Value         = _Assign;
          {$else}
            {$ifdef _DGL_ObjValue_Value}
              {$define _DGL_ObjValue_Key}
                const
                  _Free_Key            :_TFree_Key_Value           = _Free_Value;
                  _CopyCreateNew_Key   :_TCopyCreateNew_Key_Value  = _CopyCreateNew_Value;
                  _CreateNew_Key       :_TCreateNew_Key_Value      = _CreateNew_Value;
                  _Assign_Key          :_TAssign_Key_Value         = _Assign_Value;
            {$endif}
          {$endif}
  {$endif}

  {$ifndef  _DGL_Compare}
    function _IsEqual(const Value0,Value1:_ValueType):boolean; {$ifdef _DGL_Inline} inline; {$endif} //todo: Warning inline on if _ValueType if "object" then error!!!
    function _IsLess(const Value0,Value1:_ValueType):boolean; {$ifdef _DGL_Inline} inline; {$endif}  //todo: Warning inline on if _ValueType if "object" then error!!!
  {$endif}
  {$ifndef  _DGL_Compare_Value}
    function _IsEqual_Value(const Value0,Value1:_ValueType):boolean; {$ifdef _DGL_Inline} inline; {$endif}  //todo: Warning inline on if _ValueType if "object" then error!!!
    function _IsLess_Value(const Value0,Value1:_ValueType):boolean; {$ifdef _DGL_Inline} inline; {$endif}   //todo: Warning inline on if _ValueType if "object" then error!!!
  {$endif}

type
  TGenerateFunction         = function (): _ValueType;
  TGenerateFunctionOfObject = function (): _ValueType of object;
  TTansfromFunction         = function (const Value: _ValueType): _ValueType;
  TTansfromFunctionOfObject = function (const Value: _ValueType): _ValueType of object;
  TTansfromBinaryFunction         = function (const Value0,Value1: _ValueType): _ValueType;
  TTansfromBinaryFunctionOfObject = function (const Value0,Value1: _ValueType): _ValueType of object;
  TVisitProc         = procedure (const Value: _ValueType);
  TVisitProcOfObject = procedure (const Value: _ValueType) of object;
  TTestFunction         = function (const Value:_ValueType):Boolean;
  TTestFunctionOfObject = function (const Value:_ValueType):Boolean Of Object;
  TTestBinaryFunction         = function (const Value0,Value1:_ValueType):Boolean;
  TTestBinaryFunctionOfObject = function (const Value0,Value1:_ValueType):Boolean Of Object;

  TRandomGenerateFunction         = function (const Range: Integer):integer; //0<=result<Range
  TRandomGenerateFunctionOfObject = function (const Range: Integer):integer Of Object;


type
  TIteratorTraitsType = (_DGL_itTraits0,_DGL_itTraits1,_DGL_itTraits2,
                         _DGL_itTraits3,_DGL_itTraits4);
  TIteratorTraits    = set of TIteratorTraitsType;
const
  itTrivialTag       = [];
  itInputTag         = itTrivialTag + [_DGL_itTraits0];
  itOutputTag        = itTrivialTag + [_DGL_itTraits1];
  itForwardTag       = itInputTag + [_DGL_itTraits2];
  itBidirectionalTag = itForwardTag + [_DGL_itTraits3];
  itRandomAccessTag  = itBidirectionalTag + [_DGL_itTraits4];


type

  //迭代器(iterator)的统一说明
  //----------------------------------------------------------------------------
  // 作用描述: 用来遍历容器里面的元素
  // 主要方法:Value属性:用来读写迭代器引用的值
  //           IsEqual方法:判断两个迭代器是否指向同一个位置
  //           Distance方法: 返回自身位置减去传入的迭代器指向位置的差值
  //           Assign方法:使自身与传入的迭代器指向同一个容器和引用位置
  //           Next方法:指向下一个位置
  //           Previous方法:指向上一个位置
  //           Clone方法:创建一个新的迭代器,与自己指向同一个位置
  //           GetSelfObj方法:返回接口存在的原始对象(self指针),内部使用
  //           Items属性: 根据偏移量快速的访问值(对于随机迭代器才有常数时间)
  // 使用方式:
  // 注意事项: 如果实现了单向链表,则其迭代器不会实现Previous方法,会触发异常
  //           Distance方法在某些迭代器中的实现 时间复杂度可能为O(n);
  // 作    者: HouSisong ,2004.08.31
  // [相关资料]: (如果有的话)
  // [维护记录]: (类发布后,其修改需要记录下来:修改人、时间、主要原因内容)
  //----------------------------------------------------------------------------
  //迭代器分成_IIterator结构和_DGL_TObjIterator类来实现是为了优化用纯接口(+类实现)实现迭代器的创建和销毁的开销
  //实际测试中速度大幅提升!  2005.10.13
          _DGL_TObjIterator = class;
          _DGL_TObjIteratorClass = class of _DGL_TObjIterator;
  _IIterator = object
  private
    _ObjIteratorClass : _DGL_TObjIteratorClass;
    _Data0 : integer;
    _Data1 : integer;
    _Data2 : integer;
    //如果库有需要可以继续扩展
    //_InfData : IInterface;
    //_DataArray : array[0..2] of integer;
  public
    function  IteratorTraits():TIteratorTraits;          {$ifdef _DGL_Inline} inline; {$endif}
    procedure SetIteratorNil();                          {$ifdef _DGL_Inline} inline; {$endif}
    procedure SetValue(const aValue: _ValueType);        {$ifdef _DGL_Inline} inline; {$endif}
    function  GetValue(): _ValueType;                           {$ifdef _DGL_Inline} inline; {$endif}
    function  GetNextValue(const Step:integer): _ValueType;     {$ifdef _DGL_Inline} inline; {$endif}
    procedure SetNextValue(const Step:integer;const aValue:_ValueType);         {$ifdef _DGL_Inline} inline; {$endif}

    property  Value: _ValueType read GetValue write SetValue; 
    property  NextValue[const Index:integer]: _ValueType read GetNextValue write SetNextValue;
    function  IsEqual(const Iterator:_IIterator):boolean;  //{$ifdef _DGL_Inline} inline; {$endif}

⌨️ 快捷键说明

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