Skip to content
Snippets Groups Projects
Commit f4ed997d authored by Daniel Hornung's avatar Daniel Hornung
Browse files

ENH: Convenience list argument for SetDataType(..., bool list_type).

parent 67522b83
No related branches found
No related tags found
2 merge requests!14ENH: New functions getEnumNameFromValue() and getEnumValueFromName(),!12F consolidation
Pipeline #12261 failed
...@@ -541,8 +541,8 @@ public: ...@@ -541,8 +541,8 @@ public:
* Set the datatype of this property. * Set the datatype of this property.
*/ */
auto SetDataType(const DataType &new_data_type) -> StatusCode; auto SetDataType(const DataType &new_data_type) -> StatusCode;
auto SetDataType(const AtomicDataType new_data_type) -> StatusCode; auto SetDataType(const AtomicDataType new_data_type, bool list_type = false) -> StatusCode;
auto SetDataType(const std::string &new_data_type) -> StatusCode; auto SetDataType(const std::string &new_data_type, bool list_type = false) -> StatusCode;
/** /**
* Return a json string representing this property. * Return a json string representing this property.
...@@ -712,8 +712,8 @@ public: ...@@ -712,8 +712,8 @@ public:
auto SetUnit(const std::string &unit) -> void; auto SetUnit(const std::string &unit) -> void;
auto SetDataType(const DataType &new_data_type) -> StatusCode; auto SetDataType(const DataType &new_data_type) -> StatusCode;
auto SetDataType(const AtomicDataType new_data_type) -> StatusCode; auto SetDataType(const AtomicDataType new_data_type, bool list_type = false) -> StatusCode;
auto SetDataType(const std::string &new_data_type) -> StatusCode; auto SetDataType(const std::string &new_data_type, bool list_type = false) -> StatusCode;
auto AppendProperty(const Property &property) -> void; auto AppendProperty(const Property &property) -> void;
auto RemoveProperty(int index) -> void; auto RemoveProperty(int index) -> void;
......
...@@ -142,12 +142,12 @@ auto Property::SetDataType(const DataType &new_data_type) -> StatusCode { ...@@ -142,12 +142,12 @@ auto Property::SetDataType(const DataType &new_data_type) -> StatusCode {
return this->data_type.CopyFrom(new_data_type); return this->data_type.CopyFrom(new_data_type);
} }
auto Property::SetDataType(const AtomicDataType new_data_type) -> StatusCode { auto Property::SetDataType(const AtomicDataType new_data_type, bool list_type) -> StatusCode {
return SetDataType(DataType(new_data_type)); return SetDataType(DataType(new_data_type, list_type));
} }
auto Property::SetDataType(const std::string &new_data_type) -> StatusCode { auto Property::SetDataType(const std::string &new_data_type, bool list_type) -> StatusCode {
return SetDataType(DataType(new_data_type)); return SetDataType(DataType(new_data_type, list_type));
} }
[[nodiscard]] auto Entity::GetParents() const -> const Parents & { [[nodiscard]] auto Entity::GetParents() const -> const Parents & {
...@@ -238,12 +238,12 @@ auto Entity::SetDataType(const DataType &new_data_type) -> StatusCode { ...@@ -238,12 +238,12 @@ auto Entity::SetDataType(const DataType &new_data_type) -> StatusCode {
return this->data_type.CopyFrom(new_data_type); return this->data_type.CopyFrom(new_data_type);
} }
auto Entity::SetDataType(const AtomicDataType new_data_type) -> StatusCode { auto Entity::SetDataType(const AtomicDataType new_data_type, bool list_type) -> StatusCode {
return SetDataType(DataType(new_data_type)); return SetDataType(DataType(new_data_type, list_type));
} }
auto Entity::SetDataType(const std::string &new_data_type) -> StatusCode { auto Entity::SetDataType(const std::string &new_data_type, bool list_type) -> StatusCode {
return SetDataType(DataType(new_data_type)); return SetDataType(DataType(new_data_type, list_type));
} }
auto Entity::SetFilePath(const std::string &path) -> void { auto Entity::SetFilePath(const std::string &path) -> void {
......
...@@ -85,6 +85,29 @@ TEST(test_entity, test_property_setters) { ...@@ -85,6 +85,29 @@ TEST(test_entity, test_property_setters) {
EXPECT_EQ(prop.GetUnit(), "prop_unit"); EXPECT_EQ(prop.GetUnit(), "prop_unit");
EXPECT_TRUE(prop.GetDataType().IsReference()); EXPECT_TRUE(prop.GetDataType().IsReference());
EXPECT_EQ(prop.GetDataType().AsReference().GetName(), "prop_dtype"); EXPECT_EQ(prop.GetDataType().AsReference().GetName(), "prop_dtype");
EXPECT_FALSE(prop.GetDataType().IsList());
prop.SetDataType(AtomicDataType::DATETIME);
EXPECT_TRUE(prop.GetDataType().IsAtomic());
EXPECT_EQ(prop.GetDataType().AsAtomic(), AtomicDataType::DATETIME);
EXPECT_FALSE(prop.GetDataType().IsList());
}
TEST(test_entity, test_list_property_setters) {
auto prop = Property();
prop.SetDataType(AtomicDataType::DATETIME); // Set as atomic first.
EXPECT_TRUE(prop.GetDataType().IsAtomic());
EXPECT_EQ(prop.GetDataType().AsAtomic(), AtomicDataType::DATETIME);
prop.SetDataType(AtomicDataType::DOUBLE, true);
auto const & dtype = prop.GetDataType();
EXPECT_FALSE(dtype.IsAtomic()); // Should not be true anymore.
EXPECT_FALSE(dtype.IsReference());
EXPECT_TRUE(dtype.IsList());
EXPECT_NE(dtype.AsAtomic(), AtomicDataType::DATETIME); // Should be overwritten.
EXPECT_TRUE(dtype.AsList().IsListOfAtomic());
EXPECT_EQ(dtype.AsList().GetAtomicDataType(),AtomicDataType::DOUBLE);
} }
TEST(test_entity, test_append_property) { TEST(test_entity, test_append_property) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment