Save-state: refactor: added a LoadMemory() specialisation for vector<BYTE>

This commit is contained in:
tomcw 2019-12-31 12:52:10 +00:00
parent a28803cbf9
commit b37095715f
3 changed files with 12 additions and 7 deletions

View File

@ -1934,10 +1934,7 @@ bool Disk2InterfaceCard::LoadSnapshotFloppy(YamlLoadHelper& yamlLoadHelper, UINT
if (yamlLoadHelper.GetSubMap(SS_YAML_KEY_TRACK_IMAGE))
{
const UINT maxNibblesPerTrack = ImageGetMaxNibblesPerTrack(m_floppyDrive[unit].m_disk.m_imagehandle);
track.reserve(maxNibblesPerTrack); // expand (but don't shrink) vector's capacity (NB. vector's size doesn't change)
UINT bytes = yamlLoadHelper.LoadMemory(&track[0], maxNibblesPerTrack);
track.resize(bytes); // resize so that vector contains /bytes/ elements
yamlLoadHelper.LoadMemory(track, ImageGetMaxNibblesPerTrack(m_floppyDrive[unit].m_disk.m_imagehandle));
yamlLoadHelper.PopMap();
}

View File

@ -375,9 +375,16 @@ double YamlLoadHelper::LoadDouble(const std::string key)
return strtod(value.c_str(), NULL);
}
UINT YamlLoadHelper::LoadMemory(const LPBYTE pMemBase, const size_t size)
void YamlLoadHelper::LoadMemory(const LPBYTE pMemBase, const size_t size)
{
return m_yamlHelper.LoadMemory(*m_pMapYaml, pMemBase, size);
m_yamlHelper.LoadMemory(*m_pMapYaml, pMemBase, size);
}
void YamlLoadHelper::LoadMemory(std::vector<BYTE>& memory, const size_t size)
{
memory.reserve(size); // expand (but don't shrink) vector's capacity (NB. vector's size doesn't change)
const UINT bytes = m_yamlHelper.LoadMemory(*m_pMapYaml, &memory[0], size);
memory.resize(bytes); // resize so that vector contains /bytes/ elements - so that size() gives correct value.
}
//-------------------------------------

View File

@ -99,7 +99,8 @@ public:
std::string LoadString(const std::string& key);
float LoadFloat(const std::string key);
double LoadDouble(const std::string key);
UINT LoadMemory(const LPBYTE pMemBase, const size_t size);
void LoadMemory(const LPBYTE pMemBase, const size_t size);
void LoadMemory(std::vector<BYTE>& memory, const size_t size);
bool GetSubMap(const std::string key)
{