completed loading adaption .

This commit is contained in:
Zero Fanker 2024-04-03 23:03:05 -04:00
parent 34c78179f1
commit ca20863dc1
6 changed files with 514 additions and 1880 deletions

View file

@ -180,30 +180,6 @@ WORD CIniFile::InsertFile(const std::string& filename, const char* Section, BOOL
return 0;
}
const CIniFileSection* CIniFile::TryGetSection(std::size_t index) const
{
if (index > sections.size() - 1)
return NULL;
auto i = sections.cbegin();
for (auto e = 0;e < index;e++)
i++;
return &i->second;
}
CIniFileSection* CIniFile::TryGetSection(std::size_t index)
{
if (index > sections.size() - 1)
return NULL;
CIniI i = sections.begin();
for (auto e = 0;e < index;e++)
i++;
return &i->second;
}
const CString* CIniFile::GetSectionName(std::size_t index) const noexcept
{
if (index > sections.size() - 1)
@ -265,20 +241,8 @@ int CIniFileSection::FindIndex(const CString& key) const noexcept
CString CIniFile::GetValueByName(const CString& sectionName, const CString& valueName, const CString& defaultValue) const
{
auto section = TryGetSection(sectionName);
if (!section)
if (!section) {
return defaultValue;
return section->GetValueByName(valueName, defaultValue);
}
return section->GetStringOr(valueName, defaultValue);
}
int CIniFileSection::GetValueOrigPos(int index) const noexcept
{
if (index > value_orig_pos.size() - 1)
return -1;
auto i = value_orig_pos.cbegin();
for (int e = 0;e < index;e++)
i++;
return i->second;
}

View file

@ -78,6 +78,14 @@ public:
return nullptr;
}
const std::pair<int, bool> TryGetInteger(const CString& key) const {
auto const got = this->TryGetString(key);
if (!got) {
return {};
}
return { INIHelper::StringToInteger(*got, 0), true };
}
const CString& GetString(const CString& key) const {
if (auto const ret = TryGetString(key)) {
return *ret;
@ -92,10 +100,15 @@ public:
return defaultValue;
}
int GetInteger(const CString& key, int def = 0)const {
int GetInteger(const CString& key, int def = 0) const {
return INIHelper::StringToInteger(this->GetString(key), def);
}
bool GetBool(const CString& key, bool def = false) const {
auto const& str = this->GetString(key);
return INIHelper::StringToBool(str, def);
}
size_t Size() const { return value_pos.size(); }
bool Exists(const CString& key) const {
@ -121,6 +134,17 @@ public:
value_pairs[it->second].second = std::move(value);
}
void Insert(const CString& key, const CString& value) {
this->Insert(key, CString(value));
}
void Insert(const CString& key, CString&& value) {
value_pairs.push_back({ key, value });
value_pos.insert_or_assign(key, value_pairs.size() - 1);
}
// ==================== Delete
void RemoveAt(size_t idx) {
ASSERT(idx < value_pairs.size());
for (auto affectedIdx = idx + 1; affectedIdx < value_pairs.size(); ++affectedIdx) {
@ -130,7 +154,7 @@ public:
it->second--;
}
auto const itErased = value_pairs.erase(value_pairs.begin() + idx);
ASSERT(value_pos.erase(itErased->first), 1);
ASSERT(value_pos.erase(itErased->first) == 1);
}
void RemoveByKey(const CString& key) {
@ -155,9 +179,6 @@ public:
return value_pairs.end();
}
[[deprecated("instead use iterators or for_each")]]
int GetValueOrigPos(int index) const noexcept;
[[deprecated("instead use iterators or for_each")]]
const CString* GetValueName(std::size_t index) const noexcept {
return &Nth(index).first;
@ -176,6 +197,24 @@ class CIniFile
static const CIniFileSection EmptySection;
public:
CIniFile(CIniFile&& rhs) :
m_filename(std::move(rhs.m_filename)),
sections(std::move(rhs.sections))
{}
CIniFile(const CIniFile& rhs) :
m_filename(rhs.m_filename),
sections(rhs.sections)
{}
CIniFile& operator=(CIniFile&& rhs) {
new (this)CIniFile(std::move(rhs));
return *this;
}
CIniFile& operator=(const CIniFile& rhs) {
new (this)CIniFile(rhs);
return *this;
}
[[deprecated("instead use GetString")]]
CString GetValueByName(const CString& sectionName, const CString& valueName, const CString& defaultValue) const;
void Clear();
@ -189,9 +228,6 @@ public:
// ================ Section interfaces ================
const CString* GetSectionName(std::size_t Index) const noexcept;
const CIniFileSection* TryGetSection(std::size_t index) const;
CIniFileSection* TryGetSection(std::size_t index);
const CIniFileSection* TryGetSection(const CString& section) const
{
auto pMutThis = const_cast<std::remove_cv_t<std::remove_pointer_t<decltype(this)>>*>(this);
@ -232,8 +268,7 @@ public:
return GetSection(section).GetString(key);
}
const bool GetBool(const CString& section, const CString& key, bool def = false) const {
auto const& str = this->GetString(section, key);
return INIHelper::StringToBool(str, def);
return this->GetSection(section).GetBool(key, def);
}
const int GetInteger(const CString& section, const CString& key, int def = 0) const {
return GetSection(section).GetInteger(key, def);
@ -259,6 +294,14 @@ public:
return this->SetString(section, key, CString(value));
}
void SetBool(const CString& section, const CString& key, const bool value) {
this->SetString(section, key, INIHelper::ToString(value));
}
auto Size() const noexcept {
return this->sections.size();
}
auto begin() noexcept
{
return sections.begin();

View file

@ -28,4 +28,14 @@ public:
}
return def;
}
template<typename T>
static CString ToString(const T& origin);// { static_assert(false, "T must have specialized implementations!"); }
template<>
static CString ToString<bool>(const bool& origin)
{
static CString result[] = { "false", "true" };
return result[origin];
}
};

File diff suppressed because it is too large Load diff

View file

@ -110,9 +110,9 @@ public:
CLoading(CWnd* pParent = NULL); // Standardconstructor
void InitPics(CProgressCtrl* prog=NULL);
void Load();
BOOL LoadUnitGraphic(LPCTSTR lpUnittype);
BOOL LoadUnitGraphic(const CString& lpUnittype);
void LoadBuildingSubGraphic(const CString& subkey, const CIniFileSection& artSection, BOOL bAlwaysSetChar, char theat, HMIXFILE hShpMix, SHPHEADER& shp_h, BYTE*& shp);
void LoadOverlayGraphic(LPCTSTR lpOvrlName, int iOvrlNum);
void LoadOverlayGraphic(const CString& lpOvrlName, int iOvrlNum);
void InitVoxelNormalTables();
HTSPALETTE GetIsoPalette(char theat);
HTSPALETTE GetUnitPalette(char theat);

Binary file not shown.