Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • caosdb/src/caosdb-cpplib
1 result
Show changes
Commits on Source (2)
......@@ -151,6 +151,22 @@ public:
DataType(const std::string &data_type) : DataType() {
this->wrapped->mutable_reference_data_type()->set_name(data_type);
}
inline static auto ListOf(const AtomicDataType &atomic_data_type)
-> DataType {
DataType result;
result.wrapped->mutable_list_data_type()->set_atomic_data_type(
static_cast<ProtoAtomicDataType>(atomic_data_type));
return result;
}
inline static auto ListOf(const std::string reference_data_type) -> DataType {
DataType result;
result.wrapped->mutable_list_data_type()
->mutable_reference_data_type()
->set_name(reference_data_type);
return result;
}
[[nodiscard]] inline auto IsAtomic() const noexcept -> bool {
return this->wrapped->data_type_case() == DataTypeCase::kAtomicDataType;
}
......
......@@ -42,6 +42,7 @@
#include <boost/log/sources/record_ostream.hpp> // for basic_record_...
#include <boost/preprocessor/seq/limits/enum_256.hpp> // for BOOST_PP_SEQ_...
#include <boost/preprocessor/seq/limits/size_256.hpp> // for BOOST_PP_SEQ_...
#include <cstdint> // for int64_t
#include <google/protobuf/message.h> // for RepeatedPtrField
#include <google/protobuf/util/json_util.h> // for MessageToJson...
#include <iosfwd> // for streamsize
......@@ -50,6 +51,7 @@
#include <random> // for mt19937, rand...
#include <stdexcept> // for out_of_range
#include <string> // for string, basic...
#include <vector> // for vector
namespace caosdb::entity {
using boost::filesystem::exists;
......@@ -514,9 +516,16 @@ public:
*/
auto SetValue(const Value &value) -> StatusCode;
auto SetValue(const std::string &value) -> StatusCode;
auto SetValue(const char *value) -> StatusCode;
auto SetValue(const double value) -> StatusCode;
// auto SetValue(const int64_t value) -> StatusCode;
// auto SetValue(const bool value) -> StatusCode;
auto SetValue(const std::vector<std::string> &values) -> StatusCode;
auto SetValue(const std::vector<char *> &values) -> StatusCode;
auto SetValue(const std::vector<int64_t> &values) -> StatusCode;
auto SetValue(const std::vector<double> &values) -> StatusCode;
auto SetValue(const std::vector<bool> &values) -> StatusCode;
auto SetValue(const int64_t value) -> StatusCode;
auto SetValue(const bool value) -> StatusCode;
/**
* Set the unit of this property.
*/
......@@ -688,10 +697,15 @@ public:
auto SetValue(const Value &value) -> StatusCode;
auto SetValue(const std::string &value) -> StatusCode;
auto SetValue(const char *value) -> StatusCode;
auto SetValue(const double value) -> StatusCode;
// TODO(tf)
// auto SetValue(const int64_t value) -> StatusCode;
// auto SetValue(const bool value) -> StatusCode;
auto SetValue(const std::vector<std::string> &values) -> StatusCode;
auto SetValue(const std::vector<char *> &values) -> StatusCode;
auto SetValue(const std::vector<int64_t> &values) -> StatusCode;
auto SetValue(const std::vector<double> &values) -> StatusCode;
auto SetValue(const std::vector<bool> &values) -> StatusCode;
auto SetValue(const int64_t value) -> StatusCode;
auto SetValue(const bool value) -> StatusCode;
auto SetUnit(const std::string &unit) -> void;
......
......@@ -111,7 +111,9 @@ public:
: ProtoMessageWrapper<ProtoValue>() {
this->wrapped->mutable_scalar_value()->set_string_value(value);
}
explicit inline Value(const char value[]) : Value(std::string(value)) {}
explicit inline Value(const char *value) : ProtoMessageWrapper<ProtoValue>() {
this->wrapped->mutable_scalar_value()->set_string_value(std::string(value));
}
explicit inline Value(double value) : ProtoMessageWrapper<ProtoValue>() {
this->wrapped->mutable_scalar_value()->set_double_value(value);
}
......@@ -123,15 +125,12 @@ public:
this->wrapped->mutable_scalar_value()->set_boolean_value(value);
}
explicit inline Value(const std::vector<std::string> &values)
: ProtoMessageWrapper<ProtoValue>() {
for (const auto &value : values) {
this->wrapped->mutable_list_values()->add_values()->set_string_value(
value);
}
}
LIST_VALUE_CONSTRUCTOR(int, set_integer_value)
LIST_VALUE_CONSTRUCTOR(int64_t, set_integer_value)
LIST_VALUE_CONSTRUCTOR(double, set_double_value)
LIST_VALUE_CONSTRUCTOR(std::string, set_string_value)
LIST_VALUE_CONSTRUCTOR(char *, set_string_value)
LIST_VALUE_CONSTRUCTOR(bool, set_boolean_value)
[[nodiscard]] inline auto IsNull() -> bool {
return this->wrapped->value_case() == ValueCase::VALUE_NOT_SET;
......
......@@ -130,10 +130,42 @@ auto Property::SetValue(const std::string &value) -> StatusCode {
return SetValue(Value(value));
}
auto Property::SetValue(const char *value) -> StatusCode {
return SetValue(Value(value));
}
auto Property::SetValue(double value) -> StatusCode {
return SetValue(Value(value));
}
auto Property::SetValue(const std::vector<std::string> &values) -> StatusCode {
return SetValue(Value(values));
}
auto Property::SetValue(const std::vector<char *> &values) -> StatusCode {
return SetValue(Value(values));
}
auto Property::SetValue(const std::vector<int64_t> &values) -> StatusCode {
return SetValue(Value(values));
}
auto Property::SetValue(const std::vector<double> &values) -> StatusCode {
return SetValue(Value(values));
}
auto Property::SetValue(const std::vector<bool> &values) -> StatusCode {
return SetValue(Value(values));
}
auto Property::SetValue(const int64_t value) -> StatusCode {
return SetValue(Value(value));
}
auto Property::SetValue(const bool value) -> StatusCode {
return SetValue(Value(value));
}
auto Property::SetUnit(const std::string &unit) -> void {
this->wrapped->set_unit(unit);
}
......@@ -223,10 +255,42 @@ auto Entity::SetValue(const std::string &value) -> StatusCode {
return SetValue(Value(value));
}
auto Entity::SetValue(const char *value) -> StatusCode {
return SetValue(Value(value));
}
auto Entity::SetValue(double value) -> StatusCode {
return SetValue(Value(value));
}
auto Entity::SetValue(const std::vector<std::string> &values) -> StatusCode {
return SetValue(Value(values));
}
auto Entity::SetValue(const std::vector<char *> &values) -> StatusCode {
return SetValue(Value(values));
}
auto Entity::SetValue(const std::vector<int64_t> &values) -> StatusCode {
return SetValue(Value(values));
}
auto Entity::SetValue(const std::vector<double> &values) -> StatusCode {
return SetValue(Value(values));
}
auto Entity::SetValue(const std::vector<bool> &values) -> StatusCode {
return SetValue(Value(values));
}
auto Entity::SetValue(const int64_t value) -> StatusCode {
return SetValue(Value(value));
}
auto Entity::SetValue(const bool value) -> StatusCode {
return SetValue(Value(value));
}
auto Entity::SetUnit(const std::string &unit) -> void {
this->wrapped->set_unit(unit);
}
......
......@@ -26,6 +26,7 @@ set(test_cases
test_entity
test_file_transmission
test_info
test_list_properties
test_protobuf
test_transaction
test_utility
......
/*
*
* This file is a part of the CaosDB Project.
*
* Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
* Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
#include "caosdb/data_type.h" // for DataType, AtomicDataType
#include "caosdb/entity.h" // for Entity
#include "caosdb/entity/v1alpha1/main.pb.h" // for AtomicDataType, DataType
#include "caosdb/value.h" // for Value
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApi...
#include <gtest/gtest_pred_impl.h> // for AssertionResult, Test
#include <memory> // for allocator_traits<>::valu...
#include <string> // for string
#include <vector> // for vector
namespace caosdb::entity {
using ProtoEntity = caosdb::entity::v1alpha1::Entity;
using ProtoParent = caosdb::entity::v1alpha1::Parent;
using ProtoDataType = caosdb::entity::v1alpha1::DataType;
using ProtoAtomicDataType = caosdb::entity::v1alpha1::AtomicDataType;
TEST(test_list_property, test_list_of_text) {
Property list_property;
list_property.SetDataType(DataType::ListOf(AtomicDataType::TEXT));
std::vector<std::string> in_value{"item1", "item2", "item3"};
list_property.SetValue(in_value);
Entity entity;
entity.SetRole(Role::RECORD_TYPE);
entity.SetName("TestRT");
entity.AppendProperty(list_property);
const auto &data_type = entity.GetProperties().at(0).GetDataType();
const auto &value = entity.GetProperties().at(0).GetValue();
EXPECT_TRUE(data_type.IsList());
EXPECT_TRUE(data_type.AsList().IsListOfAtomic());
EXPECT_EQ(data_type.AsList().GetAtomicDataType(), AtomicDataType::TEXT);
EXPECT_TRUE(value.IsList());
EXPECT_EQ(value.AsList().size(), 3);
EXPECT_TRUE(value.AsList().at(1).IsString());
EXPECT_EQ(value.AsList().at(1).AsString(), "item2");
}
} // namespace caosdb::entity
......@@ -48,7 +48,7 @@ TEST(test_value, test_null) {
}
TEST(test_value, test_string) {
Value value("test");
Value value(std::string("test"));
EXPECT_FALSE(value.IsNull());
EXPECT_TRUE(value.IsString());
EXPECT_FALSE(value.IsDouble());
......@@ -57,7 +57,7 @@ TEST(test_value, test_string) {
EXPECT_EQ(value.AsString(), "test");
Value empty_string("");
Value empty_string(std::string(""));
EXPECT_FALSE(empty_string.IsNull());
EXPECT_TRUE(empty_string.IsString());
EXPECT_FALSE(empty_string.IsDouble());
......