3std::string
join(
const std::vector<std::string>& v) {
4 std::ostringstream oss;
5 for (
size_t i = 0; i < v.size(); ++i) {
if (i) oss <<
", "; oss << v[i]; }
10 return id.to_string();
14 std::ostringstream oss;
21 : m_(&m), ctx_(
std::move(ctx)) {}
24 return m_->find(std::string(name)) != m_->end();
28 auto it = m_->find(std::string(name));
29 if (it == m_->end()) {
30 std::vector<std::string> avail;
31 avail.reserve(m_->size());
32 for (
auto& [k,_] : *m_) avail.push_back(k);
33 std::ostringstream oss;
34 oss <<
"Missing source Block '" << name <<
"'";
35 if (!ctx_.empty()) oss <<
" in " << ctx_;
36 oss <<
". Available blocks: [" <<
join(avail) <<
"].";
37 throw std::invalid_argument(oss.str());
44 return b->retrieve(code);
59 std::initializer_list<std::size_t> code)
const {
61 v.reserve(code.size());
62 for (
auto x : code) v.push_back(
static_cast<long>(x));
68 v.reserve(code.size());
69 for (
int x : code) v.push_back(
static_cast<long>(x));
85const std::unordered_map<std::string, std::shared_ptr<Block>>&
BlockSrc::raw()
const {
return *m_; }
91 : m_(&m), ctx_(
std::move(ctx)) {}
96 auto it = m_->find(
id);
97 if (it == m_->end()) {
98 std::vector<std::string> avail;
99 avail.reserve(m_->size());
100 for (
auto& [k,_] : *m_) avail.push_back(
to_string(k));
101 std::ostringstream oss;
102 oss <<
"Missing source Parameter '" <<
to_string(
id) <<
"'";
103 if (!ctx_.empty()) oss <<
" in " << ctx_;
104 oss <<
". Available: [" <<
join(avail) <<
"].";
105 throw std::invalid_argument(oss.str());
114 LhaID id{std::vector<long>(code)};
127const std::unordered_map<ParamId, std::shared_ptr<Parameter>>&
ParamSrc::raw()
const {
return *m_; }
ParamSrc as_param_src(const std::unordered_map< ParamId, std::shared_ptr< Parameter > > &m, std::string ctx)
Helper function to build a ParamSrc view from a parameter map.
std::string to_string(const LhaID &id)
Convenience stringification for LhaID.
std::string join(const std::vector< std::string > &v)
Joins a list of strings with ", ".
BlockSrc as_block_src(const std::unordered_map< std::string, std::shared_ptr< Block > > &m, std::string ctx)
Helper function to build a BlockSrc view from a block map.
std::string to_string(const LhaID &id)
Convenience stringification for LhaID.
std::string join(const std::vector< std::string > &v)
Joins a list of strings with ", ".
Lightweight view over a set of source blocks.
const std::unordered_map< std::string, std::shared_ptr< Block > > & raw() const
Returns the underlying map reference.
scalar_t get_val(std::string_view blk, std::initializer_list< long > code) const
Retrieves the value of a parameter given as an initializer_list.
BlockSrc(const std::unordered_map< std::string, std::shared_ptr< Block > > &m, std::string ctx={})
Constructs a BlockSrc view from an existing map.
const std::shared_ptr< Block > & block(std::string_view name) const
Returns a reference to a block by name.
std::shared_ptr< Parameter > get_param(std::string_view blk, const LhaID &code) const
Retrieves a parameter from a given block by LhaID.
bool has_block(std::string_view name) const
Checks whether a block with a given name is present.
static std::string str(const IdOf< ParamTypeTag > &id)
Returns the string representation associated with an identifier.
Lightweight view over a set of source parameters keyed by ParamId.
const std::shared_ptr< Parameter > & require(const ParamId &id) const
Returns a parameter reference or throws if missing.
ParamSrc()=default
Default constructor: creates an empty, unbound view.
std::shared_ptr< Parameter > get_param(const ParamId &id) const
Convenience wrapper for require().
const std::unordered_map< ParamId, std::shared_ptr< Parameter > > & raw() const
Access to the underlying parameter map.
scalar_t get_val(const ParamId &id) const
Retrieves the current value of a parameter.
bool has(const ParamId &id) const
Checks whether a parameter with the given ID exists.
Hash specialization for SymbolId<Tag>.
Represents an identifier of a LHA element, possibly containing several sub-ids.
Composite identifier for a single parameter.