#ifndef __URLROUTERPRIVATE_H__ #define __URLROUTERPRIVATE_H__ #include "TemplateSegmentRule.h" #include #include #include class AnyResource { public: virtual ~AnyResource() = default; virtual void const *get() const noexcept = 0; }; class ChildIndexVector { static constexpr std::size_t N = 5; public: bool empty() const; std::size_t size() const; std::size_t *begin(); const std::size_t *begin() const; std::size_t *end(); const std::size_t *end() const; void erase(std::size_t *it); void push_back(std::size_t v); private: std::size_t m_capcity{0}; std::size_t m_size{0}; std::size_t *m_childIndexes{nullptr}; std::size_t m_staticChildIndexes[N]{}; }; class SegementNode { public: static constexpr std::size_t npos{std::size_t(-1)}; std::size_t parentIndex{npos}; ChildIndexVector childIndexes; TemplateSegment segment; std::string templatePath; std::shared_ptr resource; }; class UrlRouterPrivate { public: UrlRouterPrivate(); void insertImpl(boost::urls::string_view pattern, const std::shared_ptr &resource); const AnyResource *findImpl(boost::urls::segments_encoded_view path, boost::urls::string_view *&matches, boost::urls::string_view *&ids) const noexcept; protected: SegementNode const *tryMatch(boost::urls::segments_encoded_view::const_iterator it, boost::urls::segments_encoded_view::const_iterator end, const SegementNode *current, int level, boost::urls::string_view *&matches, boost::urls::string_view *&ids) const; static SegementNode const *findOptionalResource(const SegementNode *root, std::vector const &ns, boost::urls::string_view *&matches, boost::urls::string_view *&ids); private: std::vector m_nodes; }; #endif // __URLROUTERPRIVATE_H__