diff --git a/CHANGELOG.md b/CHANGELOG.md index db5c51ad6eeafd5ebe5a66e9b50bc00c1f0cc947..ec80782f4ac28d9e9081599f0ccc3639a2bb6a8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +* Integer values are 32 bit now. + ### Deprecated ### Removed diff --git a/Makefile b/Makefile index e5d2bc3a6a0dcedeb2f0dd89018a9ef01a2fb4f6..84a07651b80dc6039b4ec8c534e730b84811fb3b 100644 --- a/Makefile +++ b/Makefile @@ -37,5 +37,11 @@ style: conan-install: conan install . -s "compiler.libcxx=libstdc++11" +.PHONY: conan-install + +conan-create: conan create . -s "compiler.libcxx=libstdc++11" -.PHONY: install +.PHONY: conan-create + +conan: conan-install conan-create +.PHONY: conan diff --git a/doc/README_SETUP.md b/doc/README_SETUP.md index 8549214ec483acede205f7badf1b8184c01bd7ed..a5976af95de78a01e6ae174e39cc6a66881c28ac 100644 --- a/doc/README_SETUP.md +++ b/doc/README_SETUP.md @@ -50,7 +50,7 @@ as compiler. We use [cmake](https://cmake.org/download/) as build tool. ### Creating a Local Conan Package ## -Building and installing libcaosdb with Conan is just a single command: `make conan-install` +Building and installing libcaosdb with Conan is just a single command: `make conan` For MacOS, you probably should adjust the option as mentioned above. diff --git a/include/caosdb/entity.h b/include/caosdb/entity.h index 08a7be6b0f6f2b42752ff78f2a004e7196e9e757..f5b5a590306df4526d961f8c9a1aa52ba0066444 100644 --- a/include/caosdb/entity.h +++ b/include/caosdb/entity.h @@ -518,10 +518,10 @@ public: auto SetValue(const double 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<int32_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 int32_t value) -> StatusCode; auto SetValue(const bool value) -> StatusCode; /** @@ -681,10 +681,10 @@ public: auto SetValue(const double 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<int32_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 int32_t value) -> StatusCode; auto SetValue(const bool value) -> StatusCode; auto SetUnit(const std::string &unit) -> void; diff --git a/include/caosdb/transaction.h b/include/caosdb/transaction.h index f92cf28f8ed670177629f5534cb9777f25e1fa1b..6fd9d026a728990710973469887e19799c69fd81 100644 --- a/include/caosdb/transaction.h +++ b/include/caosdb/transaction.h @@ -366,8 +366,8 @@ public: [[nodiscard]] inline auto GetResultSet() const noexcept -> const ResultSet & { if (!this->result_set) { - this->result_set = std::make_unique<MultiResultSet>( - std::move(std::vector<std::unique_ptr<Entity>>())); + this->result_set = + std::make_unique<MultiResultSet>(std::move(std::vector<std::unique_ptr<Entity>>())); } return *(this->result_set.get()); } diff --git a/include/ccaosdb.h b/include/ccaosdb.h index e643e0d4fa048495036341ae18556ce8ebf557b7..cfe5cf446511d7272554cf4ac7be958bb0a55c11 100644 --- a/include/ccaosdb.h +++ b/include/ccaosdb.h @@ -19,6 +19,9 @@ * <https://www.gnu.org/licenses/>. * */ + +#include <cstdint> // for uint32_t + #ifdef __cplusplus extern "C" { #endif @@ -342,11 +345,11 @@ int caosdb_entity_entity_get_datatype(caosdb_entity_entity *entity, char **name, bool *is_list); int caosdb_entity_entity_get_unit(caosdb_entity_entity *entity, char **out); -int caosdb_entity_entity_get_int_value(caosdb_entity_entity *entity, long *out); +int caosdb_entity_entity_get_int_value(caosdb_entity_entity *entity, int32_t *out); int caosdb_entity_entity_get_double_value(caosdb_entity_entity *entity, double *out); int caosdb_entity_entity_get_boolean_value(caosdb_entity_entity *entity, bool *out); int caosdb_entity_entity_get_string_value(caosdb_entity_entity *entity, char **out); -int caosdb_entity_entity_get_int_list_value_at(caosdb_entity_entity *entity, long *out, +int caosdb_entity_entity_get_int_list_value_at(caosdb_entity_entity *entity, int32_t *out, const int index); int caosdb_entity_entity_get_double_list_value_at(caosdb_entity_entity *entity, double *out, const int index); @@ -384,11 +387,11 @@ int caosdb_entity_property_get_datatype(caosdb_entity_property *property, char * bool *is_list); int caosdb_entity_property_get_unit(caosdb_entity_property *property, char **out); -int caosdb_entity_property_get_int_value(caosdb_entity_property *property, long *out); +int caosdb_entity_property_get_int_value(caosdb_entity_property *property, int32_t *out); int caosdb_entity_property_get_double_value(caosdb_entity_property *property, double *out); int caosdb_entity_property_get_boolean_value(caosdb_entity_property *property, bool *out); int caosdb_entity_property_get_string_value(caosdb_entity_property *property, char **out); -int caosdb_entity_property_get_int_list_value_at(caosdb_entity_property *property, long *out, +int caosdb_entity_property_get_int_list_value_at(caosdb_entity_property *property, int32_t *out, const int index); int caosdb_entity_property_get_double_list_value_at(caosdb_entity_property *property, double *out, const int index); @@ -426,11 +429,11 @@ int caosdb_entity_entity_set_datatype(caosdb_entity_entity *entity, const char * const bool is_ref, const bool is_list); int caosdb_entity_entity_set_unit(caosdb_entity_entity *entity, const char *unit); // TODO(fspreck) replace by more specific setters -int caosdb_entity_entity_set_int_value(caosdb_entity_entity *entity, const long value); +int caosdb_entity_entity_set_int_value(caosdb_entity_entity *entity, const int32_t value); int caosdb_entity_entity_set_double_value(caosdb_entity_entity *entity, const double value); int caosdb_entity_entity_set_boolean_value(caosdb_entity_entity *entity, const bool value); int caosdb_entity_entity_set_string_value(caosdb_entity_entity *entity, const char *value); -int caosdb_entity_entity_set_int_list_value(caosdb_entity_entity *entity, const long *value, +int caosdb_entity_entity_set_int_list_value(caosdb_entity_entity *entity, const int32_t *value, const int length); int caosdb_entity_entity_set_double_list_value(caosdb_entity_entity *entity, const double *value, const int length); @@ -455,12 +458,12 @@ int caosdb_entity_property_set_datatype(caosdb_entity_property *property, const int caosdb_entity_property_set_importance(caosdb_entity_property *property, const char *importance); int caosdb_entity_property_set_unit(caosdb_entity_property *property, const char *unit); -int caosdb_entity_property_set_int_value(caosdb_entity_property *property, const long value); +int caosdb_entity_property_set_int_value(caosdb_entity_property *property, const int32_t value); int caosdb_entity_property_set_double_value(caosdb_entity_property *property, const double value); int caosdb_entity_property_set_boolean_value(caosdb_entity_property *property, const bool value); int caosdb_entity_property_set_string_value(caosdb_entity_property *property, const char *value); -int caosdb_entity_property_set_int_list_value(caosdb_entity_property *property, const long *value, - const int length); +int caosdb_entity_property_set_int_list_value(caosdb_entity_property *property, + const int32_t *value, const int length); int caosdb_entity_property_set_double_list_value(caosdb_entity_property *property, const double *value, const int length); int caosdb_entity_property_set_boolean_list_value(caosdb_entity_property *property, diff --git a/proto b/proto index 6f81c44a02b9258293bfb83b4de7831ef8d7c4e9..1857e2fe407810baf18641429f54e5eee7b71e6a 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 6f81c44a02b9258293bfb83b4de7831ef8d7c4e9 +Subproject commit 1857e2fe407810baf18641429f54e5eee7b71e6a diff --git a/src/caosdb/entity.cpp b/src/caosdb/entity.cpp index 3e14a90f9e1ef3f3d53e5bf7141b2063a70c398e..ed7ede3b5a59fb1bb4fb4138f4aa89296bc57b43 100644 --- a/src/caosdb/entity.cpp +++ b/src/caosdb/entity.cpp @@ -23,8 +23,10 @@ #include "caosdb/data_type.h" // for DataType #include "caosdb/entity/v1alpha1/main.pb.h" // for Messages #include "caosdb/exceptions.h" +#include "caosdb/logging.h" // for CAOSDB_LOG_TRACE #include "caosdb/protobuf_helper.h" // for get_arena -#include "caosdb/value.h" // for Value +#include "caosdb/utility.h" +#include "caosdb/value.h" // for Value #include <boost/algorithm/string.hpp> #include <google/protobuf/arena.h> // for Arena #include <google/protobuf/generated_message_util.h> // for Arena::Create... @@ -130,7 +132,7 @@ auto Property::SetValue(const std::vector<char *> &values) -> StatusCode { return SetValue(Value(values)); } -auto Property::SetValue(const std::vector<int64_t> &values) -> StatusCode { +auto Property::SetValue(const std::vector<int32_t> &values) -> StatusCode { return SetValue(Value(values)); } @@ -142,7 +144,7 @@ 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 int32_t value) -> StatusCode { return SetValue(Value(value)); } auto Property::SetValue(const bool value) -> StatusCode { return SetValue(Value(value)); } @@ -231,7 +233,7 @@ auto Entity::SetValue(const std::vector<char *> &values) -> StatusCode { return SetValue(Value(values)); } -auto Entity::SetValue(const std::vector<int64_t> &values) -> StatusCode { +auto Entity::SetValue(const std::vector<int32_t> &values) -> StatusCode { return SetValue(Value(values)); } @@ -243,7 +245,7 @@ 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 int32_t value) -> StatusCode { return SetValue(Value(value)); } auto Entity::SetValue(const bool value) -> StatusCode { return SetValue(Value(value)); } @@ -277,6 +279,7 @@ template <typename E> auto FixValueImpl(E *ent) -> void { // NOLINT const auto &dtype = ent->GetDataType(); const auto &value = ent->GetValue(); auto new_value = Value(); + CAOSDB_LOG_TRACE(logger_name) << "FixValueImpl()\n" << value.ToString(); if (value.IsNull() || !value.IsString()) { // Don't treat NULL and non-string values. return; } @@ -306,9 +309,9 @@ template <typename E> auto FixValueImpl(E *ent) -> void { // NOLINT } new_value = Value(data); } else if (atype == AtomicDataType::INTEGER) { - std::vector<int64_t> data; + std::vector<int32_t> data; for (auto &d : value.AsList()) { - data.push_back(std::stol(d.AsString())); + data.push_back(std::stoi(d.AsString())); } new_value = Value(data); } else if (atype == AtomicDataType::BOOLEAN) { @@ -340,8 +343,12 @@ template <typename E> auto FixValueImpl(E *ent) -> void { // NOLINT atype == AtomicDataType::DATETIME) { return; } + CAOSDB_LOG_TRACE(logger_name) << "AtomicDataType: " + << caosdb::utility::getEnumNameFromValue(atype); if (atype == AtomicDataType::DOUBLE) { - new_value = Value(std::stod(value.AsString())); + CAOSDB_LOG_TRACE(logger_name) << "double: " << value.AsString(); + new_value = Value(std::strtod(value.AsString().c_str(), nullptr)); + CAOSDB_LOG_TRACE(logger_name) << " -> " << new_value.AsDouble(); } else if (atype == AtomicDataType::INTEGER) { new_value = Value(std::stol(value.AsString())); } else if (atype == AtomicDataType::BOOLEAN) { diff --git a/src/ccaosdb.cpp b/src/ccaosdb.cpp index bd2cbf662ee2fd88369f5d52ae08160ff9f175af..b4c7ea1aac3aae3fd5ac539815883d0ea905d56f 100644 --- a/src/ccaosdb.cpp +++ b/src/ccaosdb.cpp @@ -640,7 +640,9 @@ ERROR_RETURN_CODE(GENERIC_ERROR, return 0; }) ERROR_RETURN_CODE(GENERIC_ERROR, - int caosdb_entity_entity_get_int_value(caosdb_entity_entity *entity, long *out), { + int caosdb_entity_entity_get_int_value(caosdb_entity_entity *entity, + int32_t *out), + { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); *out = wrapped_entity->GetValue().AsInteger(); return 0; @@ -665,7 +667,7 @@ CAOSDB_ENTITY_GET(string_value, GetValue().AsString()) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_entity_get_int_list_value_at(caosdb_entity_entity *entity, - long *out, const int index), + int32_t *out, const int index), { auto *wrapped_entity = WRAPPED_ENTITY_CAST(entity); auto value_list = wrapped_entity->GetValue().AsList(); @@ -894,7 +896,7 @@ CAOSDB_PROPERTY_GET(unit, GetUnit()) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_property_get_int_value(caosdb_entity_property *property, - long *out), + int32_t *out), { auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); *out = wrapped_property->GetValue().AsInteger(); @@ -920,7 +922,7 @@ CAOSDB_PROPERTY_GET(string_value, GetValue().AsString()) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_property_get_int_list_value_at(caosdb_entity_property *property, - long *out, const int index), + int32_t *out, const int index), { auto *wrapped_property = WRAPPED_PROPERTY_CAST(property); auto value_list = wrapped_property->GetValue().AsList(); @@ -1037,7 +1039,7 @@ CAOSDB_ENTITY_SET(unit, unit, wrapped_entity->SetUnit(std::string(unit));) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_entity_set_int_value(caosdb_entity_entity *entity, - const long value), + const int32_t value), { auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); @@ -1077,11 +1079,12 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_entity_set_int_list_value(caosdb_entity_entity *entity, - const long *value, const int length), + const int32_t *value, + const int length), { auto *wrapped_entity = static_cast<caosdb::entity::Entity *>(entity->wrapped_entity); - std::vector<long> value_list; + std::vector<int32_t> value_list; for (int i = 0; i < length; i++) { value_list.push_back(value[i]); } @@ -1223,7 +1226,7 @@ CAOSDB_PROPERTY_SET(unit, unit, wrapped_property->SetUnit(std::string(unit));) ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_property_set_int_value(caosdb_entity_property *property, - const long value), + const int32_t value), { auto *wrapped_property = static_cast<caosdb::entity::Property *>(property->wrapped_property); @@ -1263,12 +1266,12 @@ ERROR_RETURN_CODE(GENERIC_ERROR, ERROR_RETURN_CODE(GENERIC_ERROR, int caosdb_entity_property_set_int_list_value(caosdb_entity_property *property, - const long *value, + const int32_t *value, const int length), { auto *wrapped_property = static_cast<caosdb::entity::Property *>(property->wrapped_property); - std::vector<long> value_list; + std::vector<int32_t> value_list; for (int i = 0; i < length; i++) { value_list.push_back(value[i]); } diff --git a/test/test_issues.cpp b/test/test_issues.cpp index f4f560dd7e60332e83843a26eb43a7ea2187474b..2b414a76a3ee122fe2d622bdf685262e2eb4e56b 100644 --- a/test/test_issues.cpp +++ b/test/test_issues.cpp @@ -17,14 +17,14 @@ * 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/configuration.h" // for InsecureConnectionConfig... -#include "caosdb/connection.h" // for Connection -#include "caosdb/exceptions.h" // for ConnectionError +#include "caosdb/configuration.h" // for InsecureConnectionConfig... +#include "caosdb/connection.h" // for Connection +#include "caosdb/exceptions.h" // for ConnectionError #include "caosdb/status_code.h" -#include "caosdb/transaction.h" // for Transaction -#include <gtest/gtest-message.h> // for Message -#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPa... -#include <gtest/gtest_pred_impl.h> // for Test, TestInfo, TEST +#include "caosdb/transaction.h" // for Transaction +#include <gtest/gtest-message.h> // for Message +#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestPa... +#include <gtest/gtest_pred_impl.h> // for Test, TestInfo, TEST namespace caosdb::transaction { using caosdb::configuration::InsecureConnectionConfiguration;