구현 | Libft
새롭게 정의한 함수들
libft에서 따로 설명이 필요한, 새로 정의한 함수들은 다음과 같습니다.
int free(void *ptr);
int freeStr(char **str);
int freeDoublestr(char ***doublestr_addr);댕글링 포인터를 만들지 않는 safety free를 위해 free 함수들을 만들어서 사용합니다.
char *strsjoin(std::string s1 = "", std::string s2 = "", std::string s3 = "", std::string s4 = "", std::string s5 = "");string 인자들을 합쳐 char pointer로 바꾸는 작업은 cgi 환경변수 세팅을 위해 디자인했습니다.
std::set<std::string> stringVectorToSet(std::vector<std::string> stringVector);
std::map<std::string, std::string> stringVectorToMap(std::vector<std::string> stringVector, char sep = ':');
std::string containerToString(std::vector<unsigned char> container, std::string sep = "");스플릿한 벡터를 셋이나 맵으로 변환해야 할 때가 많고, 반대로 vector, set, map을 하나의 문자열로 병합해서 사용해야 할 일들도 있습니다.
int getline(int fd, char *line, int max_buffer_size);
int getline(std::string& data, std::string& line, size_t max_buffer_size);
int getline(std::string& data, std::string& line);
int getline(std::string& data, int& readed_size, std::string& line);getline 같은 경우 시행착오를 겪는 과정에서 여러 개를 만들어서 오버로딩을 했지만, 서브젝트 요건에 맞춰 코드를 다듬다보니 1~2개 밖에 쓰지 않았습니다.
template <typename T, typename V>
bool hasKey(T container, V value);코드를 짧게 줄이고 가독적으로 사용하기 위해 key의 존재만 확인하는 템플릿 함수를 정의했습니다.
Libft.hpp
저희가 Mandatory part에서 사용한 libft의 헤더 파일은 다음과 같습니다.
Last updated
Was this helpful?