C++ - Windows 텍스트 인코딩 변환

Ansi <-> UTF-8 std::string CGlobal::ToUFT8( const char* pszIn ) { std::string resultString; int nLenOfUni = 0, nLenOfUTF = 0; wchar_t* us = NULL; char* pszOut = NULL; if ( ( nLenOfUni = MultiByteToWideChar( CP_ACP, 0, pszIn, strlen(pszIn), NULL, 0)) <=...
더 읽기

참, 거짓을 반환 하는 함수의 네이밍

참 거짓 값(Boolean, bool)을 반환하는 함수는 is로 시작하는 것이 일반적이라고 생각한다. 적어도 C++ 에서는… 그러나 영어적으로 is 시작이 어려운 경우도 있다. is로 시작할 수 없는 함수 이름의 명명 방식을 생각해 봤다. 존재 하는가? 가장 하기 쉬운 실패가 “존재할까?”를 is에서 시작...
더 읽기

좋은 함수 이름을 짓기 위한 참고 정보

참 거짓을 돌려주는 메소드 장소 단어 의미 예 Prefix is (오브제그트가)대기 하는 상태가 되어 있나? isChecked Prefix can (오브제그트가)기대하는 동작을 할 수 있나? canRemove Prefix should (호출 측이)어떤 명령을 실행한쪽이 좋나 shouldMigrate Prefix has (오브제그트가)기대하는 데이터 프로퍼티를 가지고 있나? hasObservers...
더 읽기

좋은 클래스 이름을 짓기 위한 참고 정보

데이터 소스를 취급하는 레이어 이름 보충 예 Client HttpClient 등 Server-Client 의미로 사용하는 TwitterApiClient, QiitaApiClient Gateway API를 요청하기 위한 게이트 웨이로서 TwitterTimelineGateway, QiitaAccountGateway Store, Storage, Registry DB를 요청하거나 Disk I/O에 의한 데이터 영속화를 하는 부분에 이용 FavoriteSettingStore, DataStorage, ConfigRegistry Cache...
더 읽기

이름 붙이기

메소드 이름은 동사로 시작한다 동사 이름 한글 표현 주된 반환 값 Get 취득하다 객체 Set 설정하다 void Update 갱신하다 void(update한 건수 돌려줄 경우도) Delete 삭제하다 void(delete한 건수 돌려줄 경우도) Insert 삽입하다 void Select 선택하다 객체 Find 선택하다 객체 Add 추가하다...
더 읽기

epoll을 사용한 echo 서버

출처 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <sys/socket.h> #include <sys/types.h> #include <sys/epoll.h> #include <netinet/in.h> #define SERVER_PORT 10007 #define MAX_EVENTS 10 #define BACKLOG 10 static int listener; static int epfd; static void die(const char* msg) {...
더 읽기

C++ - STL function, lambda, bind 사용 예

/* * std_function1.cpp * Copyright (C) 2014 kaoru <kaoru@bsd> */ #include <iostream> #include <functional> using namespace std; struct Foo { Foo(const int n) : i_(n) {} void print_add(const int n) const { std::cout << i_ + n<< std::endl; } int...
더 읽기

C++ - STL map에 함수 포인터 사용

#include <iostream> #include <map> #include <string> double Add(double a, double b){ return a + b; } double Sub(double a, double b){ return a - b; } double Mul(double a, double b){ return a * b; } double Div(double a, double...
더 읽기

C++ - 컴퓨터의 실제 IP 얻기 (code)

#include <ws2tcpip.h> bool ServerInfoMgr::GetLocalIP( string& strIP ) { char host_name[256]; if (gethostname(host_name, 256) == SOCKET_ERROR) return false; struct addrinfo hints, *res = NULL; char *szRemoteAddress=NULL, *szRemotePort=NULL; int rc; memset( &hints, 0, sizeof(hints) ); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol...
더 읽기