public class Data

{

public int Val = 0;

public Data(int val)

{

Val = val;

}

}


List<Data> datas = new List<Data>();


datas.Add(new Data(1));

datas.Add(new Data(3));

datas.Add(new Data(2));


1. List의 Sort 함수 이용


datas.Sort(delegate(Data a, Data b)

{

if(a.Val > b.Val)

return 1;

else if(a.Val < b.Val)

return -1;

else 

return 0;

}

);


2. LinkQ 이용

var result = from n in datas orderby(descending) n.Val select n;



블로그 이미지

UART

,

AndroidManifest.xml 에 아래와 같이 installLocation 을 추가 한다.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"   
package="com.freecatz.test"    
android:versionCode="3"    
android:versionName="1.6"    
android:installLocation="preferExternal" >

auto : 자동으로 내장메모리에 우선 설치 하나 공간이 없는 경우 외장메모리에 설치.
internalOnly : 내장 메모리에 설치.
preferExternal : 외장메모리에 설치를 우선으로 하나 공간이 없는 경우 내장메모리에 설치.
블로그 이미지

UART

,

 

출처 :http://matoker.com/30179140155http://matoker.com/30179140155

[Eclipse] 이클립스 한글 잘보이게 변경하기(글꼴/폰트 변경하기)

(글꼴/폰트 변경하기)

이클립스에서 한글을 보면 잘 안보입니다.

좀 작고 찌그러져 보입니다.

이클립스 기본 글꼴로 지정되어 있는 Consolas 글꼴이 한글을 이쁘게 지원하지 않기 때문입니다.

그래서 한글이 잘 보이는 글꼴로 변경해보겠습니다.

제어판에 들어간 이후에 우측 상단에서 "글꼴"로 검색을 합니다.

그리고 [설치된 글꼴 보기]를 클릭합니다.

설치된 글꼴 중에서 Courier New 를 찾습니다.

Courier New 글꼴이 연하게 보이면 숨기기(비활성화) 상태이므로 표시(활성화) 상태로 변경합니다.

표시(활성화) 상태입니다.

이클립스 상단 메뉴에서 [Window]->[Preferences] 로 들어갑니다.

[General]->[Editors]->[Text Editors]->[Colors and Fonts] 로 들어갑니다.

[Text Font]를 선택하고 [Edit]를 클릭합니다.

Courier New 를 선택합니다.

[OK]를 클릭합니다.

한글이 잘 보이도록 변경이 되었습니다.

Courier New 글꼴은 Fixed Font 이므로 글자 가로 크기가 동일합니다.

개발자에게 필수인 Fixed Font 입니다.

이상으로 포스팅을 마칩니다.

블로그 이미지

UART

,

설치 순서

JDK설치 -> 이클립스설치 –> ADT 플러그인 설치 –> 안드로이드 SDK 설치 –> AVD 생성 –> eclipse 환경설정

1. JDK 설치

JDK 다운로드 – SE 버전 다운로드

옵션 변경 없이 모두 설치

시스템변수에 JAVA_HOME 추가, 자바 JDK의 설치 홈위치를 등록한다.

2. 이클립스(ECLIPSE) 설치

ECLIPSE 다운로드  - Eclipse IDE for Java Developers 다운로드

원하는 곳에 압축을 풀고 eclipse.exe 의 단축 아이콘 생성

3. ADT 플러그인 설치

ECLIPSE 메뉴 중  Help / Install New Software  선택

Add를 클릭하여

Name : Android ADT

location : http://dl-ssl.google.com/android/eclipse/

을 입력 한다.

 

4. Android(안드로이드) SDK 설치

SDK 다운로드 -    위에서 한 것 처럼 별도로 eclipse를 받았다면 USE AN EXISTING IDE 측 메뉴에서 선택하여 SDK 설치파일을  다운 받고 실행하여 설치 하자.   SDK만 설치하고자 하면 JAVA_HOME 변수가 꼭 필요하다.

이후 ADT를 잘 설치 되었다면 eclipse 의 메뉴 중 window / Android SDK Manager 가 보일 것이고 이를 실행하여 원하는 SDK를 설치 하면 된다. 설치 후 eclipse에 SDK가 설치 되어 있는 위치를 알려 주어야 한다. Window/Preference 메뉴에 Android 의 SDK Location 란에 위치를 알려 준다.

최근에는 SDK를 다운 받는 곳에 eclipse와 ADT 가 설치되어 있는 것을 배포하고 있다. 1,2,3 번을 생략 할 수 있다. 받는 것은 선택 사항이다.

5. AVD 생성

eclipse의 Window / Android Virtual Device Manager 를 선택하여 실행 생성하면 된다.  별 어려움은 없다.

6. eclipse의 환경설정

Preference / General / Workspace  -> Text file encoding –> UTF-8

Preference / General / Editors / Text Editors / Spelling –> Enable spell checking 해지

Preference / Java / Coding Style / Organize Import  / Number of import … –> 1

Preference / Java / Compiler / Errors / Warnings / Unnecessary code  -> All Ignore

Preference / Android / DDMS / ADB connection time out( ms ) –> 30000 이상

블로그 이미지

UART

,

image

이 것에서 아래 처럼 체크 해제

image

블로그 이미지

UART

,

MS SQL에서 FILE관리하기 위해서 사용했었다. 하지만 일전에 발견된 문제(?)에

다시 이전 방식(BLOB,IMAGE)으로 돌아갔었다. 하지만 내가 무지해서 방법을 찾지 못한 것인가? 란 생각에

 

다시 설치하고 확인을 했으나 역시 맘에들지 않았다.

그럼 내가 고민한 문제는 아마 고수 분들은 가볍게 웃을 수 있겠으나 내가 찾는 방법은 현재는 하나 밖에 없었다. 누구 방법을 알려 주면 좋겠는데.. 

내가 느낀 단점은 파일스트림으로 저장된 공간(NTFS 파일시스템)은 QUERY (DELETE 문) 로 삭제 되지 않았다. 나중에 보니 NTFS가 만들 수 있는 단일 폴더 개수를 넘어서니 파일시스템오류를 내고 더 이상 진행 되지 않는다.

유일한 방법(현재까지)은 DELETE 문 날리고 이후 백업을 하는 것인데.. 파일 스트림을 사용한다는 것은 대용량 파일을 사용하는 것이고 백업하면서 사용하기에는 문제가 된다. 

 

기존 처럼 IMAGE에 넣어 두고, DELETE 날리면 삭제될 것인데.. FILESTREAM 너무 불편하다. 

 

관리 도구를 사용하여 백업을 자동화 할 수 도 있겠으나  백업 용량은 어떻게 할 것인가?

디비 로그는 또 어떻게 할 것인가? 

 

 

에휴 .. 명괘한 답이 있으면 좋겠으나 아직 찾지 못했다.

아직 사용할 때가 아닌가보다....

블로그 이미지

UART

,

기존 FILE STREAM의 단점을 해결해 보려고 다시 세팅  하려 했으나 역시 책이 없으면 안되는  머리에.. 검색으로 남겨둡니다.

#원본 http://jgwk.tistory.com/14

오류 메시지
FILESTREAM 기능을 사용할 수 없습니다.


해결방법
1.시작 메뉴에서 모든 프로그램, Microsoft SQL Server 2008 R2, 구성 도구를 차례로 가리킨 다음 SQL Server 구성 관리자를 클릭합니다.
2.서비스 목록에서 SQL Server 서비스를 마우스 오른쪽 단추로 클릭한 다음 열기를 클릭합니다.
3.SQL Server 구성 관리자 스냅인에서 FILESTREAM을 사용할 SQL Server 인스턴스를 찾습니다.
4.해당 인스턴스를 마우스 오른쪽 단추로 클릭한 다음 속성을 클릭합니다.
5.SQL Server 속성 대화 상자에서 FILESTREAM 탭을 클릭합니다.
6.Transact-SQL 액세스에 FILESTREAM 사용 확인란을 선택합니다.
7.Windows에서 FILESTREAM 데이터를 읽고 쓰려는 경우 파일 I/O 스트리밍 액세스에 FILESTREAM 사용을 클릭합니다. Windows 공유 이름 상자에 Windows 공유의 이름을 입력합니다.
8.원격 클라이언트가 이 공유에 저장된 FILESTREAM 데이터에 액세스해야 하는 경우 원격 클라이언트가 FILESTREAM 데이터에 대한 스트리밍 액세스를 가질 수 있도록 허용을 선택합니다.
9.적용을 클릭합니다.
10.SQL Server Management Studio에서 새 쿼리를 클릭하여 쿼리 편집기를 표시합니다.
11.쿼리 편집기에서 다음 Transact-SQL 코드를 입력합니다.

   EXEC sp_configure filestream_access_level, 2 (실행)
   RECONFIGURE (실행)

http://technet.microsoft.com/ko-kr/library/cc645923.aspx

블로그 이미지

UART

,

모달리스 대화 상자 제어하기란 속성을 변경한다는 것도 들어갑니다만 

여기서는 모달리스에서 어떤 이벤트가 발생시 특정처리해야 할 것을 이야기 합니다.

이전에 C++ 에서 모달리스 에게 자신의 포인터를 넘겨서 특정 처리를  했습니다만  C#에서는 이벤트를 등록하여 처리하도록 권하고 있습니다.

 

먼저 모달리스 폼 측 (UserForm : Form )

public event EventHandler  doEvent;  // 이벤트 선언

if( doEvent != null ) doEvent(this, new EventArgs());  // 이벤트호출

 

다음 모달리스 폼 호출 측

 

1. 처리 함수 정의

public void  DoEvent( object obj, EventArgs e)

{

     UserForm dlg = obj as UserForm;

     //dlg를 통하여 처리

}

 

2. 모달리스폼 호출시 정의

UserForm dlg = new UserForm();

dlg.Owner = this;

dlg.doEvent += new EventHandler(DoEvent);

dlg.Show();


블로그 이미지

UART

,

원본 : http://narsus.net/technotes/1300

Visual C++를 사용하다 보면 여러가지 파일들이 자동으로 생성되는데,
이들 중 다음 파일들은 항상 자동 생성될 수 있으므로 백업시 삭제하여도 무방하며
CVS와 같은 소스관리 프로그램에는 추가되지 않도록 하는 것이 좋다.
# Visual C++에서 지워도 되는 파일들
*.pch *.mdp *.ncb *.clw *.obj *.aps *.cpl *.awk *.exp *.idb
*.opt *.pdb *.map *.res *.ilk *.scc *.bsc *.sbr *.tlb *.plg
*.lib *.dll *.exe
# 그러나, 다음 파일들은 지워서는 안된다.
*.mak, *.dsp, *.c, *.rc, *.rc2, *.ico, *.bmp, *.txt, *.def, *.hpj, *.bat, *.rtf,
*.odl, *.inf, *.reg, *.cnt, *.cpp, *.cxx, *.h, *.hpp, *.hxx, *.inl, *.tpl, *.vtp, *.mst
*--- 파일 확장자별 설명 ----------------------------------------------------------*
참고로, 아래의 설명은 MSDN 도움말에서 발췌한 것임을 밝혀둔다.
*--------------------------------------------------------------------------------*
.C/.CPP/.H/.HPP/.HXX
프로그램 소스 파일
.INL
인라인 함수 파일: 인라인 함수들에 대한 정의 포함
.RC or .RC2
윈도우 리소스 파일(Resource file)
.DEF
모듈 정의 파일(Module definition file)
.APS -- Binary version of the resource file:
This is the binary version of the current resource file. App Studio or the resource editor uses it for quick loading.
.BSC -- Browser database file:
A single .BSC file is created for each project. To use the Browser, you need to open this file in the Visual C++ Workbench. It is created from the .SBR files when the BSCMAKE tool is run.
.CLW -- Class Wizard status file:
This file keeps information about where message-handling functions are kept in your code. The format of this text file is undocumented, but it can be regenerated. For more information on how to regenerate this file, please click Contents on the Help menu in App Studio; then click "Using Class Wizard" and "Update Class Wizard when Code Changes."
.EXE or .DLL -- Executable or dynamic link library file:
This file is the final linked output file for the project. It contains executable code.
.ILK (versions 2.0 and later only) -- Incremental link information file:
The linker creates this file to allow incremental linking when possible. If you delete it, you will force the linker to perform a full link.
.OBJ -- Object module file:
This is the final output file from the compiler. The linker combines these files to create the final .EXE, .DLL, or .LIB file. The .OBJ files may have different formats in different versions of Visual C++ or in different vendor's compilers.
.PCH -- Precompiled header file:
These files can significantly speed up compile time. They are created when using the /Yc, /Yu, or /YX compiler options.
.PDB -- Program database file:
This binary file contains type and symbolic debugging information gathered over the course of compiling and linking the project. The file is for use with the Visual C++ debugger. Object files contain references into the .PDB file for debugging information. This design makes object files smaller. See the online reference under the /Zi switch for more information. When you use the /Z7 switch, this file is not created.
.SBR -- Source browser file:
This file is created for each source file compiled with either the /FR or /Fr switch. This file contains symbolic information used by the Microsoft Browser Database Maintenance Utility (BSCMAKE) to produce a browser database file (.BSC file).
.WSP -- Workspace information file (16-bit versions only):
This is a binary file containing information about the state of the WorkBench when it was closed. Such items as source files opened and their window positions are saved in this file.
.VCP -- Workspace information file (Visual C++ 2.x and later only):
This file is the Visual C++ version 2.x equivalent of the 16-bit versions' .WSP file.
.VCW -- Visual WorkBench Status file (16-bit versions only):
This file is created on a per-project basis. It works with the .MAK file to fully describe the project to the WorkBench.
.EXP -- Export file:
Export files contain information about exported functions and data items. When LIB creates an import library, it also creates an export file. You use the .EXP file when you link a program that both exports to and imports from another program, either directly or indirectly. If you link with an .EXP file, LINK does not produce an import library because it assumes that LIB already created one.
.LIB -- Library file:
These files could be standard library or import library files. Standard libraries contain objects and are created by the LIB tool. Import libraries contain information about exports in other programs and are created either by LINK when it builds a program that contains exports or by the LIB tool.
.MAP -- Map file:
A map file is a text file that contains information about the program being linked. The information includes the module name, the timestamp from the program file header (not from the file system), and a list of groups in the program with each group's starting address, length, group name, and class. It also contains a list of public symbols with each address, symbol name, flat address, and object file where the symbol is defined. A map file also includes the entry point of the program and a list of fixups.
.RES -- Compiled resource file:
The .RES file is created by the Resource Compiler (RC).
.HPJ -- Context-sensitive help project file:
This file appears when you use the Visual C++ AppWizard to create an MFC application that supports context-sensitive help. You need this file to create help files from the .RTF files and .BMP files generated by the AppWizard.
NCB -- Parser information file:
This file contains information generated by the parser used by the class view and component gallery. If the file is accidentally or deliberately deleted, it is automatically regenerated.
MDP -- Microsoft Developer studio Project file:
This file replaces Visual C++ version 2.x's .VCP file. The .MDP file contains more information about the project than does the .VCP file.
RCT -- Resource template file:
These files contain information on custom resources that can be used when you insert a resource. It can include menus, toolbars, bitmaps and any of the other resource types listed in the Insert Resource menu.
다음은 빌드 과정에서 임시로 생겼다가 사라지는두 가지 파일 들이다.
.CRF -- linker response file:
This file is created on the fly by the build process.
MSVC.BND -- copy of project .CRF file:
This file is created if the resources need to be bound to the executable. It is simply a copy of the project's .CRF file. There are some other files created depending on the features the project supports. For example, your project may also have one or more icon files with .ICO extensions, cursor files with .CUR extensions, or bitmap files with .BMP extensions. A project may also have a .REG file that has registry information for the project. Projects that support OLE may also have an .ODL file and .TLB files.

블로그 이미지

UART

,

오늘 갑자기 코딩을 하다가 보니 기존 4개의 함수를 순차적으로 부르고 있었으나 개수가 더 늘어날 수 있어서,

함수 포인터를 사용하고 싶었다. 책도 없고 기억도 가물한 상황 , 삽질을 해야 하나 귀찮기도 하여 검색했더니 훌륭한 정리 글을 볼 수 있었다.  아래 글... 보자.

 

출처 : http://zeph.tistory.com/155

함수 포인터 및 클래스 멤버함수의 함수포인터화

무슨 바람이 불었는지 갑자기 이런글이 쓰고 싶어져서 후다닥 써봤다;
틀린점이 많을지도...;ㅁ;
(사실 모 카페의 압박이..--;;)
///////////////////////////
< 함수 포인터 >
먼저 이 글은 포인터에 대한 이해를 필요로 한다.
포인터에 대한 기본지식이 있다고 가정하고 글을 쓰도록 하겠다.

int GetAreaEx( int x, int y )
{
    return x * y;
}

우선 이런 간단한 함수가 있다. 우리는 이 함수를 호출하기 위해 명시적으로
GetAreaEx( x, y );
이런식으로 기술해야 한다.
하지만 예를 들어 GetArea2, GetArea3, ..., GetAreaN 이런식으로 비슷한 함수가 존재하고
이를 상황에따라 다르게 호출해야 한다면 이 방식으로는 관리도 어려울 뿐더러 효율성도 떨어지고 코드량도 많이질 것이다.
또한 외부(스크립트 등)에서 어떤 특정한 함수를 호출하려 할때도 방법이 묘연할 것이다.
int (*GetArea)( int, int );
이 선언은 무엇일까?
언뜻보기에는 함수를 선언하는 것 같다.
이 선언은 함수에 대한 포인터를 선언한 것이다.
변수의 주소를 담는 포인터와 마찬가지로 함수포인터는 함수의 주소를 담는다.

GetArea = GetAreaEx; // 함수포인터 GetArea에 GetAreaEx()의 주소를 담는다
int nArea = (*GetArea)( x, y ); // (*GetArea)( x, y ); 로 GetAreaEx()함수를 호출하고 리턴받은 값을 nArea에 대입

이런식으로 GetAreaEx를 호출할 수 있다.
유의할점은 *GetArea를 꼭 ()로 감싸주어야 한다는 사실이다.
빼먹으면 컴파일러가 함수포인터를 통한 호출로 인식하지 못한다.
int (*GetArea[])( int, int ) = { GetAreaEx, GetArea2, GetArea3, ..., GetAreaN };
이것은 함수포인터 배열을 정적으로 선언한 것이다. 이렇게 배열로 기능이 비슷한 함수들을 묶어놓았다.

void CallFunc( int nState, int x, y )
{
    int nResult = (*GetArea[nState])( x, y );
}

그리고 그 함수들을 상황에 맞게 호출한다.
만약 함수포인터를 쓰지 않는다면

void CallFunc( int nState, int x, int y )
{
    int nResult;
    switch( nState )
    {
         case STATE_EX:
              nResult = GetAreaEx( x, y );
         break;
         case STATE_2:
              nResult = GetArea2( x, y );
         break;
         case STATE_3:
              nResult = GetArea3( x, y );
         break;
    }
}

위와 같이 기술해야 할 것이다.
두 방식의 차이점과 함수포인터의 이점을 알 수 있겠는가
그렇다면 함수포인터 배열을 동적으로 할당하는 방법은 없을까?
다음과 같은 방법으로 할당할 수 있다.

int (**GetArea)( int, int ); // 함수포인터의 포인터
GetArea = new (int (*[N])( int, int )); // N은 배열의 크기

그리고 다음과 같이 사용하면 된다.

GetArea[0] = GetAreaEx;
GetArea[1] = GetArea2;
GetArea[2] = GetArea3;
...
int nResult = (*GetArea[nState])( x, y );

물론 사용후 delete [] GetArea; 해서 해제하는것을 잊으면 안된다.
< 클래스 멤버함수의 함수포인터화 >
함수포인터는 함수의 주소값을 담는다고 했다.
그렇다면 클래스 멤버함수의 주소값도 단순히 함수포인터에 담아서 호출할 수 있지 않을까?
int (*func)();
func = CFunc::GetArea;

하지만 이 방법은 GetArea()멤버함수가 static으로 선언되었을 때만 가능하다.
static으로 선언되지 않은 멤버함수(멤버변수를 건들여야 하는 멤버함수)를 이 방법으로 담으려 한다면 컴파일 에러가 뜰 것이다.
여기에 다음과 같은 해결방법이 있다.
첫번째 방법은

class CFunc
{
public:
    static int GetArea( CFunc * cls, int x, int y );
};

위와 같이 선언하고 호출할때 해당 인트턴스의 포인터를 넘겨줘서

int GetArea( CFunc * cls, int x, int y )
{
    int a = cls->GetZ();
}

이런식으로 멤버변수를 읽거나 쓸수 있겠지만 이 방식으로는 한계가 있다.
Get, Set 같은 public 외부함수로 억세스하지 않으면 private나 protected안에 선언되어 있는
멤버변수는 건드릴 수 없다.
두번째는 멤버함수의 소속을 명시화하는 방법이다.

int (CFunc::*func)( int, int );
func = CFunc::GetArea;
CFunc A;
(A.*func)( x, y );

위와 같은 방법으로 해결가능하다. 물론 호출할 인스턴스가 명확해야 한다.
세번째는 클래스 안에 함수포인터를 멤버변수로 두고 별도의 함수포인터를 컨트롤하는 멤버함수를 만드는 방법이 있다.
이 방법이 멤버함수 관리가 가장 쉬우며 효율적이다.

class CFunc
{
public:
    int (CFunc::*pFunc)( int, int );
    int GetArea( int x, int y );
    void CallFunc( void ) { (this->*pFunc)( x, y ); } // CallFunc 함수호출시 자체 오버헤드를 줄이기 위해 inline
    CFunc();
    ~CFunc() {}
};
CFunc::CFunc()
{
    pFunc = GetArea;
}
int CFunc::GetArea( int x, int y )
{
    return x * y;
}

위와 같다면 CallFunc(); 로 GetArea 호출이 가능해진다.
지금은 단순히 한개의 멤버함수 호출만 할뿐 의미가 없다. 이제 실제 효율적으로 쓰이게 배열을 써보자.

class CFunc
{
public:
    int (CFunc::**pFunc)( int, int );
    int GetArea( int x, int y );
    void CallFunc( int nState, int x, int y ) { (this->*pFunc[nState])( x, y ); }
    CFunc();
    ~CFunc();
};
CFunc::CFunc()
{
// init
    pFunc = new (int (CFunc::*[10])( int, int )); // 동적할당, 10에는 원하는 멤버함수 갯수만큼
// 0번은 남겨둔다.
    pFunc[1] = GetArea;
    pFunc[2] = GetAreaEx;
    pFunc[3] = GetArea2;
    pFunc[4] = GetArea3;
    ...
    pFunc[9] = GetArea9;
}
CFunc::~CFunc()
{
    delete [] pFunc; // 해제
}
int CFunc::GetArea( int x, int y )
{
    return x * y;
}

자, 이제 함수하나의 호출로 상황에따라 여러 멤버함수를 호출할 수 있는 기반이 마련되었다.

CFunc A;
A.CallFunc( nState, x, y );

이렇게...
어떠한가. 함수포인터의 위력이 느껴지는가?
< STL을 이용한 함수포인터 관리 >
우리는 지금까지 함수포인터를 동적으로 배열을 할당해서 써왔다.
함수 포인터를 STL(Standard Template Library)을 써서 관리해보자.
클래스의 멤버함수의 함수포인터화에서 3번째 방법을 조금 개선시켜 보겠다.
단순히 인덱스(숫자)를 이용한 관리라면 deque정도가 괜찮을듯 싶으나,
만약 함수의 이름을 문자열로 호출하고 싶다면 map을 써볼 수 있다.
(만약 FuncCall( "GetArea", x, y ); 이런식으로 멤버함수를 호출하고 싶다면)
map은 내부적으로 트리구조를 가지고 있다.
그래서 따로 정적/동적으로 배열을 할당하지 않아도 입력된 값을 비교해서 스스로 자신의 크기를 늘린다.
mapValue["GetArea"] = 99;
이런식으로 []안에 숫자 뿐만아니라 비교할 수 있는 모든 것이 들어갈 수 있다.
먼저 map을 사용하기 위해

#include < map >
using namespace std;

를 선언한다. map은 표준 네임스페이스를 사용하므로 std의 이름공간을 활용한다.
map< []안에 들어갈 타입, 입력될 데이터타입, 비교 논리 > mapFunctor;
선언방법은 이렇게 되는데 비교 논리는 첫번째 인수가 클래스이고 안에 비교오퍼레이터가 있다면 생략가능하다
자, 이제 해보자.

struct ltstr
{
    bool operator() ( const char * s1, const char * s2 ) const
    {
         return strcmp( s1, s2 ) < 0;
    }
};
class CFunc
{
public:
    typedef int (CFunc::*_Func)( int, int );
    map< const char *, _Func, ltstr > mapFunctor;
    int GetArea( int x, int y );
    void CallFunc( const char * szFuncName, int x, int y )
    {
         (this->*mapFunctor[szFuncName])( x, y );
    }
    CFunc();
    ~CFunc();
};
CFunc::CFunc()
{
// init
    mapFunctor["GetArea"] = GetArea;
    mapFunctor["GetAreaEx"] = GetAreaEx;
}
CFunc::~CFunc()
{
// map 클리어
    mapFunctor.clear();
}
int CFunc::GetArea( int x, int y )
{
    return x * y;
}

char * 대신 string을 사용한다면 string안에 내부적으로 비교 오퍼레이터함수가 있기 때문에
map< string, _Func > mapFunctor;
이렇게 선언하고 사용할 수 있을 것이다.
이제 A.CallFunc( "GetAreaEx", x, y ); 란 호출로 GetAreaEx를 호출할 수 있다.
이 방식은 여러가지로 응용가능한데 스킬명에 의한 화면효과 호출이라던지
C로 미리 작성된 내부 함수를 외부 스크립트로 호출한다던지 할때 유용하게 쓰일 수 있다.
(스크립트 호출일 경우 함수이름을 인덱스화 해서 deque를 쓰는게 속도상 더 유리할 듯 하다)
< Caution >
- 귀차니즘의 관계로 클래스내에 GetAreaEx, GetArea2 등과 같은 멤버함수를 모두 기술하지는 않았습니다.
- 예제 소스는 컴파일해보지 않은 소스들이므로 오타나 잘못된 점이 있을 수도 있습니다. 지적 바랍니다.
- VS 2005 에서 에러가 납니다만, 몇가지를 수정해주시면 제대로 됩니다.
- 이 강좌는 제가 그동안 겪고 배우고 또 여기저기서 수집한 자료를 바탕으로 쓴 강좌입니다. 틀린부분이 있을 수도 있으니
그런 부분은 지적 바랍니다.
- 글의 이동은 자유지만 출처는 명시해 주시기 바랍니다.

블로그 이미지

UART

,