crow
현재 수정 진행중인 문서입니다!
목차
- routing
- Middleware
- 서버구조
- black_magic
https://www.youtube.com/watch?v=MixS9c3mE6U 참고 자료
Routing
Sample Code about rout
int main()
{
CROW_ROUTE(app, "/");
}
- Url->Routing Rule
get_parameter_tag("/<int>/<int>")
-> arguments<11>
-> S<int, int>
-> TaggedRule<int, int>
- get_parameter_tag
URL 스트링을 받아 인자 정보를 가지는 6진수로 표현
0 : <>(empty), 1 : int, 3 : double, 4 : string , 5 : string(path)
E.g.
13 -> <double, int>
4 -> <string>
5 -> <string>
black_magic
black_maginc::S<T..>
tuple자료형을 쓸 수도 있었지만 variadic templates으로 타입 리스트 구현
S<int, double, string>
같은 자료형이 가능하다
S<a, b>::push(c) === S&<c, a, b>
자료형에 새로운 타입 추가,
S<a>::push_back<b> === S<a,b>
push_back을 이용해 맨 뒤에 타입추가,
S<a, b, c>::rebind<Rule> === Rule<a,b,c>
S를 이용해 Rule을 리바인드 시켜줌
다음과 같은 구현이 가능함
crow_all.h in line 5515
- push 구현
S<a, b>::push(c) === S<c, a, b>
와 같은 상황 일 때 template<typename ... T>
struct S{
template<typename U>
using push = S<U, T...>;
}
rebind 구현
S<a, b, c>::rebind<Rule> == Rule<a,b,c>
와 같은 상황 일 때
template
<template <typename ...> class U>
using rebind = U<T...>;
black_magic::argument<uint64_t>
argument 구현
template<uint64_t Tag> struct arguments {
using subarg = typename arguments<Tag/6>::type;
using type =
typename subargs::template push<typename single_tag_to_type<Tag%6>::type>;
};
single_tag_to_type 구현
template<int N>
struct single_tag_to_type{};
template<>
struct single_tag_to_type<1>{
using type = int64_t;
};
template<>
struct argument<0> {
using type = s<>;
}
Partial template specialization
해석하면 부분적 템플릿 특수화 정도? 특정한 경우(template인자로 특정 값이 들어올 경우) 특수화를 별도로 시켜줌
사용된 C++11
Const expr example
constexpr int fact(int n)
{
return (n < =1)
? 1 : fact(n-1)*n;
}
int main()
{
char arr[fact(5)];
}
using이 많이 나와서 EMC++ 참조
typedef
std::unique_ptr<std::unordered_map<std::string, std::string>>
UPtrMapSS;
using UPtrMapSS =
std::unique_ptr<std::unordered_map<std::string, std::string>>;