Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Philip Trettner
polymesh
Commits
fda6f9d2
Commit
fda6f9d2
authored
Aug 03, 2018
by
Philip Trettner
Browse files
fixed make_unique, added more default types
parent
2229b6c4
Changes
3
Show whitespace changes
Inline
Side-by-side
src/polymesh/formats/pm.cc
View file @
fda6f9d2
#include
"pm.hh"
#include
<fstream>
#include
<glm/glm.hpp>
#include
<iostream>
#include
<mutex>
#include
<typeindex>
#include
<unordered_map>
#include
<glm/ext.hpp>
#include
<glm/glm.hpp>
#include
"../low_level_api.hh"
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
)
{
...
...
@@ -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
::
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
>
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 = []() {
REGISTER_TYPE
(
bool
);
REGISTER_TYPE
(
float
);
REGISTER_TYPE
(
double
);
REGISTER_TYPE
(
int8_t
);
REGISTER_TYPE
(
int16_t
);
REGISTER_TYPE
(
int32_t
);
...
...
@@ -211,9 +218,13 @@ static bool registered_default_types = []() {
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
::
bvec2
);
REGISTER_TYPE
(
glm
::
bvec3
);
REGISTER_TYPE
(
glm
::
bvec4
);
REGISTER_TYPE
(
glm
::
dvec2
);
REGISTER_TYPE
(
glm
::
dvec3
);
REGISTER_TYPE
(
glm
::
dvec4
);
...
...
@@ -223,6 +234,7 @@ static bool registered_default_types = []() {
REGISTER_TYPE
(
glm
::
uvec2
);
REGISTER_TYPE
(
glm
::
uvec3
);
REGISTER_TYPE
(
glm
::
uvec4
);
REGISTER_TYPE
(
glm
::
mat2x2
);
REGISTER_TYPE
(
glm
::
mat2x3
);
REGISTER_TYPE
(
glm
::
mat2x4
);
...
...
@@ -232,7 +244,21 @@ static bool registered_default_types = []() {
REGISTER_TYPE
(
glm
::
mat4x2
);
REGISTER_TYPE
(
glm
::
mat4x3
);
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
{});
return
true
;
}();
}
src/polymesh/formats/pm.hh
View file @
fda6f9d2
...
...
@@ -49,7 +49,7 @@ void register_attribute_serializer(std::string const &identifier, std::unique_pt
template
<
typename
T
,
typename
serdes
=
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
));
}
}
src/polymesh/tmp.hh
View file @
fda6f9d2
#pragma once
#include
<memory>
#include
<utility>
namespace
polymesh
...
...
@@ -49,5 +50,12 @@ using ref_if_mut = typename if_then_else<std::is_const<TestT>::value, TargetT, t
// std::add_lvalue_reference
// 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
)...));
}
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment