mergerfs/src/func_wrapper.hpp
Antonio SJ Musumeci b3b8e793f9 Change getattr and statx to bespoke policies
* Provides: slight improvement in performance as it no longer will
need to find and then act on the files.
* It doesn't make sense to support all original policy types. Most
people used 'newest' or 'ff' and 'combine' is a better default which
has same runtime as 'newest' but with better output.
2025-12-27 22:14:56 -06:00

55 lines
910 B
C++

#pragma once
#include "atomicsharedptr.hpp"
#include "tofrom_string.hpp"
#include <string>
#include <string_view>
#include <cassert>
template<typename BaseType,
typename FactoryType,
typename ReturnType,
typename... Args>
class FuncWrapper : public ToFromString
{
private:
AtomicSharedPtr<BaseType> _impl;
public:
explicit FuncWrapper(const std::string &name_)
{
_impl.store(FactoryType::make(name_));
assert(not _impl.is_null());
}
public:
ReturnType
operator()(Args&&... args)
{
return _impl(std::forward<Args>(args)...);
//return _impl(args...);
}
public:
std::string
to_string() const
{
return std::string{_impl.load()->name()};
}
int
from_string(const std::string_view str_)
{
std::shared_ptr<BaseType> p;
p = FactoryType::make(str_);
if(!p)
return -EINVAL;
_impl.store(p);
return 0;
}
};