blob: 77db63c694051ddd4fbb2fa1de429d0936e35318 [file] [log] [blame]
Ed Tanous7045c8d2017-04-03 10:04:37 -07001#pragma once
2
Gunnar Mills1214b7e2020-06-04 10:11:30 -05003#include "utility.h"
4
Ed Tanous1abe55e2018-09-05 08:30:59 -07005#include <boost/beast/http/verb.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -05006
Ed Tanous7045c8d2017-04-03 10:04:37 -07007#include <iostream>
8#include <stdexcept>
9#include <string>
10#include <vector>
Ed Tanous7045c8d2017-04-03 10:04:37 -070011
Ed Tanous1abe55e2018-09-05 08:30:59 -070012namespace crow
13{
Ed Tanous7045c8d2017-04-03 10:04:37 -070014
Ed Tanous1abe55e2018-09-05 08:30:59 -070015inline std::string methodName(boost::beast::http::verb method)
16{
17 switch (method)
18 {
19 case boost::beast::http::verb::delete_:
20 return "DELETE";
21 case boost::beast::http::verb::get:
22 return "GET";
23 case boost::beast::http::verb::head:
24 return "HEAD";
25 case boost::beast::http::verb::post:
26 return "POST";
27 case boost::beast::http::verb::put:
28 return "PUT";
29 case boost::beast::http::verb::connect:
30 return "CONNECT";
31 case boost::beast::http::verb::options:
32 return "OPTIONS";
33 case boost::beast::http::verb::trace:
34 return "TRACE";
35 case boost::beast::http::verb::patch:
36 return "PATCH";
Ed Tanous43b761d2019-02-13 20:10:56 -080037 default:
38 return "invalid";
Ed Tanous1abe55e2018-09-05 08:30:59 -070039 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070040}
41
Ed Tanous1abe55e2018-09-05 08:30:59 -070042enum class ParamType
43{
44 INT,
45 UINT,
46 DOUBLE,
47 STRING,
48 PATH,
Ed Tanous7045c8d2017-04-03 10:04:37 -070049
Ed Tanous1abe55e2018-09-05 08:30:59 -070050 MAX
Ed Tanous7045c8d2017-04-03 10:04:37 -070051};
52
Ed Tanous1abe55e2018-09-05 08:30:59 -070053struct RoutingParams
54{
55 std::vector<int64_t> intParams;
56 std::vector<uint64_t> uintParams;
57 std::vector<double> doubleParams;
58 std::vector<std::string> stringParams;
Ed Tanous7045c8d2017-04-03 10:04:37 -070059
Ed Tanous1abe55e2018-09-05 08:30:59 -070060 void debugPrint() const
61 {
62 std::cerr << "RoutingParams" << std::endl;
63 for (auto i : intParams)
64 {
65 std::cerr << i << ", ";
66 }
67 std::cerr << std::endl;
68 for (auto i : uintParams)
69 {
70 std::cerr << i << ", ";
71 }
72 std::cerr << std::endl;
73 for (auto i : doubleParams)
74 {
75 std::cerr << i << ", ";
76 }
77 std::cerr << std::endl;
78 for (auto& i : stringParams)
79 {
80 std::cerr << i << ", ";
81 }
82 std::cerr << std::endl;
Borawski.Lukaszc3313442018-01-19 13:54:19 +010083 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070084
Gunnar Mills1214b7e2020-06-04 10:11:30 -050085 template <typename T>
86 T get(unsigned) const;
Ed Tanous7045c8d2017-04-03 10:04:37 -070087};
88
Gunnar Mills1214b7e2020-06-04 10:11:30 -050089template <>
90inline int64_t RoutingParams::get<int64_t>(unsigned index) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070091{
92 return intParams[index];
93}
94
Gunnar Mills1214b7e2020-06-04 10:11:30 -050095template <>
96inline uint64_t RoutingParams::get<uint64_t>(unsigned index) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070097{
98 return uintParams[index];
99}
100
Gunnar Mills1214b7e2020-06-04 10:11:30 -0500101template <>
102inline double RoutingParams::get<double>(unsigned index) const
Ed Tanous1abe55e2018-09-05 08:30:59 -0700103{
104 return doubleParams[index];
Ed Tanous7045c8d2017-04-03 10:04:37 -0700105}
106
107template <>
Ed Tanous1abe55e2018-09-05 08:30:59 -0700108inline std::string RoutingParams::get<std::string>(unsigned index) const
109{
110 return stringParams[index];
Ed Tanous7045c8d2017-04-03 10:04:37 -0700111}
112
Ed Tanous1abe55e2018-09-05 08:30:59 -0700113} // namespace crow