Skip to content

Commit

Permalink
Remove class-by-value support in DataStorm
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier committed Dec 10, 2024
1 parent af4ac49 commit ed15179
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 74 deletions.
3 changes: 1 addition & 2 deletions cpp/include/DataStorm/DataStorm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1997,8 +1997,7 @@ namespace DataStorm
Value value;
if (previous)
{
value = Cloner<Value>::clone(
std::static_pointer_cast<DataStormI::SampleT<Key, Value, UpdateTag>>(previous)->getValue());
value = std::static_pointer_cast<DataStormI::SampleT<Key, Value, UpdateTag>>(previous)->getValue();
}
updater(value, Decoder<UpdateValue>::decode(communicator, next->getEncodedValue()));
std::static_pointer_cast<DataStormI::SampleT<Key, Value, UpdateTag>>(next)->setValue(std::move(value));
Expand Down
5 changes: 2 additions & 3 deletions cpp/include/DataStorm/InternalT.h
Original file line number Diff line number Diff line change
Expand Up @@ -355,12 +355,11 @@ namespace DataStormI
{
if (sample)
{
_value = DataStorm::Cloner<Value>::clone(
std::static_pointer_cast<DataStormI::SampleT<Key, Value, UpdateTag>>(sample)->getValue());
_value = std::static_pointer_cast<DataStormI::SampleT<Key, Value, UpdateTag>>(sample)->getValue();
}
else
{
_value = Value();
_value = Value{};
}
_hasValue = true;
}
Expand Down
52 changes: 0 additions & 52 deletions cpp/include/DataStorm/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,58 +240,6 @@ namespace DataStorm
static T decode(const Ice::CommunicatorPtr& communicator, const Ice::ByteSeq& value) noexcept;
};

/**
* The Cloner template provides a method to clone user types.
*
* The cloner template can be specialized to provide cloning for types that require special cloning. By
* default, the template uses plain C++ copy.
*
* @headerfile DataStorm/DataStorm.h
*/
template<typename T, typename Enabler = void> struct Cloner
{
/**
* Clone the given value. This helper is used when processing partial update to clone the previous value
* and compute the new value with the partial update. The default implementation performs a plain C++ copy
* with the copy constructor.
*
* @param value The value to encode
* @return The cloned value
*/
static T clone(const T& value) noexcept { return value; }
};

/**
* Encoder template specialization to encode Ice::Value instances.
**/
template<typename T> struct Encoder<T, typename std::enable_if<std::is_base_of<::Ice::Value, T>::value>::type>
{
static Ice::ByteSeq encode(const Ice::CommunicatorPtr& communicator, const T& value) noexcept
{
return Encoder<std::shared_ptr<T>>::encode(communicator, std::make_shared<T>(value));
}
};

/**
* Decoder template specialization to decode Ice::Value instances.
**/
template<typename T> struct Decoder<T, typename std::enable_if<std::is_base_of<::Ice::Value, T>::value>::type>
{
static T decode(const Ice::CommunicatorPtr& communicator, const Ice::ByteSeq& data) noexcept
{
return *Decoder<std::shared_ptr<T>>::decode(communicator, data);
}
};

/**
* Cloner template specialization to clone shared Ice values using ice_clone.
*/
template<typename T>
struct Cloner<std::shared_ptr<T>, typename std::enable_if<std::is_base_of<::Ice::Value, T>::value>::type>
{
static std::shared_ptr<T> clone(const std::shared_ptr<T>& value) noexcept { return value->ice_clone(); }
};

/**
* Encoder template implementation
*/
Expand Down
7 changes: 0 additions & 7 deletions cpp/test/DataStorm/types/Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,6 @@ void ::Reader::run(int argc, char* argv[])
map<StructValue, string>{{{"firstName", "lastName", 10}, "v2"}, {{"fn", "ln", 12}, "v3"}},
map<StructValue, string>{{{"firstName", "lastName", 10}, "v4"}, {{"fn", "ln", 12}, "v5"}});

/*
testReader(Topic<string, Extended>(node, "stringclassbyvalue"),
map<string, Extended> { { "k1", Extended("v1", 8) },
{ "k2", Extended("v2", 8) } },
map<string, Extended> { { "k1", Extended("v1", 10) },
{ "k2", Extended("v2", 10) } });
*/
testReader(
Topic<string, shared_ptr<Base>>(node, "stringclassbyref"),
map<string, shared_ptr<Base>>{{"k1", make_shared<Base>("v1")}, {"k2", make_shared<Base>("v2")}},
Expand Down
10 changes: 0 additions & 10 deletions cpp/test/DataStorm/types/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,6 @@ main(int argc, char* argv[])
map<StructValue, string>{{{"firstName", "lastName", 10}, "v4"}, {{"fn", "ln", 12}, "v5"}});
cout << "ok" << endl;

/*
cout << "testing string/class by value... " << flush;
testWriter(Topic<string, Extended>(node, "stringclassbyvalue"),
map<string, Extended> { { string("k1"), Extended("v1", 8) },
{ string("k2"), Extended("v2", 8) } },
map<string, Extended> { { "k1", Extended("v1", 10) },
{ "k2", Extended("v2", 10) } });
cout << "ok" << endl;
*/

cout << "testing string/class by ref... " << flush;
testWriter(
Topic<string, shared_ptr<Base>>(node, "stringclassbyref"),
Expand Down

0 comments on commit ed15179

Please sign in to comment.