Commit fda6f9d2 authored by Philip Trettner's avatar Philip Trettner
Browse files

fixed make_unique, added more default types

parent 2229b6c4
#include "pm.hh" #include "pm.hh"
#include <fstream> #include <fstream>
#include <glm/glm.hpp>
#include <iostream> #include <iostream>
#include <mutex> #include <mutex>
#include <typeindex> #include <typeindex>
#include <unordered_map> #include <unordered_map>
#include <glm/ext.hpp>
#include <glm/glm.hpp>
#include "../low_level_api.hh" #include "../low_level_api.hh"
namespace polymesh namespace polymesh
{ {
static std::unordered_map<std::string, std::unique_ptr<detail::GenericAttributeSerializer>> sSerializers; namespace
{
std::unordered_map<std::string, std::unique_ptr<detail::GenericAttributeSerializer>> sSerializers;
const std::string unregistered_type_name = "UNREGISTERED_TYPE";
}
void detail::register_attribute_serializer(const std::string &identifier, std::unique_ptr<detail::GenericAttributeSerializer> ptr) void detail::register_attribute_serializer(const std::string &identifier, std::unique_ptr<detail::GenericAttributeSerializer> ptr)
{ {
...@@ -61,8 +69,6 @@ static std::ostream &write_index(std::ostream &out, primitive_index<tag> const & ...@@ -61,8 +69,6 @@ static std::ostream &write_index(std::ostream &out, primitive_index<tag> const &
static std::ostream &write_string(std::ostream &out, std::string const &text) { return out.write(text.c_str(), text.size() + 1); } static std::ostream &write_string(std::ostream &out, std::string const &text) { return out.write(text.c_str(), text.size() + 1); }
static std::istream &read_string(std::istream &in, std::string &text) { return std::getline(in, text, '\0'); } static std::istream &read_string(std::istream &in, std::string &text) { return std::getline(in, text, '\0'); }
static const std::string unregistered_type_name = "UNREGISTERED_TYPE";
template <class tag> template <class tag>
static std::ostream &storeAttributes(std::ostream &out, std::map<std::string, std::unique_ptr<primitive_attribute_base<tag>>> const &attrs) static std::ostream &storeAttributes(std::ostream &out, std::map<std::string, std::unique_ptr<primitive_attribute_base<tag>>> const &attrs)
{ {
...@@ -203,6 +209,7 @@ static bool registered_default_types = []() { ...@@ -203,6 +209,7 @@ static bool registered_default_types = []() {
REGISTER_TYPE(bool); REGISTER_TYPE(bool);
REGISTER_TYPE(float); REGISTER_TYPE(float);
REGISTER_TYPE(double); REGISTER_TYPE(double);
REGISTER_TYPE(int8_t); REGISTER_TYPE(int8_t);
REGISTER_TYPE(int16_t); REGISTER_TYPE(int16_t);
REGISTER_TYPE(int32_t); REGISTER_TYPE(int32_t);
...@@ -211,9 +218,13 @@ static bool registered_default_types = []() { ...@@ -211,9 +218,13 @@ static bool registered_default_types = []() {
REGISTER_TYPE(uint16_t); REGISTER_TYPE(uint16_t);
REGISTER_TYPE(uint32_t); REGISTER_TYPE(uint32_t);
REGISTER_TYPE(uint64_t); REGISTER_TYPE(uint64_t);
REGISTER_TYPE(glm::vec2); REGISTER_TYPE(glm::vec2);
REGISTER_TYPE(glm::vec3); REGISTER_TYPE(glm::vec3);
REGISTER_TYPE(glm::vec4); REGISTER_TYPE(glm::vec4);
REGISTER_TYPE(glm::bvec2);
REGISTER_TYPE(glm::bvec3);
REGISTER_TYPE(glm::bvec4);
REGISTER_TYPE(glm::dvec2); REGISTER_TYPE(glm::dvec2);
REGISTER_TYPE(glm::dvec3); REGISTER_TYPE(glm::dvec3);
REGISTER_TYPE(glm::dvec4); REGISTER_TYPE(glm::dvec4);
...@@ -223,6 +234,7 @@ static bool registered_default_types = []() { ...@@ -223,6 +234,7 @@ static bool registered_default_types = []() {
REGISTER_TYPE(glm::uvec2); REGISTER_TYPE(glm::uvec2);
REGISTER_TYPE(glm::uvec3); REGISTER_TYPE(glm::uvec3);
REGISTER_TYPE(glm::uvec4); REGISTER_TYPE(glm::uvec4);
REGISTER_TYPE(glm::mat2x2); REGISTER_TYPE(glm::mat2x2);
REGISTER_TYPE(glm::mat2x3); REGISTER_TYPE(glm::mat2x3);
REGISTER_TYPE(glm::mat2x4); REGISTER_TYPE(glm::mat2x4);
...@@ -232,7 +244,21 @@ static bool registered_default_types = []() { ...@@ -232,7 +244,21 @@ static bool registered_default_types = []() {
REGISTER_TYPE(glm::mat4x2); REGISTER_TYPE(glm::mat4x2);
REGISTER_TYPE(glm::mat4x3); REGISTER_TYPE(glm::mat4x3);
REGISTER_TYPE(glm::mat4x4); REGISTER_TYPE(glm::mat4x4);
REGISTER_TYPE(glm::dmat2x2);
REGISTER_TYPE(glm::dmat2x3);
REGISTER_TYPE(glm::dmat2x4);
REGISTER_TYPE(glm::dmat3x2);
REGISTER_TYPE(glm::dmat3x3);
REGISTER_TYPE(glm::dmat3x4);
REGISTER_TYPE(glm::dmat4x2);
REGISTER_TYPE(glm::dmat4x3);
REGISTER_TYPE(glm::dmat4x4);
REGISTER_TYPE(glm::quat);
register_type<std::string>("std::string", detail::string_serdes{}); register_type<std::string>("std::string", detail::string_serdes{});
return true; return true;
}(); }();
} }
...@@ -49,7 +49,7 @@ void register_attribute_serializer(std::string const &identifier, std::unique_pt ...@@ -49,7 +49,7 @@ void register_attribute_serializer(std::string const &identifier, std::unique_pt
template <typename T, typename serdes = detail::bytewise_serdes<T>> template <typename T, typename serdes = detail::bytewise_serdes<T>>
void register_type(std::string const &identifier, serdes &&serializer = detail::bytewise_serdes<T>{}) void register_type(std::string const &identifier, serdes &&serializer = detail::bytewise_serdes<T>{})
{ {
auto ptr = std::make_unique<detail::AttributeSerializer<T, serdes>>(serializer); auto ptr = tmp::make_unique<detail::AttributeSerializer<T, serdes>>(serializer);
detail::register_attribute_serializer(identifier, std::move(ptr)); detail::register_attribute_serializer(identifier, std::move(ptr));
} }
} }
#pragma once #pragma once
#include <memory>
#include <utility> #include <utility>
namespace polymesh namespace polymesh
...@@ -49,5 +50,12 @@ using ref_if_mut = typename if_then_else<std::is_const<TestT>::value, TargetT, t ...@@ -49,5 +50,12 @@ using ref_if_mut = typename if_then_else<std::is_const<TestT>::value, TargetT, t
// std::add_lvalue_reference // std::add_lvalue_reference
// template <class T> // template <class T>
/// For C++11
template <typename T, typename... Args>
std::unique_ptr<T> make_unique(Args&&... args)
{
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment