Commit ed5b7f68 authored by Christian Mattes's avatar Christian Mattes
Browse files

Added automatic registration of some common attribute types

parent f5edacbc
#include "pm.hh"
#include <fstream>
#include <glm/glm.hpp>
#include <iostream>
#include <mutex>
#include <typeindex>
......@@ -195,4 +196,42 @@ bool read_pm(const std::string &filename, Mesh &mesh, attribute_collection &attr
std::ifstream in(filename, std::ios::binary);
return read_pm(in, mesh, attributes);
}
#define REGISTER_TYPE(type) register_type<type>(#type)
static bool registered_default_types = []() {
REGISTER_TYPE(float);
REGISTER_TYPE(double);
REGISTER_TYPE(int8_t);
REGISTER_TYPE(int16_t);
REGISTER_TYPE(int32_t);
REGISTER_TYPE(int64_t);
REGISTER_TYPE(uint8_t);
REGISTER_TYPE(uint16_t);
REGISTER_TYPE(uint32_t);
REGISTER_TYPE(uint64_t);
REGISTER_TYPE(glm::vec2);
REGISTER_TYPE(glm::vec3);
REGISTER_TYPE(glm::vec4);
REGISTER_TYPE(glm::dvec2);
REGISTER_TYPE(glm::dvec3);
REGISTER_TYPE(glm::dvec4);
REGISTER_TYPE(glm::ivec2);
REGISTER_TYPE(glm::ivec3);
REGISTER_TYPE(glm::ivec4);
REGISTER_TYPE(glm::uvec2);
REGISTER_TYPE(glm::uvec3);
REGISTER_TYPE(glm::uvec4);
REGISTER_TYPE(glm::mat2x2);
REGISTER_TYPE(glm::mat2x3);
REGISTER_TYPE(glm::mat2x4);
REGISTER_TYPE(glm::mat3x2);
REGISTER_TYPE(glm::mat3x3);
REGISTER_TYPE(glm::mat3x4);
REGISTER_TYPE(glm::mat4x2);
REGISTER_TYPE(glm::mat4x3);
REGISTER_TYPE(glm::mat4x4);
register_type<std::string>("std::string", detail::string_serdes{});
return true;
}();
}
......@@ -22,7 +22,10 @@ namespace detail
template <typename T>
struct bytewise_serdes
{
void serialize(std::ostream &out, T const *data, size_t num_items) const { out.write(reinterpret_cast<char const *>(data), num_items * sizeof(T)); }
void serialize(std::ostream &out, T const *data, size_t num_items) const
{
out.write(reinterpret_cast<char const *>(data), num_items * sizeof(T));
}
void deserialize(std::istream &in, T *data, size_t num_items) const { in.read(reinterpret_cast<char *>(data), num_items * sizeof(T)); }
};
......
Markdown is supported
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