IT 취미생활.  
Front Page
Tag | Location | Media | Guestbook | Admin   
 
'C++ Templete'에 해당하는 글(1)
2008.03.12   Tiny singleton helper class


Tiny singleton helper class

Introduction

Sometimes we have to code with 'singleton'. If you don't know what Singleton is, you can read about it in many Design Pattern books. Singleton principle is really simple.

As you know, if you use reference pointer for singleton object, then you must delete it when program terminates. But it will be good because it does 'late instance'.

I want to terminate singleton object automatically, and instance lately. So, I coded this.

Good things:

  • Late instance.
  • Safe terminate automatically.
  • Separated code for Object and Singleton.

Here is my tiny singleton helper class - CSingletonT<>, and I hope it helps you.

//
// Using singletonT class
//
#include "SingletonT.h"
// test class
class CObj
{
protected:
    CObj(){ x = 0 ; TRACE("Created CObj\r\n"); }
public:
    virtual ~CObj(){ x = 0 ; TRACE("Deleted CObj\r\n");}
    int x;
};
// Testing
void CTestSingleTDlg::OnButton1()
{
    // TODO: Add your control notification handler code here
    // if first call, then singleton object will instance ( instance lately )
        CObj* o = CSingletonT<CObj>::GetObject();
    // use singletone object
    o->x ++;
    TRACE("o->x = %d\r\n",o->x);
}
------------------------------------------------------------------------------------
싱글톤에 조금은 벗어났지만,활용 할 수 있는 방법은 많다고 생각 됩니다.
원문을 보고 싶으시다면  아래로...
정확한 출처는 CodeProject 입니다.



http://www.codeproject.com/cpp/singlet.asp
우리 나라 분이 작성한 글입니다


BLOG main image
취미생활
 Notice
 Category
분류 전체보기 (191)
매일매일갱생 (83)
서버개발 (1)
임베디드개발 (12)
Programming (80)
Personal Projects (6)
유용한 프로그램 (0)
 TAGS
warning Error Case 영어 이메일 1seg 알고리즘 isdbt english email ISDB-T Wince5.0 project 음식 Dshow DVB-T VC++ It M480 MP3 debugging 개발자 C Algorithm spam mail Debug English Linux 벨소리 변경 출장 DirectShow C++ Windows Mobile6.0 티스토리 초대장 Brazil DVB 서태지 티스토리초대 퇴사 군대 미라지폰 Java
 Calendar
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
 Recent Entries
 Recent Comments
 Recent Trackbacks
 Archive
 Link Site
zextor
괴짜 프로그래머의 일상사~@@
Gag & Peace, and more..
Kazakhstan Almaty.......
Min-A
Sadgarret
Steve Yoon's log
가슴 뛰는 삶을 살아라
오스틴 파워
GUI sin
melanie parker_Lady
제레미의 TV 2.0 이야기..
 Visitor Statistics
Total :
Today :
Yesterday :
rss