티스토리 뷰

실전

템플릿 코드 생성 프로그램

Just4Fun 2024. 6. 7. 18:41

제법 규모가 있는 프로젝트의 경우 수많은 소스코드로 이루어져 있다.  비단 큰 프로젝트가 아니더라도 새로운 코드를 작성할 때 완전히 빈 화면에서부터 시작하여야 한다.

이런 경우 그냥 빈화면 보다는 뭔가 미리 필요한 내용이 기본으로 들어가 있으면 전체적인 코드의 모양도 일관성 있게되고 여러명의 개발자가 공동으로 작업하게 되더라도 이질감 없이 코드를 공유하기가 쉬워진다.

이번 글에서는 코드 확장자에 맞는 기본 템플릿 코드를 만드는 방법을 공유하고자 한다.

code generator

위의 그림은 d:\work\c\tmp 디렉토리에 hello.h hello.cpp 파일을 생성해주는 경우이다.  cpp의 경우 class까지 같이 생성해 주려면 class name도 입력해주면 된다.

위와 같이 선택한 다음 Create 버튼을 눌러주면 다음과 같은 파일이 생성된다.

/*==============================================================================
Copyright (c) 2024, Just4Fun

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this 
   list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, 
   this list of conditions and the following disclaimer in the documentation 
   and/or other materials provided with the distribution.

3. Neither the name of the Just4Fun nor the names of its contributors may be 
   used to endorse or promote products derived from this software without 
   specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

$Id: $
==============================================================================*/

#ifndef _HELLO_H_
#define _HELLO_H_

class Helloclass
{
public:
    Helloclass();
    ~Helloclass();
};

#endif /* _HELLO_H_ */

// vim:ts=8:sts=4:sw=4:et:

hello.h

 

/* HELLO.CPP */
/*==============================================================================
Copyright (c) 2024, Just4Fun

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this 
   list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, 
   this list of conditions and the following disclaimer in the documentation 
   and/or other materials provided with the distribution.

3. Neither the name of the Just4Fun nor the names of its contributors may be 
   used to endorse or promote products derived from this software without 
   specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

$Id: $
==============================================================================*/

/*------------------------------------------------------------------------------
    HEADER FILE INCLUDE
------------------------------------------------------------------------------*/
#include <>

#include "hello.h"

/*------------------------------------------------------------------------------
    TYPEDEF & MACROS
------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------
    FUNCTION PROTOTYPES
------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------
    EXTERNAL VARIABLES
------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------
    LOCAL VARIABLES
------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------
    LOCAL FUNCTIONS
------------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------
    EXTERNAL FUNCTIONS
------------------------------------------------------------------------------*/

Helloclass::Helloclass()
{
}

Helloclass::~Helloclass()
{
}


// vim:ts=8:sts=4:sw=4:et:

 hello.cpp

 

헤더파일에는 HelloClass라는 class의 원형이 선언되어 있고, cpp 파일에는 실제 class의 생성자와 소멸자가 기본으로 들어가 있는것을 볼 수 있다.

code generator는 python으로 간단하게 만들었는데 필요한 경우 java나 python 코드 생성 기능을 추가하면 된다.

code_gen.py
0.01MB

'실전' 카테고리의 다른 글

빌드 버전과 시간 정보 추가  (0) 2024.06.01
cmake를 이용한 AVR 개발 환경  (0) 2024.05.28
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
TAG
more
«   2024/12   »
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
글 보관함