Emulator: Prefer string_view over const char*
This commit is contained in:
+4
-4
@@ -29,23 +29,23 @@ void Emu::update()
|
||||
}
|
||||
}
|
||||
|
||||
void Emu::addProcessingUnit(const char* name, ProcessingUnit* processing_unit)
|
||||
void Emu::addProcessingUnit(std::string_view name, ProcessingUnit* processing_unit)
|
||||
{
|
||||
m_processing_units.emplace(name, processing_unit);
|
||||
}
|
||||
|
||||
void Emu::addMemorySpace(const char* name, uint32_t size)
|
||||
void Emu::addMemorySpace(std::string_view name, uint32_t size)
|
||||
{
|
||||
std::vector<uint32_t> memory(size);
|
||||
m_memory_spaces.emplace(name, memory);
|
||||
}
|
||||
|
||||
void Emu::writeMemory(const char* memory_space, uint32_t location, uint32_t value)
|
||||
void Emu::writeMemory(std::string_view memory_space, uint32_t location, uint32_t value)
|
||||
{
|
||||
m_memory_spaces[memory_space][location] = value;
|
||||
}
|
||||
|
||||
uint32_t Emu::readMemory(const char* memory_space, uint32_t location)
|
||||
uint32_t Emu::readMemory(std::string_view memory_space, uint32_t location)
|
||||
{
|
||||
return m_memory_spaces[memory_space][location];
|
||||
}
|
||||
|
||||
@@ -17,15 +17,15 @@ public:
|
||||
|
||||
void update();
|
||||
|
||||
void addProcessingUnit(const char* name, ProcessingUnit* processing_unit);
|
||||
void addMemorySpace(const char* name, uint32_t size);
|
||||
void addProcessingUnit(std::string_view name, ProcessingUnit* processing_unit);
|
||||
void addMemorySpace(std::string_view name, uint32_t size);
|
||||
|
||||
void writeMemory(const char* memory_space, uint32_t location, uint32_t value);
|
||||
uint32_t readMemory(const char* memory_space, uint32_t location);
|
||||
void writeMemory(std::string_view memory_space, uint32_t location, uint32_t value);
|
||||
uint32_t readMemory(std::string_view memory_space, uint32_t location);
|
||||
|
||||
// -------------------------------------
|
||||
|
||||
ProcessingUnit* processingUnit(const char* name) const { return m_processing_units.at(name); }
|
||||
ProcessingUnit* processingUnit(std::string_view name) const { return m_processing_units.at(name); }
|
||||
|
||||
private:
|
||||
uint32_t m_frequency { 0 };
|
||||
@@ -36,8 +36,8 @@ private:
|
||||
|
||||
ruc::Timer m_timer;
|
||||
|
||||
std::unordered_map<const char*, ProcessingUnit*> m_processing_units;
|
||||
std::unordered_map<const char*, std::vector<uint32_t>> m_memory_spaces;
|
||||
std::unordered_map<std::string_view, ProcessingUnit*> m_processing_units;
|
||||
std::unordered_map<std::string_view, std::vector<uint32_t>> m_memory_spaces;
|
||||
|
||||
std::string_view m_bootrom;
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint> // uint32_t
|
||||
#include <string_view>
|
||||
#include <unordered_map>
|
||||
|
||||
class ProcessingUnit {
|
||||
@@ -20,9 +21,9 @@ public:
|
||||
// -------------------------------------
|
||||
|
||||
uint32_t frequency() const { return m_frequency; };
|
||||
uint32_t* sharedRegister(const char* shared_register) const { return m_shared_registers.at(shared_register); }
|
||||
uint32_t* sharedRegister(std::string_view shared_register) const { return m_shared_registers.at(shared_register); }
|
||||
|
||||
protected:
|
||||
uint32_t m_frequency { 0 };
|
||||
std::unordered_map<const char*, uint32_t*> m_shared_registers;
|
||||
std::unordered_map<std::string_view, uint32_t*> m_shared_registers;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user