IT 취미생활.  
Front Page
Tag | Location | Media | Guestbook | Admin   
 
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
MP3 음식 Wince5.0 M480 벨소리 변경 isdbt 티스토리초대 Brazil spam mail Error Case ISDB-T 1seg DirectShow DVB Debug 알고리즘 warning 출장 미라지폰 Dshow 퇴사 english email DVB-T 군대 Java 영어 이메일 Windows Mobile6.0 Algorithm debugging VC++ project It English 티스토리 초대장 서태지 개발자 C C++ Linux
 Calendar
«   2024/05   »
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 31
 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