mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-26 05:50:32 +05:00
archive enums
This commit is contained in:
parent
4f40087866
commit
f287df575b
@ -209,6 +209,19 @@ namespace ngcore
|
|||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// archive implementation for enums
|
||||||
|
template<typename T>
|
||||||
|
auto operator & (T& val) -> typename std::enable_if<std::is_enum<T>::value, Archive&>::type
|
||||||
|
{
|
||||||
|
int enumval;
|
||||||
|
if(Output())
|
||||||
|
enumval = int(val);
|
||||||
|
*this & enumval;
|
||||||
|
if(Input())
|
||||||
|
val = T(enumval);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
// vector<bool> has special implementation (like a bitarray) therefore
|
// vector<bool> has special implementation (like a bitarray) therefore
|
||||||
// it needs a special overload (this could probably be more efficient, but we
|
// it needs a special overload (this could probably be more efficient, but we
|
||||||
// don't use it that often anyway)
|
// don't use it that often anyway)
|
||||||
|
@ -248,6 +248,22 @@ void testMap(Archive& in, Archive& out)
|
|||||||
CHECK(map2["netgen"] == "v6.2.1901");
|
CHECK(map2["netgen"] == "v6.2.1901");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum MyEnum
|
||||||
|
{
|
||||||
|
CASE1,
|
||||||
|
CASE2
|
||||||
|
};
|
||||||
|
|
||||||
|
void testEnum(Archive& in, Archive& out)
|
||||||
|
{
|
||||||
|
MyEnum en = CASE2;
|
||||||
|
out & en;
|
||||||
|
out.FlushBuffer();
|
||||||
|
MyEnum enin;
|
||||||
|
in & enin;
|
||||||
|
CHECK(enin == CASE2);
|
||||||
|
}
|
||||||
|
|
||||||
void testArchive(Archive& in, Archive& out)
|
void testArchive(Archive& in, Archive& out)
|
||||||
{
|
{
|
||||||
SECTION("Empty String")
|
SECTION("Empty String")
|
||||||
@ -301,6 +317,10 @@ void testArchive(Archive& in, Archive& out)
|
|||||||
{
|
{
|
||||||
testMap(in, out);
|
testMap(in, out);
|
||||||
}
|
}
|
||||||
|
SECTION("enum")
|
||||||
|
{
|
||||||
|
testEnum(in, out);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("BinaryArchive")
|
TEST_CASE("BinaryArchive")
|
||||||
|
Loading…
Reference in New Issue
Block a user