SlideShare a Scribd company logo
GPG2권 1.6동적인형 정보 김준섭 (트라시르)
동적 형 정보 클래스 Dynamic Type Information
동적 형 정보 클래스 ? 실행시점에서 형에 대한 관리를 효율적으로 수행하기 위한 클래스
간단한 형태로 구현한 동적 형 정보 클래스 Class dtiClass { Private: char* szName; dtiClass* pdtiParent; Public: dtiClass(); dtiClass( char* szSetName, dtiClass* pSetParent ); virtual ditClass(); const char* GetName(); boolSetName( char* szSetName ); dtiClass* GetParent(); boolSetParent( dtiClass* pSetParent ); };
DTI 클래스 사용 Dynamic Type Information
DTI를 도입하려면 클래스들이 dtiClass를 static 맴버로포함을시키고 초기화 해야 한다. #define EXPOSE_TYPE br />	public: br />		static dtiClass Type; class CRootClass { public: EXPOSE_TYPE; CRootClass() {}; 	virtual ~CRootClass() {}; }; dtiClassCRootClass::Type( "CRootClass", NULL );
객체의 클래스 이름을 조회 pSomeptr->Type.GetName(); 객체의 부모 클래스 이름을 조회 pSomeptr->Type.GetParent()->GetName();
문제점 void main(void) { A* a = new B; cout << a->Type.GetName() << endl; cout<< *a->Type.GetName() << endl; } 출력 화면 A A
해결책 public:  static dtiClassType; public:	 	virtual dtiClass* RuntimeInfo() { return & Type; } 사용 void main(void) { A* a = new B; cout << a->Type.GetName() << endl; cout << a->RuntimeInfo()->GetName() << endl; } 출력 화면 A B
상속 관계 사용
다양한 종류의 객체들을 다형성을 사용하는 경우가 많다. 객체를 다른 것으로 형 변형하기 전에  그 객체가 호환 가능한 형인지를 확인해야 한다. booldtiClass::IsA( dtiClass* pType ) { dtiClass* pStartType = this; 	while( pStartType ) 	{ 		if ( pStartType == pType ) 		{ 			return true; 		} 		else 		{ pStartType = pStartType->GetParent(); 		} 	} 	return false; }
IsA함수를 이용하여 안전한 형변형을 위한 함수를 만들 수 있다. void* CRootClass::SafeCast( dtiClass* pCastToType ) { if ( Type.IsA( pCastToType ) ) { 		return this; } 	else { return NULL; } } 형 변형이 안전하지 않다면 NULL을 돌려준다.
영속적 형 정보 구현 Persistent Type information
객체에 대한 정보를 영속적으로 보관하거나 다시 들여오는 방법을 살펴보자 데이터를 저장하는 클래스를 만들고  파일에 읽거나 쓰기를 위한 Stream 맴버 함수와  		friend << 연산자를 정의해준다 friend CdtiBin& operator<<( CdtiBin& bin, int& data ) { bin.Stream( &data, sizeof(int) ); 	return bin; } 클래스가 저장 클래스와 연동할 수 있는 함수를 만들어준다. void CChildClass::Serialize( CdtiBin& ObjStore ) { Root::Serialize( ObjStore ); ObjStore << fMemberFloat << iAnotherInt; }
부록
MFC에서의 DTI사용 예제 트리니지의VISION 엔진에서 사용되고 있는 예 http://cafe.naver.com/devrookie/5431
Q/A
감사합니다

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

1.6 동적인 형 정보

  • 1. GPG2권 1.6동적인형 정보 김준섭 (트라시르)
  • 2. 동적 형 정보 클래스 Dynamic Type Information
  • 3. 동적 형 정보 클래스 ? 실행시점에서 형에 대한 관리를 효율적으로 수행하기 위한 클래스
  • 4. 간단한 형태로 구현한 동적 형 정보 클래스 Class dtiClass { Private: char* szName; dtiClass* pdtiParent; Public: dtiClass(); dtiClass( char* szSetName, dtiClass* pSetParent ); virtual ditClass(); const char* GetName(); boolSetName( char* szSetName ); dtiClass* GetParent(); boolSetParent( dtiClass* pSetParent ); };
  • 5. DTI 클래스 사용 Dynamic Type Information
  • 6. DTI를 도입하려면 클래스들이 dtiClass를 static 맴버로포함을시키고 초기화 해야 한다. #define EXPOSE_TYPE br /> public: br /> static dtiClass Type; class CRootClass { public: EXPOSE_TYPE; CRootClass() {}; virtual ~CRootClass() {}; }; dtiClassCRootClass::Type( "CRootClass", NULL );
  • 7. 객체의 클래스 이름을 조회 pSomeptr->Type.GetName(); 객체의 부모 클래스 이름을 조회 pSomeptr->Type.GetParent()->GetName();
  • 8. 문제점 void main(void) { A* a = new B; cout << a->Type.GetName() << endl; cout<< *a->Type.GetName() << endl; } 출력 화면 A A
  • 9. 해결책 public: static dtiClassType; public: virtual dtiClass* RuntimeInfo() { return & Type; } 사용 void main(void) { A* a = new B; cout << a->Type.GetName() << endl; cout << a->RuntimeInfo()->GetName() << endl; } 출력 화면 A B
  • 11. 다양한 종류의 객체들을 다형성을 사용하는 경우가 많다. 객체를 다른 것으로 형 변형하기 전에 그 객체가 호환 가능한 형인지를 확인해야 한다. booldtiClass::IsA( dtiClass* pType ) { dtiClass* pStartType = this; while( pStartType ) { if ( pStartType == pType ) { return true; } else { pStartType = pStartType->GetParent(); } } return false; }
  • 12. IsA함수를 이용하여 안전한 형변형을 위한 함수를 만들 수 있다. void* CRootClass::SafeCast( dtiClass* pCastToType ) { if ( Type.IsA( pCastToType ) ) { return this; } else { return NULL; } } 형 변형이 안전하지 않다면 NULL을 돌려준다.
  • 13. 영속적 형 정보 구현 Persistent Type information
  • 14. 객체에 대한 정보를 영속적으로 보관하거나 다시 들여오는 방법을 살펴보자 데이터를 저장하는 클래스를 만들고 파일에 읽거나 쓰기를 위한 Stream 맴버 함수와 friend << 연산자를 정의해준다 friend CdtiBin& operator<<( CdtiBin& bin, int& data ) { bin.Stream( &data, sizeof(int) ); return bin; } 클래스가 저장 클래스와 연동할 수 있는 함수를 만들어준다. void CChildClass::Serialize( CdtiBin& ObjStore ) { Root::Serialize( ObjStore ); ObjStore << fMemberFloat << iAnotherInt; }
  • 16. MFC에서의 DTI사용 예제 트리니지의VISION 엔진에서 사용되고 있는 예 http://cafe.naver.com/devrookie/5431
  • 17. Q/A