#include "pch.h"
#include "serializer.h"

Serializer::Type::Ref Serializer::instanciate(const std::string& key)
{
    if (m_ctor_table.find(key) != m_ctor_table.end())
        return m_ctor_table[key]();
    return nullptr;
}

std::map<std::string /*key*/, std::function<Serializer::Type::Ref()>> Serializer::m_ctor_table =
{
    { "VlLs", [] { return std::make_shared<Serializer::List>(); } },
    { "TEXT", [] { return std::make_shared<Serializer::String>(); } },
    { "Objc", [] { return std::make_shared<Serializer::Descriptor>(); } },
    { "UntF", [] { return std::make_shared<Serializer::UnitFloat>(); } },
    { "bool", [] { return std::make_shared<Serializer::Boolean>(); } },
    { "long", [] { return std::make_shared<Serializer::Integer>(); } },
    { "doub", [] { return std::make_shared<Serializer::Double>(); } },
    { "enum", [] { return std::make_shared<Serializer::Enum>(); } },
    { "tdta", [] { return std::make_shared<Serializer::RawData>(); } },
    { "vec2", [] { return std::make_shared<Serializer::Vec2>(); } },
    { "vec3", [] { return std::make_shared<Serializer::Vec3>(); } },
    { "vec4", [] { return std::make_shared<Serializer::Vec4>(); } },
    { "ive2", [] { return std::make_shared<Serializer::IVec2>(); } },
    { "ive3", [] { return std::make_shared<Serializer::IVec3>(); } },
    { "ive4", [] { return std::make_shared<Serializer::IVec4>(); } },
    { "flt ", [] { return std::make_shared<Serializer::Float>(); } },
    { "cstr", [] { return std::make_shared<Serializer::CString>(); } },
};
