blob: 6f6b24c0aeee35387511f149b43ee8f35bf6123b [file] [log] [blame]
Ed Tanous7045c8d2017-04-03 10:04:37 -07001#pragma once
2
Ed Tanous04e438c2020-10-03 08:06:26 -07003#include "utility.hpp"
Gunnar Mills1214b7e2020-06-04 10:11:30 -05004
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 -070015enum class ParamType
16{
17 INT,
18 UINT,
19 DOUBLE,
20 STRING,
21 PATH,
Ed Tanous7045c8d2017-04-03 10:04:37 -070022
Ed Tanous1abe55e2018-09-05 08:30:59 -070023 MAX
Ed Tanous7045c8d2017-04-03 10:04:37 -070024};
25
Ed Tanous1abe55e2018-09-05 08:30:59 -070026struct RoutingParams
27{
28 std::vector<int64_t> intParams;
29 std::vector<uint64_t> uintParams;
30 std::vector<double> doubleParams;
31 std::vector<std::string> stringParams;
Ed Tanous7045c8d2017-04-03 10:04:37 -070032
Ed Tanous1abe55e2018-09-05 08:30:59 -070033 void debugPrint() const
34 {
35 std::cerr << "RoutingParams" << std::endl;
36 for (auto i : intParams)
37 {
38 std::cerr << i << ", ";
39 }
40 std::cerr << std::endl;
41 for (auto i : uintParams)
42 {
43 std::cerr << i << ", ";
44 }
45 std::cerr << std::endl;
46 for (auto i : doubleParams)
47 {
48 std::cerr << i << ", ";
49 }
50 std::cerr << std::endl;
51 for (auto& i : stringParams)
52 {
53 std::cerr << i << ", ";
54 }
55 std::cerr << std::endl;
Borawski.Lukaszc3313442018-01-19 13:54:19 +010056 }
Ed Tanous7045c8d2017-04-03 10:04:37 -070057
Gunnar Mills1214b7e2020-06-04 10:11:30 -050058 template <typename T>
59 T get(unsigned) const;
Ed Tanous7045c8d2017-04-03 10:04:37 -070060};
61
Gunnar Mills1214b7e2020-06-04 10:11:30 -050062template <>
63inline int64_t RoutingParams::get<int64_t>(unsigned index) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070064{
65 return intParams[index];
66}
67
Gunnar Mills1214b7e2020-06-04 10:11:30 -050068template <>
69inline uint64_t RoutingParams::get<uint64_t>(unsigned index) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070070{
71 return uintParams[index];
72}
73
Gunnar Mills1214b7e2020-06-04 10:11:30 -050074template <>
75inline double RoutingParams::get<double>(unsigned index) const
Ed Tanous1abe55e2018-09-05 08:30:59 -070076{
77 return doubleParams[index];
Ed Tanous7045c8d2017-04-03 10:04:37 -070078}
79
80template <>
Ed Tanous1abe55e2018-09-05 08:30:59 -070081inline std::string RoutingParams::get<std::string>(unsigned index) const
82{
83 return stringParams[index];
Ed Tanous7045c8d2017-04-03 10:04:37 -070084}
85
Ed Tanous1abe55e2018-09-05 08:30:59 -070086} // namespace crow