#pragma once
-#include <vist/archive.hpp>
+#include <vist/stringfy.hpp>
#include <string>
namespace vist {
namespace policy {
-// TODO: Support various value type
struct PolicyValue final {
- enum class Type {
- Integer,
- String,
- None
- };
-
- explicit PolicyValue(int value) : type(Type::Integer)
- {
- this->buffer << value;
- }
-
- explicit PolicyValue(const std::string& value) : type(Type::String)
- {
- this->buffer << value;
- }
-
explicit PolicyValue() noexcept = default;
+ explicit PolicyValue(int value) : stringfied(Stringfy::Dump(value)) {}
+ explicit PolicyValue(const std::string& value) : stringfied(Stringfy::Dump(value)) {}
~PolicyValue() = default;
PolicyValue(const PolicyValue&) = default;
PolicyValue(PolicyValue&&) noexcept = default;
PolicyValue& operator=(PolicyValue&&) noexcept = default;
- inline Type getType() const noexcept
+ inline std::string dump() const noexcept
{
- return this->type;
+ return this->stringfied;
}
- operator int() const
+ inline Stringfy::Type getType() const
{
- auto clone = this->buffer;
- int out;
- clone >> out;
+ return Stringfy::GetType(this->stringfied);
+ }
- return out;
+ operator int() const
+ {
+ return Stringfy::Restore(this->stringfied);
}
operator std::string() const
{
- auto clone = this->buffer;
- std::string out;
- clone >> out;
-
- return out;
+ return Stringfy::Restore(this->stringfied);
}
private:
- Archive buffer;
- Type type = Type::None;
+ std::string stringfied;
};
} // namespace policy
int g_value = -1;
} // anonymous namespace
+using namespace vist;
using namespace vist::policy;
class TestPolicyModel : public PolicyModel {
TEST(PolicySDKTests, policy_value_int)
{
PolicyValue value(1);
- EXPECT_EQ(PolicyValue::Type::Integer, value.getType());
- EXPECT_EQ((int)value, 1);
+ EXPECT_EQ(Stringfy::Type::Integer, value.getType());
+ EXPECT_EQ(static_cast<int>(value), 1);
}
TEST(PolicySDKTests, policy_value_string)
{
- PolicyValue value(std::string("text"));
- EXPECT_EQ(PolicyValue::Type::String, value.getType());
- EXPECT_EQ((std::string)value, "text");
+ PolicyValue value("TEXT");
+ EXPECT_EQ(Stringfy::Type::String, value.getType());
+ EXPECT_EQ(static_cast<std::string>(value), "TEXT");
+}
+
+TEST(PolicySDKTests, policy_value_dump)
+{
+ PolicyValue intValue(1);
+ EXPECT_EQ("I/1", intValue.dump());
+
+ PolicyValue strValue("TEXT");
+ EXPECT_EQ("S/TEXT", strValue.dump());
}
TEST(PolicySDKTests, policy_model)