Large diffs are not rendered by default.

@@ -5,17 +5,27 @@
#include <string>
#include <unordered_map>

#include <stdint.h>
#include <enum/enum.h>
#include <cstdint>

typedef const char *(*annotation_f)();
#include <enum\enum.h>
#include <optional\optional.hpp>


template <class T>
using Optional = nonstd::optional<T>;

using RString = std::string;
using RFile = std::string;
using RHash = uint32_t;

#include "Foundation\Reflection\ReflectionList.h"
#include "Foundation\Reflection\ReflectionMap.h"

template <class T>
using RList = RArrayList<T>;

template <class T>
using RList = std::vector<T>;
using RDictionary = ReflectionMap<std::string, T>;

template <class T>
using RDictionary = std::unordered_map<RHash, T>;
using RHashMap = ReflectionMap<RHash, T>;
@@ -27,8 +27,9 @@
<ClInclude Include="Document\DocumentPath.h" />
<ClInclude Include="Json\Json.h" />
<ClInclude Include="Reflection\Reflection.h" />
<ClInclude Include="Reflection\ReflectionArray.h" />
<ClInclude Include="Reflection\ReflectionJson.h" />
<ClInclude Include="Reflection\ReflectionList.h" />
<ClInclude Include="Reflection\ReflectionMap.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Document\Document.cpp" />
@@ -31,7 +31,10 @@
<ClInclude Include="Json\Json.h">
<Filter>Json</Filter>
</ClInclude>
<ClInclude Include="Reflection\ReflectionArray.h">
<ClInclude Include="Reflection\ReflectionMap.h">
<Filter>Reflection</Filter>
</ClInclude>
<ClInclude Include="Reflection\ReflectionList.h">
<Filter>Reflection</Filter>
</ClInclude>
</ItemGroup>
@@ -30,16 +30,16 @@ void DecodeJson(T & value, Json & j)
}

template <class T>
void DecodeJson(RList<T> & value, Json & j)
void DecodeJson(RArrayList<T> & value, Json & j)
{
value.clear();
value.reserve(j.size());
value.Clear();
value.Reserve(j.size());
for (auto t : j)
{
T new_val;
DecodeJson(new_val, t);

value.push_back(new_val);
value.PushBack(new_val);
}
}

@@ -134,7 +134,7 @@ Json EncodeJson(const T & value)
}

template <class T>
Json EncodeJson(const RList<T> & value)
Json EncodeJson(const RArrayList<T> & value)
{
Json j_value;
for (auto t : value)
@@ -2,6 +2,77 @@

#include "Foundation\Common.h"

template <class T>
class RArrayList
{
public:

void Clear()
{
m_Values.clear();
}

void Reserve(std::size_t size)
{
m_Values.reserve(size);
}

void PushBack(const T & val)
{
m_Values.push_back(val);
}

void InsertAt(const T & val, std::size_t logical_index)
{
if (logical_index == m_Values.size())
{
m_Values.push_back(ContainerData());
return;
}

m_Values.insert(m_Values.begin() + logical_index);
}

void RemoveAt(std::size_t logical_index)
{
m_Values.erase(m_Values.begin() + logical_index);
}

std::size_t HighestIndex()
{
return m_Values.size();
}

void Compress()
{
}

auto begin()
{
return m_Values.begin();
}

auto end()
{
return m_Values.end();
}

auto begin() const
{
return m_Value.begin();
}

auto end() const
{
return m_Values.end();
}

private:

std::vector<T> m_Values;
};


template <class T>
class RSparseList
{
@@ -21,9 +92,9 @@ class RSparseList
return m_PhysicalIndex != rhs.m_PhysicalIndex;
}

const std::pair<int, T &> operator *() const
const std::pair<std::size_t, T &> operator *() const
{
std::pair<int, T &> val(m_PhysicalIndex, m_List->m_Values[m_PhysicalIndex].m_T);
std::pair<std::size_t, T &> val(m_PhysicalIndex, m_List->m_Values[m_PhysicalIndex].m_T);
return val;
}

@@ -37,7 +108,7 @@ class RSparseList

private:

RSparseListIterator(RSparseList<T> * list, int physical_index) : m_List(list), m_PhysicalIndex(physical_index) { }
RSparseListIterator(RSparseList<T> * list, std::size_t physical_index) : m_List(list), m_PhysicalIndex(physical_index) { }

std::size_t m_PhysicalIndex = 0;
RSparseList<T> * m_List;
@@ -59,9 +130,9 @@ class RSparseList
return m_PhysicalIndex != rhs.m_PhysicalIndex;
}

const std::pair<int, const T &> operator *() const
const std::pair<std::size_t, const T &> operator *() const
{
std::pair<int, const T &> val(m_PhysicalIndex, m_List->m_Values[m_PhysicalIndex].m_T);
std::pair<std::size_t, const T &> val(m_PhysicalIndex, m_List->m_Values[m_PhysicalIndex].m_T);
return val;
}

@@ -75,7 +146,7 @@ class RSparseList

private:

RSparseListIteratorConst(const RSparseList<T> * list, int physical_index) : m_List(list), m_PhysicalIndex(physical_index) { }
RSparseListIteratorConst(const RSparseList<T> * list, std::size_t physical_index) : m_List(list), m_PhysicalIndex(physical_index) { }

std::size_t m_PhysicalIndex = 0;
const RSparseList<T> * m_List;
@@ -120,7 +191,7 @@ class RSparseList

if (m_HighestIndex == logical_index)
{
for (int index = m_Values.size() - 1; index >= 0 && m_Values[index].m_Valid == false; index--)
for (std::size_t index = m_Values.size() - 1; index >= 0 && m_Values[index].m_Valid == false; index--)
{
m_HighestIndex--;
}
@@ -184,7 +255,6 @@ class RSparseList
return itr;
}


private:
struct ContainerData
{
@@ -239,7 +309,7 @@ class RMergeList

private:

RMergeListIterator(RMergeList<T> * list, int physical_index) : m_List(list), m_PhysicalIndex(physical_index) { }
RMergeListIterator(RMergeList<T> * list, std::size_t physical_index) : m_List(list), m_PhysicalIndex(physical_index) { }

int m_PhysicalIndex = 0;
RMergeList<T> * m_List;
@@ -274,7 +344,7 @@ class RMergeList

private:

RMergeListIteratorConst(const RMergeList<T> * list, int physical_index) : m_List(list), m_PhysicalIndex(physical_index) { }
RMergeListIteratorConst(const RMergeList<T> * list, std::size_t physical_index) : m_List(list), m_PhysicalIndex(physical_index) { }

int m_PhysicalIndex = 0;
const RMergeList<T> * m_List;
@@ -0,0 +1,68 @@
#pragma once

#include "Foundation\Common.h"

template <class K, class T>
class ReflectionMap
{
public:
void Clear()
{
m_Values.clear();
}

void Set(const K & k, T && t)
{
m_Values.insert_or_assign(k, t);
}

void Remove(const K & k)
{
auto itr = m_Values.find(k);
if (itr == m_Values.end())
{
return;
}

m_Values.erase(itr);
}

Optional<T> Get(const K & k)
{
auto itr = m_Values.find(k);
if (itr == m_Values.end())
{
return Optional<T>();
}

return itr->second;
}

T & operator [] (const K & k)
{
return m_Values[k];
}

auto begin()
{
return m_Values.begin();
}

auto end()
{
return m_Values.end();
}

auto begin() const
{
return m_Values.begin();
}

auto end() const
{
return m_Values.end();
}

public:
std::unordered_map<uint32_t, T> m_Values;
};
@@ -5,7 +5,6 @@

#include "Foundation\Common.h"
#include "Foundation\Reflection\Reflection.h"
#include "Foundation\Reflection\ReflectionArray.h"
#include "Foundation\Reflection\ReflectionJson.h"

#include "Foundation\Document\DocumentPath.h"
@@ -16,7 +15,7 @@ struct Inventory
{
Inventory()
{
items.push_back(20);
items.PushBack(20);
}

public:
@@ -143,6 +142,11 @@ int main()
asdf.RemoveAt(1);
asdf.PushBack(90);

RHashMap<int> map;
map.Set(0, 2);
map.Get(0);
map.Remove(0);

Json j = EncodeJson(asdf);
std::string test = j.dump(2);
std::cout << test << std::endl;