16#ifndef SIMICS_MAPPABLE_CONF_OBJECT_H
17#define SIMICS_MAPPABLE_CONF_OBJECT_H
19#include <simics/base/log.h>
25#include <unordered_map>
26#include <unordered_set>
45template <
typename IFACE>
59 void set_iface(
const std::string &name, IFACE *iface)
override {
61 throw std::invalid_argument {
62 "Cannot set with NULL interface"
64 }
else if (name.empty()) {
65 throw std::invalid_argument {
66 "Cannot set with empty name string"
69 name_to_iface_[
hash_str(name)] = iface;
82 IFACE *
get_iface(
const std::string &name)
const override {
84 if (name_to_iface_.find(hashed) == name_to_iface_.end()) {
87 return name_to_iface_.at(hashed);
100 if (name_to_iface_.find(name_hash) == name_to_iface_.end()) {
103 return name_to_iface_.at(name_hash);
115 name_to_iface_.erase(
hash_str(name));
120 std::unordered_map<size_t, IFACE *> name_to_iface_;
124class RegisterInterface;
144 template <
typename IFACE>
147 SIM_LOG_ERROR(
obj(), 0,
148 "Cannot set interface for %s when ConfObject"
149 " has been finalized", name.c_str());
153 auto current_iface = get_iface<IFACE>(name);
154 if (current_iface && current_iface != iface) {
155 if (iface_maps_write_protected_) {
156 SIM_LOG_INFO(3,
obj(), 0,
157 "Interface for %s ignored since iface_map is"
158 " write protected", name.c_str());
161 SIM_LOG_INFO(4,
obj(), 0,
162 "Interface for %s overridden", name.c_str());
166 std::get<MapNameToInterfaceObject<IFACE>>(
168 }
catch (
const std::exception &e) {
169 SIM_LOG_ERROR(
obj(), 0,
"%s", e.what());
179 template <
typename IFACE>
181 return std::get<MapNameToInterfaceObject<IFACE>>(
189 return std::get<MapNameToInterfaceObject<RegisterInterface>>(
197 template <
typename IFACE>
199 std::get<MapNameToInterfaceObject<IFACE>>(
211 return &allocated_bank_memories_[name_of_memory.data()];
216 iface_maps_write_protected_ = write_protect;
221 std::tuple<MapNameToInterfaceObject<BankInterface>,
238 std::unordered_map<std::string,
242 bool iface_maps_write_protected_ {
false};
Base class for all Simics configuration objects.
Definition: conf-object.h:126
ConfObject(const ConfObjectRef &obj)
Create a ConfObject from ConfObjectRef.
Definition: conf-object.h:129
virtual bool finalized()
Return if the finalize method has been called.
Definition: conf-object.h:140
ConfObjectRef obj() const
Return a ConfObjectRef represents this object.
Definition: conf-object.h:137
Class that supports get/set a pointer to IFACE with a string name.
Definition: mappable-conf-object.h:46
void set_iface(const std::string &name, IFACE *iface) override
Sets the IFACE associated with the given name.
Definition: mappable-conf-object.h:59
IFACE * get_iface(const std::string &name) const override
Gets the interface associated with the given name.
Definition: mappable-conf-object.h:82
void erase_iface(const std::string &name) override
Erases the interface associated with the given name.
Definition: mappable-conf-object.h:114
IFACE * get_iface(size_t name_hash) const
Gets the interface associated with the given name hash.
Definition: mappable-conf-object.h:99
Definition: map-name-to-interface.h:24
Definition: mappable-conf-object.h:134
void write_protect_iface_maps(bool write_protect)
Whether to write protect the iface_maps, default is not write protected.
Definition: mappable-conf-object.h:215
void erase_iface(const std::string &name)
Erase the IFACE interface by name.
Definition: mappable-conf-object.h:198
RegisterInterface * get_iface(size_t name_hash) const
Get the RegisterInterface* by name hash.
Definition: mappable-conf-object.h:188
bank_memory_t * get_bank_memory(std::string_view name_of_memory)
Get the bank memory by name.
Definition: mappable-conf-object.h:210
virtual bool big_endian_bitorder()
Definition: mappable-conf-object.h:205
virtual ~MappableConfObject()=default
void set_iface(const std::string &name, IFACE *iface)
Set the IFACE interface* by name.
Definition: mappable-conf-object.h:145
IFACE * get_iface(const std::string &name) const
Get the IFACE interface* by name.
Definition: mappable-conf-object.h:180
Definition: register-interface.h:37
Definition: after-bank.h:33
std::unordered_map< Offset, uint8_t > bank_memory_t
Definition: bank-type.h:52
size_t hash_str(const std::string &name)
Hashes a string to a size_t value.