mergerfs/src/state.cpp
trapexit 6ac7f389c5
Some checks are pending
CodeQL / Analyze (push) Waiting to run
mkdocs / deploy (push) Waiting to run
Misc changes (#1513)
* Start moving to string_view where possible
* Rework readdir object to use atomic load/store
2025-08-21 22:42:58 -05:00

66 lines
1.1 KiB
C++

#include "state.hpp"
#include "fmt/core.h"
#include "errno.hpp"
State state;
// static
// void
// _register_getattr(State *state_)
// {
// State::GetSet x;
// x.get = [state_]() -> std::string
// {
// return state_->getattr.to_string();
// };
// x.set = [state_](const std::string_view s_) -> int
// {
// return state_->getattr.from_string(s_);
// };
// state_->set_getset("user.mergerfs.func.getattr",x);
// }
State::State()
{
// _register_getattr(this);
}
void
State::set_getset(const std::string &name_,
const State::GetSet &gs_)
{
_getset[name_] = gs_;
}
int
State::get(const std::string &key_,
std::string &val_)
{
std::map<std::string,State::GetSet>::iterator i;
i = _getset.find(key_);
if((i == _getset.end()) || (!i->second.get))
return -ENOATTR;
val_ = i->second.get();
return 0;
}
int
State::set(const std::string &key_,
const std::string_view val_)
{
std::map<std::string,State::GetSet>::iterator i;
i = _getset.find(key_);
if((i == _getset.end()) || (!i->second.set))
return -ENOATTR;
return i->second.set(val_);
}