Kylin/HttpProxy/TemplateMatchs.h

58 lines
1.4 KiB
C
Raw Normal View History

2023-07-21 15:28:59 +08:00
#ifndef __TEMPLATEMATCHS_H__
#define __TEMPLATEMATCHS_H__
#include <boost/url/string_view.hpp>
class TemplateMatchStorageBase {
public:
2023-12-30 00:03:40 +08:00
using const_reference = boost::core::string_view const &;
2023-07-21 15:28:59 +08:00
2023-12-30 00:03:40 +08:00
virtual boost::core::string_view *matches() = 0;
virtual const boost::core::string_view *matches() const = 0;
2023-07-21 15:28:59 +08:00
2023-12-30 00:03:40 +08:00
virtual boost::core::string_view *ids() = 0;
virtual const boost::core::string_view *ids() const = 0;
2023-07-21 15:28:59 +08:00
virtual std::size_t size() const = 0;
virtual void resize(std::size_t) = 0;
2023-12-30 00:03:40 +08:00
const_reference at(boost::core::string_view id) const;
2023-07-21 15:28:59 +08:00
2023-12-30 00:03:40 +08:00
const_reference operator[](boost::core::string_view id) const;
2023-07-21 15:28:59 +08:00
};
template <std::size_t N = 20>
class TemplateMatchStorage : public TemplateMatchStorageBase {
public:
2023-12-30 00:03:40 +08:00
boost::core::string_view *matches() final {
2023-07-21 15:28:59 +08:00
return m_matches;
}
2023-12-30 00:03:40 +08:00
virtual const boost::core::string_view *matches() const final {
2023-07-21 15:28:59 +08:00
return m_matches;
}
2023-12-30 00:03:40 +08:00
boost::core::string_view *ids() final {
2023-07-21 15:28:59 +08:00
return m_ids;
}
2023-12-30 00:03:40 +08:00
const boost::core::string_view *ids() const final {
2023-07-21 15:28:59 +08:00
return m_ids;
}
std::size_t size() const final {
return m_size;
}
void resize(std::size_t n) final {
m_size = n;
}
private:
2023-12-30 00:03:40 +08:00
boost::core::string_view m_matches[N];
boost::core::string_view m_ids[N];
2023-07-21 15:28:59 +08:00
std::size_t m_size;
};
using TemplateMatches = TemplateMatchStorage<20>;
#endif // __TEMPLATEMATCHS_H__