Electroneum
common.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 #include <string>
5 #include <stdexcept>
6 #include <iostream>
7 #include "utility.h"
8 
9 namespace crow
10 {
11  enum class HTTPMethod
12  {
13 #ifndef DELETE
14  DELETE = 0,
15  GET,
16  HEAD,
17  POST,
18  PUT,
19  CONNECT,
20  OPTIONS,
21  TRACE,
22 #endif
23 
24  Delete = 0,
25  Get,
26  Head,
27  Post,
28  Put,
29  Connect,
30  Options,
31  Trace,
32  };
33 
34  inline std::string method_name(HTTPMethod method)
35  {
36  switch(method)
37  {
38  case HTTPMethod::Delete:
39  return "DELETE";
40  case HTTPMethod::Get:
41  return "GET";
42  case HTTPMethod::Head:
43  return "HEAD";
44  case HTTPMethod::Post:
45  return "POST";
46  case HTTPMethod::Put:
47  return "PUT";
49  return "CONNECT";
51  return "OPTIONS";
52  case HTTPMethod::Trace:
53  return "TRACE";
54  }
55  return "invalid";
56  }
57 
58  enum class ParamType
59  {
60  INT,
61  UINT,
62  DOUBLE,
63  STRING,
64  PATH,
65 
66  MAX
67  };
68 
70  {
71  std::vector<int64_t> int_params;
72  std::vector<uint64_t> uint_params;
73  std::vector<double> double_params;
74  std::vector<std::string> string_params;
75 
76  void debug_print() const
77  {
78  std::cerr << "routing_params" << std::endl;
79  for(auto i:int_params)
80  std::cerr<<i <<", " ;
81  std::cerr<<std::endl;
82  for(auto i:uint_params)
83  std::cerr<<i <<", " ;
84  std::cerr<<std::endl;
85  for(auto i:double_params)
86  std::cerr<<i <<", " ;
87  std::cerr<<std::endl;
88  for(auto& i:string_params)
89  std::cerr<<i <<", " ;
90  std::cerr<<std::endl;
91  }
92 
93  template <typename T>
94  T get(unsigned) const;
95 
96  };
97 
98  template<>
99  inline int64_t routing_params::get<int64_t>(unsigned index) const
100  {
101  return int_params[index];
102  }
103 
104  template<>
105  inline uint64_t routing_params::get<uint64_t>(unsigned index) const
106  {
107  return uint_params[index];
108  }
109 
110  template<>
111  inline double routing_params::get<double>(unsigned index) const
112  {
113  return double_params[index];
114  }
115 
116  template<>
117  inline std::string routing_params::get<std::string>(unsigned index) const
118  {
119  return string_params[index];
120  }
121 }
122 
123 #ifndef CROW_MSVC_WORKAROUND
124 constexpr crow::HTTPMethod operator "" _method(const char* str, size_t /*len*/)
125 {
126  return
135  throw std::runtime_error("invalid http method");
136 }
137 #endif
void debug_print() const
Definition: common.h:76
const uint32_t T[512]
Definition: groestl_tables.h:34
std::vector< double > double_params
Definition: common.h:73
ParamType
Definition: common.h:58
std::vector< uint64_t > uint_params
Definition: common.h:72
Definition: common.h:69
constexpr bool is_equ_p(const char *a, const char *b, unsigned n)
Definition: utility.h:70
std::vector< int64_t > int_params
Definition: common.h:71
Definition: ci_map.h:7
std::vector< std::string > string_params
Definition: common.h:74
std::string method_name(HTTPMethod method)
Definition: common.h:34
HTTPMethod
Definition: common.h:11