11#pragma once
22
33#include < cstdint>
4+ #include < limits>
45#include < utility>
56#include < tuple>
67#include < unordered_map>
2324namespace crow // NOTE: Already documented in "crow/app.h"
2425{
2526
26- constexpr const uint16_t INVALID_BP_ID{(( uint16_t )- 1 ) };
27+ constexpr size_t INVALID_BP_ID{SIZE_MAX };
2728
2829namespace detail
2930 {
@@ -718,7 +719,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
718719 std::function<void (crow::request&, crow::response&, Args...)> handler_;
719720 };
720721
721- const int RULE_SPECIAL_REDIRECT_SLASH =1 ;
722+ constexpr size_t RULE_SPECIAL_REDIRECT_SLASH =1 ;
722723
723724
724725// / A search tree.
@@ -727,9 +728,9 @@ namespace crow // NOTE: Already documented in "crow/app.h"
727728public:
728729struct Node
729730 {
730- uint16_t rule_index{};
731+ size_t rule_index{};
731732// Assign the index to the maximum 32 unsigned integer value by default so that any other number (specifically 0) is a valid BP id.
732- uint16_t blueprint_index{INVALID_BP_ID};
733+ size_t blueprint_index{INVALID_BP_ID};
733734 std::string key;
734735 ParamType param = ParamType::MAX;// MAX = No param.
735736 std::vector<Node> children;
@@ -852,19 +853,19 @@ namespace crow // NOTE: Already documented in "crow/app.h"
852853 }
853854
854855// Rule_index, Blueprint_index, routing_params
855- routing_handle_resultfind (const std::string& req_url,const Node& node,unsigned pos =0 , routing_params* params =nullptr , std::vector<uint16_t >* blueprints =nullptr )const
856+ routing_handle_resultfind (const std::string& req_url,const Node& node,size_t pos =0 , routing_params* params =nullptr , std::vector<size_t >* blueprints =nullptr )const
856857 {
857858// start params as an empty struct
858859 routing_params empty;
859860if (params ==nullptr )
860861 params = ∅
861862// same for blueprint vector
862- std::vector<uint16_t > MT;
863+ std::vector<size_t > MT;
863864if (blueprints ==nullptr )
864865 blueprints = &MT;
865866
866- uint16_t found{};// The rule index to be found
867- std::vector<uint16_t > found_BP;// The Blueprint indices to be found
867+ size_t found{};// The rule index to be found
868+ std::vector<size_t > found_BP;// The Blueprint indices to be found
868869 routing_params match_params;// supposedly the final matched parameters
869870
870871auto update_found = [&found, &found_BP, &match_params](routing_handle_result& ret) {
@@ -1016,7 +1017,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
10161017 }
10171018
10181019// This functions assumes any blueprint info passed is valid
1019- void add (const std::string& url,uint16_t rule_index,unsigned bp_prefix_length =0 ,uint16_t blueprint_index = INVALID_BP_ID)
1020+ void add (const std::string& url,size_t rule_index,unsigned bp_prefix_length =0 ,size_t blueprint_index = INVALID_BP_ID)
10201021 {
10211022auto idx = &head_;
10221023
@@ -1301,7 +1302,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
13011302internal_add_rule_object (rule, ruleObject, INVALID_BP_ID, blueprints_);
13021303 }
13031304
1304- void internal_add_rule_object (const std::string& rule, BaseRule* ruleObject,const uint16_t & BP_index, std::vector<Blueprint*>& blueprints)
1305+ void internal_add_rule_object (const std::string& rule, BaseRule* ruleObject,const size_t & BP_index, std::vector<Blueprint*>& blueprints)
13051306 {
13061307bool has_trailing_slash =false ;
13071308 std::string rule_without_trailing_slash;
@@ -1434,7 +1435,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
14341435
14351436auto & per_method = per_methods_[static_cast <int >(req.method )];
14361437auto & rules = per_method.rules ;
1437- unsigned rule_index = per_method.trie .find (req.url ).rule_index ;
1438+ size_t rule_index = per_method.trie .find (req.url ).rule_index ;
14381439
14391440if (!rule_index)
14401441 {
@@ -1483,7 +1484,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
14831484 }
14841485 }
14851486
1486- void get_found_bp (const std::vector<uint16_t >& bp_i,const std::vector<Blueprint*>& blueprints, std::vector<Blueprint*>& found_bps,uint16_t index =0 )
1487+ void get_found_bp (const std::vector<size_t >& bp_i,const std::vector<Blueprint*>& blueprints, std::vector<Blueprint*>& found_bps,size_t index =0 )
14871488 {
14881489// This statement makes 3 assertions:
14891490// 1. The index is above 0.
@@ -1529,7 +1530,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
15291530get_found_bp (found.blueprint_indices , blueprints_, bps_found);
15301531for (int i = bps_found.size () -1 ; i >0 ; i--)
15311532 {
1532- std::vector<uint16_t > bpi = found.blueprint_indices ;
1533+ std::vector<size_t > bpi = found.blueprint_indices ;
15331534if (bps_found[i]->catchall_rule ().has_handler ()) {
15341535return bps_found[i]->catchall_rule ();
15351536 }
@@ -1545,7 +1546,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
15451546get_found_bp (found.blueprint_indices , blueprints_, bps_found);
15461547for (int i = bps_found.size () -1 ; i >0 ; i--)
15471548 {
1548- std::vector<uint16_t > bpi = found.blueprint_indices ;
1549+ std::vector<size_t > bpi = found.blueprint_indices ;
15491550if (bps_found[i]->catchall_rule ().has_handler ())
15501551 {
15511552#ifdef CROW_ENABLE_DEBUG
@@ -1573,7 +1574,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
15731574 std::unique_ptr<routing_handle_result> found{
15741575new routing_handle_result (
157515760 ,
1576- std::vector<uint16_t >(),
1577+ std::vector<size_t >(),
15771578routing_params (),
15781579 HTTPMethod::InternalMethodCount)};// This is always returned to avoid a null pointer dereference.
15791580
@@ -1715,7 +1716,7 @@ namespace crow // NOTE: Already documented in "crow/app.h"
17151716 }else {
17161717 HTTPMethod method_actual = found.method ;
17171718const auto & rules = per_methods_[static_cast <int >(method_actual)].rules ;
1718- const unsigned rule_index = found.rule_index ;
1719+ const size_t rule_index = found.rule_index ;
17191720
17201721if (rule_index >= rules.size ())
17211722throw std::runtime_error (" Trie internal structure corrupted!" );