Split InfoString classes into multiple files depending on loading and writing code

This commit is contained in:
Jan
2021-03-24 13:51:21 +01:00
parent 9e00ad60e7
commit abcce11b00
36 changed files with 579 additions and 549 deletions

View File

@ -0,0 +1,105 @@
#include "InfoString.h"
#include <sstream>
#include <cstring>
const std::string InfoString::EMPTY_VALUE;
bool InfoString::HasKey(const std::string& key) const
{
return m_values.find(key) != m_values.end();
}
const std::string& InfoString::GetValueForKey(const std::string& key) const
{
const auto& value = m_values.find(key);
if (value == m_values.end())
return EMPTY_VALUE;
return value->second;
}
const std::string& InfoString::GetValueForKey(const std::string& key, bool* foundValue) const
{
const auto& value = m_values.find(key);
if (value == m_values.end())
{
if (foundValue)
*foundValue = false;
return EMPTY_VALUE;
}
if (foundValue)
*foundValue = true;
return value->second;
}
void InfoString::SetValueForKey(const std::string& key, std::string value)
{
if (!HasKey(key))
m_keys_by_insertion.push_back(key);
m_values[key] = std::move(value);
}
void InfoString::RemoveKey(const std::string& key)
{
const auto& value = m_values.find(key);
if (value != m_values.end())
m_values.erase(value);
}
std::string InfoString::ToString() const
{
std::stringstream ss;
bool first = true;
for (const auto& key : m_keys_by_insertion)
{
const auto value = m_values.find(key);
if (!first)
ss << '\\';
else
first = false;
ss << key << '\\' << value->second;
}
return ss.str();
}
std::string InfoString::ToString(const std::string& prefix) const
{
std::stringstream ss;
ss << prefix;
for (const auto& key : m_keys_by_insertion)
{
const auto value = m_values.find(key);
ss << '\\' << key << '\\' << value->second;
}
return ss.str();
}
void InfoString::ToGdtProperties(const std::string& prefix, GdtEntry& gdtEntry) const
{
for (const auto& key : m_keys_by_insertion)
{
const auto value = m_values.find(key);
gdtEntry.m_properties[key] = value->second;
}
gdtEntry.m_properties["configstringFileType"] = prefix;
}
void InfoString::FromString()
{
}
void InfoString::FromString(const std::string& prefix)
{
}

View File

@ -0,0 +1,28 @@
#pragma once
#include <unordered_map>
#include <string>
#include <vector>
#include "Utils/ClassUtils.h"
#include "Obj/Gdt/GdtEntry.h"
class InfoString
{
static const std::string EMPTY_VALUE;
std::unordered_map<std::string, std::string> m_values;
std::vector<std::string> m_keys_by_insertion;
public:
_NODISCARD bool HasKey(const std::string& key) const;
_NODISCARD const std::string& GetValueForKey(const std::string& key) const;
const std::string& GetValueForKey(const std::string& key, bool* foundValue) const;
void SetValueForKey(const std::string& key, std::string value);
void RemoveKey(const std::string& key);
_NODISCARD std::string ToString() const;
_NODISCARD std::string ToString(const std::string& prefix) const;
void ToGdtProperties(const std::string& prefix, GdtEntry& gdtEntry) const;
void FromString();
void FromString(const std::string& prefix);
};