0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-27 11:18:51 +02:00

ircd::resource: Replace resources map with instance_map.

This commit is contained in:
Jason Volk 2022-07-14 12:41:12 -07:00
parent 6a961e5b38
commit 378b9b3acf
3 changed files with 15 additions and 34 deletions

View file

@ -20,6 +20,7 @@ namespace ircd
/// The target of an HTTP request specified by clients with a path.
///
struct ircd::resource
:instance_map<string_view, resource, iless>
{
IRCD_EXCEPTION(ircd::error, error)
@ -31,12 +32,10 @@ struct ircd::resource
struct redirect;
static log::log log;
static std::map<string_view, resource *, iless> resources;
string_view path;
std::unique_ptr<const struct opts> opts;
std::map<string_view, method *> methods;
unique_const_iterator<decltype(resources)> resources_it;
std::unique_ptr<method> default_method_head;
std::unique_ptr<method> default_method_options;
@ -52,7 +51,8 @@ struct ircd::resource
resource(const string_view &path, struct opts);
resource(const string_view &path);
resource() = default;
resource(resource &&) = delete;
resource(const resource &) = delete;
~resource() noexcept;
static resource &find(const string_view &path);

View file

@ -8,19 +8,15 @@
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
///////////////////////////////////////////////////////////////////////////////
//
// resource/resource.h
//
decltype(ircd::resource::log)
ircd::resource::log
{
"resource", 'r'
};
decltype(ircd::resource::resources)
ircd::resource::resources
template<>
decltype(ircd::util::instance_map<ircd::string_view, ircd::resource, ircd::iless>::map)
ircd::util::instance_map<ircd::string_view, ircd::resource, ircd::iless>::map
{};
ircd::resource &
@ -31,6 +27,7 @@ ircd::resource::find(const string_view &path_)
rstrip(path_, '/')
};
auto &resources(instance_map::map);
auto it
{
resources.lower_bound(path)
@ -113,34 +110,19 @@ ircd::resource::resource(const string_view &path)
ircd::resource::resource(const string_view &path,
struct opts opts)
:path
:instance_map
{
rstrip(path, '/')
}
,path
{
instance_map::it->first
}
,opts
{
std::make_unique<const struct opts>(std::move(opts))
}
,resources_it{[this]
{
const auto iit
{
resources.emplace(this->path, this)
};
if(!iit.second)
throw error
{
"resource \"%s\" already registered", this->path
};
return unique_const_iterator<decltype(resources)>
{
resources, iit.first
};
}()}
,default_method_head{[this]
() -> std::unique_ptr<method>
,default_method_head{[this]() -> std::unique_ptr<method>
{
if(this->opts->flags & flag::OVERRIDE_HEAD)
return {};
@ -152,8 +134,7 @@ ircd::resource::resource(const string_view &path,
return std::make_unique<method>(*this, "HEAD", std::move(handler));
}()}
,default_method_options{[this]
() -> std::unique_ptr<method>
,default_method_options{[this]() -> std::unique_ptr<method>
{
if(this->opts->flags & flag::OVERRIDE_OPTIONS)
return {};

View file

@ -6910,7 +6910,7 @@ console_cmd__resource(opt &out, const string_view &line)
return true;
}
for(const auto &p : resource::resources)
for(const auto &p : resource::map)
{
const auto &r(*p.second);
for(const auto &mp : p.second->methods)