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);
|
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);
|
std::vector<uint32_t> memory(size);
|
||||||
m_memory_spaces.emplace(name, memory);
|
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;
|
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];
|
return m_memory_spaces[memory_space][location];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,15 @@ public:
|
|||||||
|
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
void addProcessingUnit(const char* name, ProcessingUnit* processing_unit);
|
void addProcessingUnit(std::string_view name, ProcessingUnit* processing_unit);
|
||||||
void addMemorySpace(const char* name, uint32_t size);
|
void addMemorySpace(std::string_view name, uint32_t size);
|
||||||
|
|
||||||
void writeMemory(const char* memory_space, uint32_t location, uint32_t value);
|
void writeMemory(std::string_view memory_space, uint32_t location, uint32_t value);
|
||||||
uint32_t readMemory(const char* memory_space, uint32_t location);
|
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:
|
private:
|
||||||
uint32_t m_frequency { 0 };
|
uint32_t m_frequency { 0 };
|
||||||
@@ -36,8 +36,8 @@ private:
|
|||||||
|
|
||||||
ruc::Timer m_timer;
|
ruc::Timer m_timer;
|
||||||
|
|
||||||
std::unordered_map<const char*, ProcessingUnit*> m_processing_units;
|
std::unordered_map<std::string_view, ProcessingUnit*> m_processing_units;
|
||||||
std::unordered_map<const char*, std::vector<uint32_t>> m_memory_spaces;
|
std::unordered_map<std::string_view, std::vector<uint32_t>> m_memory_spaces;
|
||||||
|
|
||||||
std::string_view m_bootrom;
|
std::string_view m_bootrom;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint> // uint32_t
|
#include <cstdint> // uint32_t
|
||||||
|
#include <string_view>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
class ProcessingUnit {
|
class ProcessingUnit {
|
||||||
@@ -20,9 +21,9 @@ public:
|
|||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
|
|
||||||
uint32_t frequency() const { return m_frequency; };
|
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:
|
protected:
|
||||||
uint32_t m_frequency { 0 };
|
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