aggregate TMap into Dictionary instead of deriving from it

This commit is contained in:
Alexander Kromm 2020-02-06 21:20:33 +07:00 committed by Christoph Oelckers
parent 3607ffaf66
commit b038c168c6
3 changed files with 15 additions and 9 deletions

View file

@ -2165,7 +2165,7 @@ template<> FSerializer &Serialize(FSerializer &arc, const char *key, FFont *&fon
FString DictionaryToString(const Dictionary &dict) FString DictionaryToString(const Dictionary &dict)
{ {
Dictionary::ConstPair *pair; Dictionary::ConstPair *pair;
Dictionary::ConstIterator i { dict }; Dictionary::ConstIterator i { dict.Map };
rapidjson::StringBuffer buffer; rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer); rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
@ -2214,7 +2214,7 @@ Dictionary *DictionaryFromString(const FString &string)
return dict; return dict;
} }
dict->Insert(i->name.GetString(), i->value.GetString()); dict->Map.Insert(i->name.GetString(), i->value.GetString());
} }
return dict; return dict;

View file

@ -42,7 +42,7 @@ void Dictionary::Serialize(FSerializer &arc)
// Receive new Dictionary, copy contents, clean up. // Receive new Dictionary, copy contents, clean up.
Dictionary *pointerToDeserializedDictionary; Dictionary *pointerToDeserializedDictionary;
arc(key, pointerToDeserializedDictionary); arc(key, pointerToDeserializedDictionary);
TransferFrom(*pointerToDeserializedDictionary); Map.TransferFrom(pointerToDeserializedDictionary->Map);
delete pointerToDeserializedDictionary; delete pointerToDeserializedDictionary;
} }
} }
@ -56,12 +56,12 @@ static Dictionary *DictCreate()
static void DictInsert(Dictionary *dict, const FString &key, const FString &value) static void DictInsert(Dictionary *dict, const FString &key, const FString &value)
{ {
dict->Insert(key, value); dict->Map.Insert(key, value);
} }
static void DictAt(const Dictionary *dict, const FString &key, FString *result) static void DictAt(const Dictionary *dict, const FString &key, FString *result)
{ {
const FString *value = dict->CheckKey(key); const FString *value = dict->Map.CheckKey(key);
*result = value ? *value : ""; *result = value ? *value : "";
} }
@ -72,7 +72,7 @@ static void DictToString(const Dictionary *dict, FString *result)
static void DictRemove(Dictionary *dict, const FString &key) static void DictRemove(Dictionary *dict, const FString &key)
{ {
dict->Remove(key); dict->Map.Remove(key);
} }
//===================================================================================== //=====================================================================================
@ -150,7 +150,7 @@ void DictionaryIterator::Serialize(FSerializer &arc)
void DictionaryIterator::init(Dictionary *dict) void DictionaryIterator::init(Dictionary *dict)
{ {
Iterator = std::make_unique<Dictionary::ConstIterator>(*dict); Iterator = std::make_unique<Dictionary::ConstIterator>(dict->Map);
Dict = dict; Dict = dict;
GC::WriteBarrier(this, Dict); GC::WriteBarrier(this, Dict);

View file

@ -13,13 +13,19 @@
* *
* It is derived from DObject to be a part of normal GC process. * It is derived from DObject to be a part of normal GC process.
*/ */
class Dictionary final : public DObject, public TMap<FString, FString> class Dictionary final : public DObject
{ {
DECLARE_CLASS(Dictionary, DObject) DECLARE_CLASS(Dictionary, DObject)
public: public:
using StringMap = TMap<FString, FString>;
using ConstIterator = StringMap::ConstIterator;
using ConstPair = StringMap::ConstPair;
void Serialize(FSerializer &arc) override; void Serialize(FSerializer &arc) override;
StringMap Map;
}; };
/** /**