*: update for for mu-maildir changes

Update the dependencies.
This commit is contained in:
Dirk-Jan C. Binnema
2022-02-16 23:03:48 +02:00
parent abd2a4a8f1
commit 4eabf1a64a
7 changed files with 424 additions and 401 deletions

View File

@ -126,48 +126,48 @@ wrong_type(Sexp::Type expected, Sexp::Type got)
to_string(got).c_str());
}
const std::string&
Command::get_string_or(const Parameters& params, const std::string& argname, const std::string& alt)
std::optional<std::string>
Command::get_string(const Parameters& params, const std::string& argname)
{
const auto it = find_param_node(params, argname);
if (it == params.end() || it->is_nil())
return alt;
return std::nullopt;
else if (!it->is_string())
throw wrong_type(Sexp::Type::String, it->type());
else
return it->value();
}
const std::string&
Command::get_symbol_or(const Parameters& params, const std::string& argname, const std::string& alt)
std::optional<std::string>
Command::get_symbol(const Parameters& params, const std::string& argname)
{
const auto it = find_param_node(params, argname);
if (it == params.end() || it->is_nil())
return alt;
return std::nullopt;
else if (!it->is_symbol())
throw wrong_type(Sexp::Type::Symbol, it->type());
else
return it->value();
}
int
Command::get_int_or(const Parameters& params, const std::string& argname, int alt)
std::optional<int>
Command::get_int(const Parameters& params, const std::string& argname)
{
const auto it = find_param_node(params, argname);
if (it == params.end() || it->is_nil())
return alt;
return std::nullopt;
else if (!it->is_number())
throw wrong_type(Sexp::Type::Number, it->type());
else
return ::atoi(it->value().c_str());
}
bool
Command::get_bool_or(const Parameters& params, const std::string& argname, bool alt)
std::optional<bool>
Command::get_bool(const Parameters& params, const std::string& argname)
{
const auto it = find_param_node(params, argname);
if (it == params.end())
return alt;
return std::nullopt;
else if (!it->is_symbol())
throw wrong_type(Sexp::Type::Symbol, it->type());
else

View File

@ -26,6 +26,7 @@
#include <unordered_map>
#include <functional>
#include <algorithm>
#include <optional>
#include "utils/mu-error.hh"
#include "utils/mu-sexp.hh"
@ -61,15 +62,37 @@ using ArgMap = std::unordered_map<std::string, ArgInfo>;
// The parameters to a Handler.
using Parameters = Sexp::Seq;
int get_int_or(const Parameters& parms, const std::string& argname, int alt = 0);
bool get_bool_or(const Parameters& parms, const std::string& argname, bool alt = false);
const std::string&
get_string_or(const Parameters& parms, const std::string& argname, const std::string& alt = "");
const std::string&
get_symbol_or(const Parameters& parms, const std::string& argname, const std::string& alt = "nil");
std::optional<int> get_int(const Parameters& parms, const std::string& argname);
std::optional<bool> get_bool(const Parameters& parms, const std::string& argname);
std::optional<std::string> get_string(const Parameters& parms, const std::string& argname);
std::optional<std::string> get_symbol(const Parameters& parms, const std::string& argname);
std::vector<std::string> get_string_vec(const Parameters& params, const std::string& argname);
/*
* backward compat
*/
static inline int
get_int_or(const Parameters& parms, const std::string& arg, int alt = 0) {
return get_int(parms, arg).value_or(alt);
}
static inline bool
get_bool_or(const Parameters& parms, const std::string& arg, bool alt = false) {
return get_bool(parms, arg).value_or(alt);
}
static inline std::string
get_string_or(const Parameters& parms, const std::string& arg, const std::string& alt = ""){
return get_string(parms, arg).value_or(alt);
}
static inline std::string
get_symbol_or(const Parameters& parms, const std::string& arg, const std::string& alt = "nil") {
return get_symbol(parms, arg).value_or(alt);
}
// A handler function
using Handler = std::function<void(const Parameters&)>;