diff --git a/include/maidsafe/common/data_types/data.h b/include/maidsafe/common/data_types/data.h index 8f49f3ea..8fc8ad85 100644 --- a/include/maidsafe/common/data_types/data.h +++ b/include/maidsafe/common/data_types/data.h @@ -49,9 +49,9 @@ class Data { Data(); Data(const Data&); - Data(Data&& other); + Data(Data&& other) MAIDSAFE_NOEXCEPT; Data& operator=(const Data&); - Data& operator=(Data&& other); + Data& operator=(Data&& other) MAIDSAFE_NOEXCEPT; virtual ~Data(); // Returns false for a default-constructed instance of this class, otherwise true. diff --git a/include/maidsafe/common/data_types/immutable_data.h b/include/maidsafe/common/data_types/immutable_data.h index aff9eaa8..98640e47 100644 --- a/include/maidsafe/common/data_types/immutable_data.h +++ b/include/maidsafe/common/data_types/immutable_data.h @@ -35,6 +35,8 @@ namespace maidsafe { class ImmutableData : public Data { public: + static NameAndTypeId MakeNameAndTypeId(Identity name); + explicit ImmutableData(NonEmptyString value); ImmutableData(); @@ -65,7 +67,7 @@ class ImmutableData : public Data { } private: - virtual std::uint32_t ThisTypeId() const final { return 0; } + virtual std::uint32_t ThisTypeId() const final; NonEmptyString value_; }; diff --git a/include/maidsafe/common/data_types/mutable_data.h b/include/maidsafe/common/data_types/mutable_data.h index ba1a1dc1..81ec4e7e 100644 --- a/include/maidsafe/common/data_types/mutable_data.h +++ b/include/maidsafe/common/data_types/mutable_data.h @@ -22,6 +22,7 @@ #include "cereal/types/base_class.hpp" #include "cereal/types/polymorphic.hpp" +#include "maidsafe/common/config.h" #include "maidsafe/common/identity.h" #include "maidsafe/common/log.h" #include "maidsafe/common/types.h" @@ -34,13 +35,15 @@ namespace maidsafe { class MutableData : public Data { public: + static NameAndTypeId MakeNameAndTypeId(Identity name); + MutableData(Identity name, NonEmptyString value); MutableData(); MutableData(const MutableData&); - MutableData(MutableData&& other); + MutableData(MutableData&& other) MAIDSAFE_NOEXCEPT; MutableData& operator=(const MutableData&); - MutableData& operator=(MutableData&& other); + MutableData& operator=(MutableData&& other) MAIDSAFE_NOEXCEPT; virtual ~MutableData() final; const NonEmptyString& Value() const; @@ -64,7 +67,7 @@ class MutableData : public Data { } private: - virtual std::uint32_t ThisTypeId() const final { return 1; } + virtual std::uint32_t ThisTypeId() const final; NonEmptyString value_; }; diff --git a/include/maidsafe/common/data_units.h b/include/maidsafe/common/data_units.h new file mode 100644 index 00000000..e47c567d --- /dev/null +++ b/include/maidsafe/common/data_units.h @@ -0,0 +1,35 @@ +/* Copyright 2015 MaidSafe.net limited + + This MaidSafe Software is licensed to you under (1) the MaidSafe.net Commercial License, + version 1.0 or later, or (2) The General Public License (GPL), version 3, depending on which + licence you accepted on initial access to the Software (the "Licences"). + + By contributing code to the MaidSafe Software, or to this project generally, you agree to be + bound by the terms of the MaidSafe Contributor Agreement, version 1.0, found in the root + directory of this project at LICENSE, COPYING and CONTRIBUTOR respectively and also + available at: http://www.maidsafe.net/licenses + + Unless required by applicable law or agreed to in writing, the MaidSafe Software distributed + under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS + OF ANY KIND, either express or implied. + + See the Licences for the specific language governing permissions and limitations relating to + use of the MaidSafe Software. */ + +#ifndef MAIDSAFE_COMMON_DATA_UNITS_H_ +#define MAIDSAFE_COMMON_DATA_UNITS_H_ + +#include + +namespace maidsafe { +// SI units. +using Bytes = std::chrono::duration; +using KiloBytes = std::chrono::duration; +using MegaBytes = std::chrono::duration; +using GigaBytes = std::chrono::duration; +using TeraBytes = std::chrono::duration; +using PetaBytes = std::chrono::duration; +using ExaBytes = std::chrono::duration; +} + +#endif // MAIDSAFE_COMMON_DATA_UNITS_H_ diff --git a/src/maidsafe/common/data_types/data.cc b/src/maidsafe/common/data_types/data.cc index c66e2279..d507122f 100644 --- a/src/maidsafe/common/data_types/data.cc +++ b/src/maidsafe/common/data_types/data.cc @@ -53,11 +53,11 @@ Data::Data() = default; Data::Data(const Data&) = default; -Data::Data(Data&& other) : name_(std::move(other.name_)) {} +Data::Data(Data&& other) MAIDSAFE_NOEXCEPT : name_(std::move(other.name_)) {} Data& Data::operator=(const Data&) = default; -Data& Data::operator=(Data&& other) { +Data& Data::operator=(Data&& other) MAIDSAFE_NOEXCEPT { name_ = std::move(other.name_); return *this; } diff --git a/src/maidsafe/common/data_types/immutable_data.cc b/src/maidsafe/common/data_types/immutable_data.cc index fb13bb82..90c5264e 100644 --- a/src/maidsafe/common/data_types/immutable_data.cc +++ b/src/maidsafe/common/data_types/immutable_data.cc @@ -23,6 +23,13 @@ #include "maidsafe/common/error.h" namespace maidsafe { +namespace { +const std::uint32_t kTypeId = 0; +} + +Data::NameAndTypeId ImmutableData::MakeNameAndTypeId(Identity name) { + return NameAndTypeId{std::move(name), DataTypeId{kTypeId}}; +} ImmutableData::ImmutableData(NonEmptyString value) : Data(crypto::Hash(value)), value_(std::move(value)) {} @@ -50,4 +57,6 @@ const NonEmptyString& ImmutableData::Value() const { return value_; } +std::uint32_t ImmutableData::ThisTypeId() const { return kTypeId; } + } // namespace maidsafe diff --git a/src/maidsafe/common/data_types/mutable_data.cc b/src/maidsafe/common/data_types/mutable_data.cc index 5df83a92..62a9d635 100644 --- a/src/maidsafe/common/data_types/mutable_data.cc +++ b/src/maidsafe/common/data_types/mutable_data.cc @@ -26,6 +26,13 @@ #include "maidsafe/common/serialisation/serialisation.h" namespace maidsafe { +namespace { +const std::uint32_t kTypeId = 1; +} + +Data::NameAndTypeId MutableData::MakeNameAndTypeId(Identity name) { + return NameAndTypeId{std::move(name), DataTypeId{kTypeId}}; +} MutableData::MutableData(Identity name, NonEmptyString value) : Data(std::move(name)), value_(std::move(value)) { @@ -43,12 +50,12 @@ MutableData::MutableData() = default; MutableData::MutableData(const MutableData&) = default; -MutableData::MutableData(MutableData&& other) +MutableData::MutableData(MutableData&& other) MAIDSAFE_NOEXCEPT : Data(std::move(other)), value_(std::move(other.value_)) {} MutableData& MutableData::operator=(const MutableData&) = default; -MutableData& MutableData::operator=(MutableData&& other) { +MutableData& MutableData::operator=(MutableData&& other) MAIDSAFE_NOEXCEPT { Data::operator=(std::move(other)); value_ = std::move(other.value_); return *this; @@ -62,4 +69,6 @@ const NonEmptyString& MutableData::Value() const { return value_; } +std::uint32_t MutableData::ThisTypeId() const { return kTypeId; } + } // namespace maidsafe diff --git a/src/maidsafe/common/data_types/tests/derived_data_test.cc b/src/maidsafe/common/data_types/tests/derived_data_test.cc index ed4c47e0..587eb1a6 100644 --- a/src/maidsafe/common/data_types/tests/derived_data_test.cc +++ b/src/maidsafe/common/data_types/tests/derived_data_test.cc @@ -51,6 +51,8 @@ class DerivedDataTest : public testing::Test { } } + T GetData(); + const NonEmptyString value_; Identity name_; T data_; @@ -58,7 +60,6 @@ class DerivedDataTest : public testing::Test { private: Identity GetName(); - T GetData(); }; template <> @@ -137,6 +138,11 @@ TYPED_TEST(DerivedDataTest, BEH_SerialiseParse) { EXPECT_TRUE(Equal(&this->data_, dynamic_cast(parsed_ptr.get()))); } +TYPED_TEST(DerivedDataTest, MakeNameAndTypeId) { + const auto data = this->GetData(); + const auto name_and_type = TypeParam::MakeNameAndTypeId(this->name_); + EXPECT_EQ(data.TypeId(), name_and_type.type_id); + EXPECT_EQ(data.Name(), name_and_type.name); +} } // namespace test - } // namespace maidsafe