Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 3 | #include "utility.h" |
| 4 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 5 | #include <boost/beast/http/verb.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 6 | |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 7 | #include <iostream> |
| 8 | #include <stdexcept> |
| 9 | #include <string> |
| 10 | #include <vector> |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 11 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 12 | namespace crow |
| 13 | { |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 14 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 15 | inline 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 Tanous | 43b761d | 2019-02-13 20:10:56 -0800 | [diff] [blame] | 37 | default: |
| 38 | return "invalid"; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 39 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 42 | enum class ParamType |
| 43 | { |
| 44 | INT, |
| 45 | UINT, |
| 46 | DOUBLE, |
| 47 | STRING, |
| 48 | PATH, |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 49 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 50 | MAX |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 53 | struct 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 Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 59 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 60 | 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.Lukasz | c331344 | 2018-01-19 13:54:19 +0100 | [diff] [blame] | 83 | } |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 84 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 85 | template <typename T> |
| 86 | T get(unsigned) const; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 89 | template <> |
| 90 | inline int64_t RoutingParams::get<int64_t>(unsigned index) const |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 91 | { |
| 92 | return intParams[index]; |
| 93 | } |
| 94 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 95 | template <> |
| 96 | inline uint64_t RoutingParams::get<uint64_t>(unsigned index) const |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 97 | { |
| 98 | return uintParams[index]; |
| 99 | } |
| 100 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 101 | template <> |
| 102 | inline double RoutingParams::get<double>(unsigned index) const |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 103 | { |
| 104 | return doubleParams[index]; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | template <> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 108 | inline std::string RoutingParams::get<std::string>(unsigned index) const |
| 109 | { |
| 110 | return stringParams[index]; |
Ed Tanous | 7045c8d | 2017-04-03 10:04:37 -0700 | [diff] [blame] | 111 | } |
| 112 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 113 | } // namespace crow |