Skip to content
Permalink
Browse files

aggregate TMap into Dictionary instead of deriving from it

  • Loading branch information
mmaulwurff authored and coelckers committed Feb 6, 2020
1 parent 3607ffa commit b038c168c635fedd58bf6f9baffd37ccadf31904
Showing with 15 additions and 9 deletions.
  1. +2 −2 src/serializer.cpp
  2. +5 −5 src/utility/dictionary.cpp
  3. +8 −2 src/utility/dictionary.h
@@ -2165,7 +2165,7 @@ template<> FSerializer &Serialize(FSerializer &arc, const char *key, FFont *&fon
FString DictionaryToString(const Dictionary &dict)
{
Dictionary::ConstPair *pair;
Dictionary::ConstIterator i { dict };
Dictionary::ConstIterator i { dict.Map };

rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
@@ -2214,7 +2214,7 @@ Dictionary *DictionaryFromString(const FString &string)
return dict;
}

dict->Insert(i->name.GetString(), i->value.GetString());
dict->Map.Insert(i->name.GetString(), i->value.GetString());
}

return dict;
@@ -42,7 +42,7 @@ void Dictionary::Serialize(FSerializer &arc)
// Receive new Dictionary, copy contents, clean up.
Dictionary *pointerToDeserializedDictionary;
arc(key, pointerToDeserializedDictionary);
TransferFrom(*pointerToDeserializedDictionary);
Map.TransferFrom(pointerToDeserializedDictionary->Map);
delete pointerToDeserializedDictionary;
}
}
@@ -56,12 +56,12 @@ static Dictionary *DictCreate()

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)
{
const FString *value = dict->CheckKey(key);
const FString *value = dict->Map.CheckKey(key);
*result = value ? *value : "";
}

@@ -72,7 +72,7 @@ static void DictToString(const Dictionary *dict, FString *result)

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)
{
Iterator = std::make_unique<Dictionary::ConstIterator>(*dict);
Iterator = std::make_unique<Dictionary::ConstIterator>(dict->Map);
Dict = dict;

GC::WriteBarrier(this, Dict);
@@ -13,13 +13,19 @@
*
* 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)

public:

using StringMap = TMap<FString, FString>;
using ConstIterator = StringMap::ConstIterator;
using ConstPair = StringMap::ConstPair;

void Serialize(FSerializer &arc) override;

StringMap Map;
};

/**
@@ -45,7 +51,7 @@ class DictionaryIterator final : public DObject
*/
DictionaryIterator();

void Serialize(FSerializer &arc) override;
void Serialize(FSerializer &arc) override;

/**
* @brief init function complements constructor.

0 comments on commit b038c16

Please sign in to comment.
You can’t perform that action at this time.