亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? xpsingleton.pas

?? 類似于Java JUnit的單元測試
?? PAS
字號:
unit XPSingleton;

{.$DEFINE DBG_XPSINGLETON}

{
 $Source: /cvsroot/dunit/dunit/Contrib/DUnitWizard/Source/Common/XPSingleton.pas,v $
 $Revision: 1.1 $
 $Date: 2004/05/03 15:07:15 $
 Last amended by $Author: pvspain $
 $State: Exp $

 Implementation of thread-safe singleton as a TObject descendant and
 a TInterfacedObject descendant.

 Copyright (c) 2001 by The Excellent Programming Company Pty Ltd
 (Australia) (ABN 27 005 394 918).

 Contact Paul Spain via email: paul@xpro.com.au

 This unit is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License as published by the Free Software Foundation; either
 version 2.1 of the License, or (at your option) any later version.

 This unit 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
 Lesser General Public License for more details.

 You should have received a copy of the GNU Lesser General Public
 License along with this unit; if not, the license can be viewed at:
 http://www.gnu.org/copyleft/lesser.html
 or write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 Boston, MA  02111-1307  USA
}

interface

{ TODO: Long term. May need to investigate better solution than TStringList
  for registration if performance is an issue. }

uses
  XPSyncRW,             // IXPSyncRW,
  XPWinSync,            // CreateThreadRWSynchroniser()
  XPStrings;         // IXPStrings, CreateXPStrings()

type

//////////////////////////////////////////////////////////////////////////////
//    TXPSingleton declaration
//////////////////////////////////////////////////////////////////////////////

  TXPSingleton = class(TObject)
    private

    FRefCount: integer;
    { Local references to file scope objects kept to stop premature
      disappearance of implementing objects after unit finalization occurs. }
    FSingletons: IXPStrings;
    FSync: IXPSyncRW;

    function GetRefCount: integer;
    function GetIsSoleRef: boolean;
{$IFDEF DBG_XPSINGLETON}
class procedure DumpYaGuts;
{$ENDIF}

    public

    class function NewInstance: TObject; override;
    procedure AfterConstruction; override;

    procedure BeforeDestruction; override;
    destructor Destroy; override;
    procedure FreeInstance; override;

    property RefCount: integer read GetRefCount;

  { You must reference <IsSoleRef> property in your subclass constructor.
    If <IsSoleRef> is true, you need to execute any code you may have in your
    subclass constructor. If false, you don't need to execute your code, as
    it has been executed in a previous constructor call.
    You must also reference <IsSoleRef> property in your subclass destructor.
    If <IsSoleRef> is true, you need to execute any code you may have in your
    subclass destructor. If false, you don't need to execute your code, as
    there are remaining references to the singleton. }

    property IsSoleRef: boolean read GetIsSoleRef;
    end;

//////////////////////////////////////////////////////////////////////////////
//    TXPInterfacedSingleton declaration
//////////////////////////////////////////////////////////////////////////////

  TXPInterfacedSingleton = class(TInterfacedObject, IUnknown)
    private

    { Local references to file scope objects kept to stop premature
      disappearance of implementing objects after unit finalization occurs. }
    FSingletons: IXPStrings;
    FSync: IXPSyncRW;

    function GetIsSoleRef: boolean;
    function GetRefCount: integer;

    public

    class function NewInstance: TObject; override;
    procedure AfterConstruction; override;

    destructor Destroy; override;

    function _AddRef: Integer; stdcall;
    function _Release: Integer; stdcall;


    { Hides inherited property. }
    property RefCount: integer read GetRefCount;

  { You must reference <IsSoleRef> property in your subclass constructor.
    If <IsSoleRef> is true, you need to execute any code you may have in your
    subclass constructor. If false, you don't need to execute your code, as
    it has been executed in a previous constructor call.

    Unlike TXPSingleton, you needn't reference <IsSoleRef> property in your
    subclass destructor. The destructor should never be called explicitly, and
    will only be invoked when the last reference disappears, so any destructor
    code should be executed for every invocation of Destroy(). }

    property IsSoleRef: boolean read GetIsSoleRef;
    end;

implementation

{$IFDEF DBG_XPSINGLETON}

uses
  PVDLU,        // PVDL.Diagnostic;
  SysUtils;

var
  fGOSingletons, fGISingletons: IXPStrings;
  fGOSync, fGISync: IXPSyncRW;

{$ELSE}

var
  GOSingletons, GISingletons: IXPStrings;
  GOSync, GISync: IXPSyncRW;

{$ENDIF}

const
  CVSID: string ='$Header: /cvsroot/dunit/dunit/Contrib/DUnitWizard/Source/Common/XPSingleton.pas,v 1.1 2004/05/03 15:07:15 pvspain Exp $';


{$IFDEF DBG_XPSINGLETON}

function GOSingletons: IXPStrings;
  begin

  if fGOSingletons = nil then
    fGOSingletons := CreateXPStrings(true);

  Result := fGOSingletons;
  end;

function GISingletons: IXPStrings;
  begin

  if fGISingletons = nil then
    fGISingletons := CreateXPStrings(true);

  Result := fGISingletons;
  end;

function GOSync: IXPSyncRW;
  begin

  if fGOSync = nil then
    fGOSync := CreateThreadRWSynchroniser;

  Result := fGOSync;
  end;

function GISync: IXPSyncRW;
  begin

  if fGISync = nil then
    fGISync := CreateThreadRWSynchroniser;

  Result := fGISync;
  end;

{$ENDIF}

//////////////////////////////////////////////////////////////////////////////
//    TXPSingleton implementation
//////////////////////////////////////////////////////////////////////////////

{$IFDEF DBG_XPSINGLETON}
class procedure TXPSingleton.DumpYaGuts;
  var
  idx: integer;
  msg: string;

  begin
  msg := 'TXPSingleton: Refs:';

  for idx := 0 to GOSingletons.Strings.Count - 1 do
    msg := SysUtils.Format('%s %s %d', [msg, GOSingletons.Strings[idx],
        TXPSingleton(GOSingletons.Strings.Objects[idx]).RefCount]);

  PVDL.Diagnostic.Post(msg);
  end;
{$ENDIF}

class function TXPSingleton.NewInstance: TObject;
  var
  idx: integer;

  begin
  { Entry point for construction process.
    Note that we are accessing the filescope references here (GOSync and
    GOSingletons), as the member equivalents won't be established yet
    for new instances. }
  GOSync.WriteBegin;
  idx := GOSingletons.Strings.IndexOf(ClassName);

  if idx <> -1 then
    { Previous instance. Return singleton. }
    Result := GOSingletons.Strings.Objects[idx]
  else
    begin
{$IFDEF DBG_XPSINGLETON}
    DumpYaGuts;
    PVDL.Diagnostic.PostFmt('TXPSingleton: Adding %s', [ClassName]);
{$ENDIF}
    { First instance. Allocate memory *and* initialise - InitInstance
      is called by inherited method. }
    Result := inherited NewInstance;
    { Register class name and associated instance. }
    GOSingletons.Strings.AddObject(ClassName, Result);
    { Allocate instance data. }
    TXPSingleton(Result).FSingletons := GOSingletons;
    TXPSingleton(Result).FSync := GOSync;
    end;

  { Increment reference count. }
  System.Inc(TXPSingleton(Result).FRefCount);
end;

procedure TXPSingleton.AfterConstruction;
  begin
  { Exit point for construction process. }
  GOSync.WriteEnd;
  end;

procedure TXPSingleton.BeforeDestruction;
  begin
  { Entry point for destruction process. }
  FSync.WriteBegin;
  end;

destructor TXPSingleton.Destroy;
  begin
  System.Dec(FRefCount);

    if FRefCount = 0 then
      begin
      with FSingletons.Strings do Delete(IndexOf(self.ClassName));
      inherited Destroy;
      end;

  end;

procedure TXPSingleton.FreeInstance;
  begin
  { Exit point for destruction process. }

  { Release memory only when all references gone. }
  if RefCount = 0 then
    begin
    FSync.WriteEnd;
{$IFDEF DBG_XPSINGLETON}
    PVDL.Diagnostic.PostFmt('TXPSingleton: Deleting %s', [ClassName]);
    DumpYaGuts;
{$ENDIF}
    inherited FreeInstance;
    end
  else
    FSync.WriteEnd;

  end;

function TXPSingleton.GetRefCount: integer;
  begin
  Result := FRefCount;
  end;

function TXPSingleton.GetIsSoleRef: boolean;
  begin
  FSync.ReadBegin;

  try
    Result := (RefCount = 1);
  finally
    FSync.ReadEnd;
    end;

  end;

//////////////////////////////////////////////////////////////////////////////
//    TXPInterfacedSingleton implementation
//////////////////////////////////////////////////////////////////////////////

class function TXPInterfacedSingleton.NewInstance: TObject;
  var
  idx: integer;

  begin
  { Entry point for construction process.
    Note that we are accessing the filescope references here (GISync and
    GISingletons), as the member equivalents won't be established yet
    for new instances. }
  GISync.WriteBegin;
  idx := GISingletons.Strings.IndexOf(ClassName);

  if idx <> -1 then
    begin
    { Previous instance. Return singleton. }
    Result := GISingletons.Strings.Objects[idx];
    { Increment ref count, as TInterfacedObject.AfterConstruction() decrements
      value by 1. No need to inc ref count otherwise, as this is done by
      TInterfacedObject._AddRef() mechanism. }
    System.Inc(TXPInterfacedSingleton(Result).FRefCount);
    end
  else
    begin
    { First instance. Allocate memory and initialise. }
    Result := inherited NewInstance;
    { Register class type and associated instance. }
    GISingletons.Strings.AddObject(ClassName, Result);
    { Allocate instance data. }
    TXPInterfacedSingleton(Result).FSingletons := GISingletons;
    TXPInterfacedSingleton(Result).FSync := GISync;
    end;

  end;

procedure TXPInterfacedSingleton.AfterConstruction;
  begin
  { Exit point for construction process. }
  inherited;
  GISync.WriteEnd;
  end;

destructor TXPInterfacedSingleton.Destroy;
  begin
  with FSingletons.Strings do Delete(IndexOf(self.ClassName));
  inherited;
  end;

function TXPInterfacedSingleton.GetIsSoleRef: boolean;
  begin
  { RefCount = 1 within the context of a constructor, or after the first
    assignment. RefCount = 0 for a constructed object that hasn't been
    assigned to an interface. }
  Result := (RefCount = 0) or (RefCount = 1);
  end;

function TXPInterfacedSingleton.GetRefCount: integer;
  begin
  FSync.ReadBegin;
  Result := FRefCount;
  FSync.ReadEnd;
  end;

function TXPInterfacedSingleton._AddRef: Integer;
  begin
  FSync.WriteBegin;
  System.Inc(FRefCount);
  Result := FRefCount;
  FSync.WriteEnd;
  end;

function TXPInterfacedSingleton._Release: Integer;
  begin
  FSync.WriteBegin;
  System.Dec(FRefCount);
  Result := FRefCount;
  FSync.WriteEnd;

  if Result = 0 then
    Destroy;

  end;

{$IFNDEF DBG_XPSINGLETON}

initialization

  GOSync := CreateThreadRWSynchroniser;
  GISync := CreateThreadRWSynchroniser;
  { Sort IXPStrings to improve lookup response. }
  GOSingletons := CreateXPStrings(true);
  GISingletons := CreateXPStrings(true);

{$ENDIF}
end.

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
樱桃视频在线观看一区| 成人av网站在线观看免费| 国产一区在线观看麻豆| 99久久久国产精品免费蜜臀| 日韩一级大片在线观看| 亚洲欧美日韩一区二区 | 亚洲欧美日韩国产综合| 黄色日韩网站视频| 欧美精品一卡两卡| 亚洲欧美激情小说另类| 国产精品88av| 久久久久久久久一| 男女激情视频一区| 欧美三级在线播放| 亚洲精品福利视频网站| 成人国产精品免费观看视频| 久久网站热最新地址| 天涯成人国产亚洲精品一区av| 91丝袜呻吟高潮美腿白嫩在线观看| 久久久久久久综合| 国产剧情在线观看一区二区| 日韩亚洲欧美成人一区| 天堂蜜桃一区二区三区| 欧美久久婷婷综合色| 亚洲精品国产a| 日本韩国视频一区二区| 一区二区三区免费| 色综合久久久久综合体| 亚洲图片另类小说| 一本色道**综合亚洲精品蜜桃冫| 成人欧美一区二区三区黑人麻豆| 国产91色综合久久免费分享| 国产午夜精品美女毛片视频| 韩国精品一区二区| 精品国产在天天线2019| 精品一区二区三区免费| 欧美变态tickle挠乳网站| 另类小说欧美激情| 久久天天做天天爱综合色| 国产九九视频一区二区三区| 国产欧美一区二区精品久导航| 国产精品自拍在线| 国产精品黄色在线观看| 欧洲人成人精品| 日韩激情视频在线观看| 欧美本精品男人aⅴ天堂| 国产在线播放一区二区三区| 国产精品青草综合久久久久99| 99久久免费视频.com| 亚洲欧洲日韩一区二区三区| 一本在线高清不卡dvd| 亚洲国产成人av网| 欧美变态tickle挠乳网站| 懂色av噜噜一区二区三区av| 国产精品白丝在线| 337p亚洲精品色噜噜狠狠| 国产在线精品一区二区三区不卡| 中文字幕二三区不卡| 欧美日韩在线播放一区| 国内不卡的二区三区中文字幕 | 欧美人xxxx| 麻豆精品一区二区av白丝在线| 国产色爱av资源综合区| 日本久久一区二区三区| 久99久精品视频免费观看| 国产精品免费久久| 91精品国产综合久久久蜜臀粉嫩| 国产成人福利片| 五月开心婷婷久久| 国产精品拍天天在线| 欧美乱熟臀69xxxxxx| 韩国av一区二区三区四区| 亚洲免费av网站| 欧美成人午夜电影| 在线观看免费视频综合| 国产精品性做久久久久久| 亚洲激情自拍视频| 久久精品视频在线免费观看| 欧美日韩成人在线| 不卡一区二区中文字幕| 蜜桃视频一区二区三区在线观看 | 亚洲精品一区二区三区蜜桃下载 | 亚洲一级在线观看| 久久精品一区二区| 欧美一卡二卡三卡| 91麻豆蜜桃一区二区三区| 国产一区二区美女诱惑| 亚洲一区二区三区中文字幕在线| 中文字幕成人网| 日韩亚洲欧美在线观看| 欧美三级三级三级爽爽爽| 成人av在线观| 国产成人日日夜夜| 麻豆视频观看网址久久| 五月天一区二区三区| 亚洲人成在线观看一区二区| 久久精品夜夜夜夜久久| 欧美xingq一区二区| 欧美一区二区三区公司| 欧美视频第二页| 色综合久久中文字幕综合网| www.一区二区| 99视频精品免费视频| 成人高清视频在线观看| 国产精品一区不卡| 国产精品资源在线看| 久久精品国产999大香线蕉| 天天色 色综合| 亚洲国产视频一区二区| 亚洲国产中文字幕| 午夜a成v人精品| 亚洲电影一级黄| 日韩精品91亚洲二区在线观看| 亚洲一区二区在线免费观看视频| 夜色激情一区二区| 亚洲国产sm捆绑调教视频| 一区二区激情视频| 亚洲午夜在线视频| 日本伊人色综合网| 捆绑调教一区二区三区| 喷水一区二区三区| 韩国精品久久久| 粉嫩久久99精品久久久久久夜| 国产99久久久国产精品免费看| 国产九色sp调教91| 波多野洁衣一区| 欧美日韩在线不卡| 日韩免费视频一区二区| 久久先锋影音av鲁色资源网| 欧美经典一区二区| 亚洲免费在线观看视频| 亚洲国产成人精品视频| 久久99九九99精品| 99麻豆久久久国产精品免费| 色美美综合视频| 91精品国产高清一区二区三区 | 制服丝袜中文字幕亚洲| 欧美精品一区男女天堂| 国产精品麻豆视频| 夜夜爽夜夜爽精品视频| 美国十次了思思久久精品导航| 国产精品一二三四| 色婷婷一区二区三区四区| 欧美精品v国产精品v日韩精品| 欧美电影精品一区二区| 国产精品久久夜| 丝袜a∨在线一区二区三区不卡| 狠狠v欧美v日韩v亚洲ⅴ| 91丨九色丨黑人外教| 欧美一区二区三区免费| 1024成人网色www| 久久成人羞羞网站| 在线视频综合导航| 久久蜜桃一区二区| 亚洲妇女屁股眼交7| 国产suv精品一区二区三区| 欧美色老头old∨ideo| 久久丝袜美腿综合| 午夜在线成人av| 成人免费毛片嘿嘿连载视频| 欧美精品xxxxbbbb| 国产精品久久久久一区| 久久99精品久久久久久国产越南| 色婷婷久久一区二区三区麻豆| 91精品国产综合久久久久| 亚洲欧美综合网| 国产黑丝在线一区二区三区| 欧美人妇做爰xxxⅹ性高电影| 欧美激情一区二区三区| 免费观看一级欧美片| 日本高清不卡aⅴ免费网站| 久久香蕉国产线看观看99| 日韩精品国产精品| 精品婷婷伊人一区三区三| 中文字幕在线观看一区二区| 另类小说视频一区二区| 欧美日韩亚洲综合在线| 亚洲人成网站在线| 国产成人综合网| 2021国产精品久久精品| 日本vs亚洲vs韩国一区三区二区| 欧洲精品在线观看| 亚洲欧美一区二区三区国产精品| 国产经典欧美精品| 精品日韩在线观看| 日本特黄久久久高潮| 欧美日韩国产欧美日美国产精品| 亚洲日本电影在线| 暴力调教一区二区三区| 国产精品私房写真福利视频| 国产一区二区三区免费播放 | 国产在线国偷精品产拍免费yy| 欧美精品1区2区| 午夜影院久久久| 7777女厕盗摄久久久| 日韩专区在线视频| 在线观看91av| 七七婷婷婷婷精品国产| 日韩欧美中文字幕制服| 久久精品国产澳门|