Skip to content

Commit

Permalink
Cleanup virtual/override/final in DataStorm (#3024)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Oct 31, 2024
1 parent e5261ff commit 3d9a742
Show file tree
Hide file tree
Showing 14 changed files with 115 additions and 117 deletions.
2 changes: 0 additions & 2 deletions cpp/include/DataStorm/DataStorm.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

namespace DataStorm
{

/**
* A sample provides information about a data element update.
*
Expand Down Expand Up @@ -2083,7 +2082,6 @@ namespace DataStorm
{
return _topicFactory->getCommunicator();
}

}

#if defined(__clang__)
Expand Down
14 changes: 7 additions & 7 deletions cpp/include/DataStorm/InternalI.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace DataStormI
virtual std::int64_t getId() const = 0;
};

class Key : public Filterable, virtual public Element
class Key : public Filterable, public virtual Element
{
};

Expand All @@ -55,7 +55,7 @@ namespace DataStormI
virtual std::shared_ptr<Key> decode(const Ice::CommunicatorPtr&, const Ice::ByteSeq&) = 0;
};

class Tag : virtual public Element
class Tag : public virtual Element
{
};

Expand Down Expand Up @@ -129,7 +129,7 @@ namespace DataStormI
std::int64_t) = 0;
};

class Filter : virtual public Element
class Filter : public virtual Element
{
public:
virtual bool match(const std::shared_ptr<Filterable>&) const = 0;
Expand Down Expand Up @@ -176,7 +176,7 @@ namespace DataStormI
virtual Ice::CommunicatorPtr getCommunicator() const = 0;
};

class DataReader : virtual public DataElement
class DataReader : public virtual DataElement
{
public:
virtual bool hasWriters() = 0;
Expand All @@ -193,7 +193,7 @@ namespace DataStormI
std::function<void(const std::shared_ptr<Sample>&)>) = 0;
};

class DataWriter : virtual public DataElement
class DataWriter : public virtual DataElement
{
public:
virtual bool hasReaders() const = 0;
Expand Down Expand Up @@ -222,7 +222,7 @@ namespace DataStormI
virtual void destroy() = 0;
};

class TopicReader : virtual public Topic
class TopicReader : public virtual Topic
{
public:
virtual std::shared_ptr<DataReader> createFiltered(
Expand All @@ -244,7 +244,7 @@ namespace DataStormI
virtual void waitForWriters(int) const = 0;
};

class TopicWriter : virtual public Topic
class TopicWriter : public virtual Topic
{
public:
virtual std::shared_ptr<DataWriter>
Expand Down
81 changes: 37 additions & 44 deletions cpp/include/DataStorm/InternalT.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,24 @@ namespace DataStormI
}
};

template<typename T> class AbstractElementT : virtual public Element
template<typename T> class AbstractElementT : public virtual Element
{
public:
template<typename TT> AbstractElementT(TT&& v, std::int64_t id) : _value(std::forward<TT>(v)), _id(id) {}

virtual std::string toString() const override
std::string toString() const override
{
std::ostringstream os;
os << _id << ':' << Stringifier<T>::toString(_value);
return os.str();
}

virtual Ice::ByteSeq encode(const Ice::CommunicatorPtr& communicator) const override
Ice::ByteSeq encode(const Ice::CommunicatorPtr& communicator) const override
{
return EncoderT<T>::encode(communicator, _value);
}

virtual std::int64_t getId() const override { return _id; }
std::int64_t getId() const override { return _id; }

const T& get() const { return _value; }

Expand Down Expand Up @@ -242,26 +242,23 @@ namespace DataStormI
std::int64_t _nextId;
};

template<typename K> class KeyT : public Key, public AbstractElementT<K>
template<typename K> class KeyT final : public Key, public AbstractElementT<K>
{
public:
virtual std::string toString() const override { return "k" + AbstractElementT<K>::toString(); }
std::string toString() const final { return "k" + AbstractElementT<K>::toString(); }

using AbstractElementT<K>::AbstractElementT;
using BaseClassType = Key;
};

template<typename K> class KeyFactoryT : public KeyFactory, public AbstractFactoryT<K, KeyT<K>>
template<typename K> class KeyFactoryT final : public KeyFactory, public AbstractFactoryT<K, KeyT<K>>
{
public:
using AbstractFactoryT<K, KeyT<K>>::AbstractFactoryT;

virtual std::shared_ptr<Key> get(std::int64_t id) const override
{
return AbstractFactoryT<K, KeyT<K>>::getImpl(id);
}
std::shared_ptr<Key> get(std::int64_t id) const final { return AbstractFactoryT<K, KeyT<K>>::getImpl(id); }

virtual std::shared_ptr<Key> decode(const Ice::CommunicatorPtr& communicator, const Ice::ByteSeq& data) override
std::shared_ptr<Key> decode(const Ice::CommunicatorPtr& communicator, const Ice::ByteSeq& data) final
{
return AbstractFactoryT<K, KeyT<K>>::create(DecoderT<K>::decode(communicator, data));
}
Expand All @@ -274,26 +271,23 @@ namespace DataStormI
}
};

template<typename T> class TagT : public Tag, public AbstractElementT<T>
template<typename T> class TagT final : public Tag, public AbstractElementT<T>
{
public:
virtual std::string toString() const override { return "t" + AbstractElementT<T>::toString(); }
std::string toString() const final { return "t" + AbstractElementT<T>::toString(); }

using AbstractElementT<T>::AbstractElementT;
using BaseClassType = Tag;
};

template<typename T> class TagFactoryT : public TagFactory, public AbstractFactoryT<T, TagT<T>>
template<typename T> class TagFactoryT final : public TagFactory, public AbstractFactoryT<T, TagT<T>>
{
public:
using AbstractFactoryT<T, TagT<T>>::AbstractFactoryT;

virtual std::shared_ptr<Tag> get(std::int64_t id) const override
{
return AbstractFactoryT<T, TagT<T>>::getImpl(id);
}
std::shared_ptr<Tag> get(std::int64_t id) const final { return AbstractFactoryT<T, TagT<T>>::getImpl(id); }

virtual std::shared_ptr<Tag> decode(const Ice::CommunicatorPtr& communicator, const Ice::ByteSeq& data) override
std::shared_ptr<Tag> decode(const Ice::CommunicatorPtr& communicator, const Ice::ByteSeq& data) final
{
return AbstractFactoryT<T, TagT<T>>::create(DecoderT<T>::decode(communicator, data));
}
Expand All @@ -307,7 +301,7 @@ namespace DataStormI
};

template<typename Key, typename Value, typename UpdateTag>
class SampleT : public Sample, public std::enable_shared_from_this<SampleT<Key, Value, UpdateTag>>
class SampleT final : public Sample, public std::enable_shared_from_this<SampleT<Key, Value, UpdateTag>>
{
public:
SampleT(
Expand Down Expand Up @@ -357,9 +351,9 @@ namespace DataStormI
_hasValue = true;
}

virtual bool hasValue() const override { return _hasValue; }
bool hasValue() const final { return _hasValue; }

virtual void setValue(const std::shared_ptr<Sample>& sample) override
void setValue(const std::shared_ptr<Sample>& sample) final
{
if (sample)
{
Expand All @@ -373,7 +367,7 @@ namespace DataStormI
_hasValue = true;
}

virtual const Ice::ByteSeq& encode(const Ice::CommunicatorPtr& communicator) override
const Ice::ByteSeq& encode(const Ice::CommunicatorPtr& communicator) final
{
if (_encodedValue.empty())
{
Expand All @@ -382,13 +376,13 @@ namespace DataStormI
return _encodedValue;
}

virtual Ice::ByteSeq encodeValue(const Ice::CommunicatorPtr& communicator) override
Ice::ByteSeq encodeValue(const Ice::CommunicatorPtr& communicator) final
{
assert(_hasValue || event == DataStorm::SampleEvent::Remove);
return EncoderT<Value>::encode(communicator, _value);
}

virtual void decode(const Ice::CommunicatorPtr& communicator) override
void decode(const Ice::CommunicatorPtr& communicator) final
{
if (!_encodedValue.empty())
{
Expand All @@ -403,18 +397,18 @@ namespace DataStormI
Value _value;
};

template<typename Key, typename Value, typename UpdateTag> class SampleFactoryT : public SampleFactory
template<typename Key, typename Value, typename UpdateTag> class SampleFactoryT final : public SampleFactory
{
public:
virtual std::shared_ptr<Sample> create(
std::shared_ptr<Sample> create(
std::string session,
std::string origin,
std::int64_t id,
DataStorm::SampleEvent type,
const std::shared_ptr<DataStormI::Key>& key,
const std::shared_ptr<DataStormI::Tag>& tag,
Ice::ByteSeq value,
std::int64_t timestamp)
std::int64_t timestamp) final
{
return std::make_shared<SampleT<Key, Value, UpdateTag>>(
std::move(session),
Expand All @@ -428,22 +422,22 @@ namespace DataStormI
}
};

template<typename C, typename V> class FilterT : public Filter, public AbstractElementT<C>
template<typename C, typename V> class FilterT final : public Filter, public AbstractElementT<C>
{
public:
template<typename CC>
FilterT(CC&& criteria, std::int64_t id) : AbstractElementT<C>::AbstractElementT(std::forward<CC>(criteria), id)
{
}

virtual std::string toString() const override { return "f" + AbstractElementT<C>::toString(); }
std::string toString() const final { return "f" + AbstractElementT<C>::toString(); }

virtual bool match(const std::shared_ptr<Filterable>& value) const override
bool match(const std::shared_ptr<Filterable>& value) const final
{
return _lambda(std::static_pointer_cast<V>(value)->get());
}

virtual const std::string& getName() const override { return _name; }
const std::string& getName() const final { return _name; }

template<typename FF> void init(const std::string& name, FF&& lambda)
{
Expand All @@ -459,18 +453,17 @@ namespace DataStormI
};

template<typename C, typename V>
class FilterFactoryT : public FilterFactory, public AbstractFactoryT<C, FilterT<C, V>>
class FilterFactoryT final : public FilterFactory, public AbstractFactoryT<C, FilterT<C, V>>
{
public:
FilterFactoryT() {}

virtual std::shared_ptr<Filter> get(std::int64_t id) const override
std::shared_ptr<Filter> get(std::int64_t id) const final
{
return AbstractFactoryT<C, FilterT<C, V>>::getImpl(id);
}

virtual std::shared_ptr<Filter>
decode(const Ice::CommunicatorPtr& communicator, const Ice::ByteSeq& data) override
std::shared_ptr<Filter> decode(const Ice::CommunicatorPtr& communicator, const Ice::ByteSeq& data) final
{
return AbstractFactoryT<C, FilterT<C, V>>::create(DecoderT<C>::decode(communicator, data));
}
Expand All @@ -483,7 +476,7 @@ namespace DataStormI
}
};

template<typename ValueT> class FilterManagerT : public FilterManager
template<typename ValueT> class FilterManagerT final : public FilterManager
{
using Value = typename std::remove_reference<decltype(std::declval<ValueT>().get())>::type;

Expand All @@ -496,7 +489,7 @@ namespace DataStormI
virtual std::shared_ptr<Filter> decode(const Ice::CommunicatorPtr&, const Ice::ByteSeq&) = 0;
};

template<typename Criteria> struct FactoryT : Factory
template<typename Criteria> struct FactoryT final : Factory
{
FactoryT(std::string name, std::function<std::function<bool(const Value&)>(const Criteria&)> lambda)
: name(std::move(name)),
Expand All @@ -511,9 +504,9 @@ namespace DataStormI
return filter;
}

virtual std::shared_ptr<Filter> get(std::int64_t id) const { return filterFactory.get(id); }
std::shared_ptr<Filter> get(std::int64_t id) const final { return filterFactory.get(id); }

virtual std::shared_ptr<Filter> decode(const Ice::CommunicatorPtr& communicator, const Ice::ByteSeq& data)
std::shared_ptr<Filter> decode(const Ice::CommunicatorPtr& communicator, const Ice::ByteSeq& data) final
{
return create(DecoderT<Criteria>::decode(communicator, data));
}
Expand Down Expand Up @@ -543,8 +536,8 @@ namespace DataStormI
return factory->create(criteria);
}

virtual std::shared_ptr<Filter>
decode(const Ice::CommunicatorPtr& communicator, const std::string& name, const Ice::ByteSeq& data) override
std::shared_ptr<Filter>
decode(const Ice::CommunicatorPtr& communicator, const std::string& name, const Ice::ByteSeq& data) final
{
auto p = _factories.find(name);
if (p == _factories.end())
Expand All @@ -555,7 +548,7 @@ namespace DataStormI
return p->second->decode(communicator, data);
}

virtual std::shared_ptr<Filter> get(const std::string& name, std::int64_t id) const override
std::shared_ptr<Filter> get(const std::string& name, std::int64_t id) const final
{
auto p = _factories.find(name);
if (p == _factories.end())
Expand Down
4 changes: 2 additions & 2 deletions cpp/include/DataStorm/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ namespace DataStorm
*
* @headerfile DataStorm/DataStorm.h
*/
class DATASTORM_API NodeShutdownException : public std::exception
class DATASTORM_API NodeShutdownException final : public std::exception
{
public:
virtual const char* what() const noexcept;
const char* what() const noexcept final;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/DataStorm/CallbackExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace DataStormI
{
class DataElementI;

class CallbackExecutor
class CallbackExecutor final
{
public:
CallbackExecutor(std::function<void(std::function<void()> call)> customExecutor);
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/DataStorm/ConnectionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace DataStormI
{
class CallbackExecutor;

class ConnectionManager : public std::enable_shared_from_this<ConnectionManager>
class ConnectionManager final : public std::enable_shared_from_this<ConnectionManager>
{
public:
ConnectionManager(const std::shared_ptr<CallbackExecutor>&);
Expand Down
Loading

0 comments on commit 3d9a742

Please sign in to comment.