Skip to content

Commit

Permalink
Fix DataStorm clang-tidy lints (#3453)
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardnormier authored Jan 30, 2025
1 parent af9b80e commit 2f089da
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 116 deletions.
129 changes: 70 additions & 59 deletions cpp/include/DataStorm/DataStorm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1360,20 +1360,23 @@ namespace DataStorm
std::function<void(std::vector<Key>)> init,
std::function<void(CallbackReason, Key)> update) noexcept
{
_impl->onConnectedKeys(init ? [init](const std::vector<std::shared_ptr<DataStormI::Key>>& connectedKeys)
{
std::vector<Key> keys;
keys.reserve(connectedKeys.size());
for(const auto& k : connectedKeys)
{
keys.push_back(std::static_pointer_cast<DataStormI::KeyT<Key>>(k)->get());
}
init(std::move(keys));
} : std::function<void(std::vector<std::shared_ptr<DataStormI::Key>>)>(),
update ? [update](CallbackReason action, std::shared_ptr<DataStormI::Key> key)
{
update(action, std::static_pointer_cast<DataStormI::KeyT<Key>>(key)->get());
} : std::function<void(CallbackReason, std::shared_ptr<DataStormI::Key>)>());
_impl->onConnectedKeys(
init ?
[init = std::move(init)](const std::vector<std::shared_ptr<DataStormI::Key>>& connectedKeys)
{
std::vector<Key> keys;
keys.reserve(connectedKeys.size());
for(const auto& k : connectedKeys)
{
keys.push_back(std::static_pointer_cast<DataStormI::KeyT<Key>>(k)->get());
}
init(std::move(keys));
} : std::function<void(std::vector<std::shared_ptr<DataStormI::Key>>)>{},
update ?
[update = std::move(update)](CallbackReason action, const std::shared_ptr<DataStormI::Key>& key)
{
update(action, std::static_pointer_cast<DataStormI::KeyT<Key>>(key)->get());
} : std::function<void(CallbackReason, std::shared_ptr<DataStormI::Key>)>{});
}

template<typename Key, typename Value, typename UpdateTag>
Expand All @@ -1390,20 +1393,23 @@ namespace DataStorm
std::function<void(Sample<Key, Value, UpdateTag>)> update) noexcept
{
auto communicator = _impl->getCommunicator();
_impl->onSamples(init ? [communicator, init](const std::vector<std::shared_ptr<DataStormI::Sample>>& samplesI)
{
std::vector<Sample<Key, Value, UpdateTag>> samples;
samples.reserve(samplesI.size());
for(const auto& s : samplesI)
{
samples.emplace_back(s);
}
init(std::move(samples));
} : std::function<void(const std::vector<std::shared_ptr<DataStormI::Sample>>&)>(),
update ? [communicator, update](const std::shared_ptr<DataStormI::Sample>& sampleI)
{
update(sampleI);
} : std::function<void(const std::shared_ptr<DataStormI::Sample>&)>());
_impl->onSamples(
init ?
[communicator, init = std::move(init)](const std::vector<std::shared_ptr<DataStormI::Sample>>& samplesI)
{
std::vector<Sample<Key, Value, UpdateTag>> samples;
samples.reserve(samplesI.size());
for(const auto& s : samplesI)
{
samples.emplace_back(s);
}
init(std::move(samples));
} : std::function<void(const std::vector<std::shared_ptr<DataStormI::Sample>>&)>(),
update ?
[communicator, update = std::move(update)](const std::shared_ptr<DataStormI::Sample>& sampleI)
{
update(sampleI);
} : std::function<void(const std::shared_ptr<DataStormI::Sample>&)>{});
}

template<typename Key, typename Value, typename UpdateTag>
Expand Down Expand Up @@ -1629,20 +1635,23 @@ namespace DataStorm
std::function<void(std::vector<Key>)> init,
std::function<void(CallbackReason, Key)> update) noexcept
{
_impl->onConnectedKeys(init ? [init](const std::vector<std::shared_ptr<DataStormI::Key>>& connectedKeys)
{
std::vector<Key> keys;
keys.reserve(connectedKeys.size());
for(const auto& k : connectedKeys)
{
keys.push_back(std::static_pointer_cast<DataStormI::KeyT<Key>>(k)->get());
}
init(std::move(keys));
} : std::function<void(std::vector<std::shared_ptr<DataStormI::Key>>)>(),
update ? [update](CallbackReason action, std::shared_ptr<DataStormI::Key> key)
{
update(action, std::static_pointer_cast<DataStormI::KeyT<Key>>(key)->get());
} : std::function<void(CallbackReason, std::shared_ptr<DataStormI::Key>)>());
_impl->onConnectedKeys(
init ?
[init = std::move(init)](const std::vector<std::shared_ptr<DataStormI::Key>>& connectedKeys)
{
std::vector<Key> keys;
keys.reserve(connectedKeys.size());
for(const auto& k : connectedKeys)
{
keys.push_back(std::static_pointer_cast<DataStormI::KeyT<Key>>(k)->get());
}
init(std::move(keys));
} : std::function<void(std::vector<std::shared_ptr<DataStormI::Key>>)>{},
update ?
[update = std::move(update)](CallbackReason action, const std::shared_ptr<DataStormI::Key>& key)
{
update(action, std::static_pointer_cast<DataStormI::KeyT<Key>>(key)->get());
} : std::function<void(CallbackReason, std::shared_ptr<DataStormI::Key>)>{});
}

template<typename Key, typename Value, typename UpdateTag>
Expand Down Expand Up @@ -1820,13 +1829,13 @@ namespace DataStorm
/** @private */
template<typename T, typename V, typename Enabler = void> struct RegexFilter
{
template<typename F> static void add(F) {}
template<typename F> static void add(const F&) {}
};

/** @private */
template<typename T, typename V> struct RegexFilter<T, V, std::enable_if_t<DataStormI::is_streamable<V>::value>>
{
template<typename F> static void add(F factory)
template<typename F> static void add(const F& factory)
{
factory->set("_regex", makeRegexFilter<T>()); // Only set the _regex filter if the value is streamable
}
Expand Down Expand Up @@ -1943,21 +1952,23 @@ namespace DataStorm
{
std::lock_guard<std::mutex> lock(_mutex);
auto tagI = _tagFactory->create(std::move(tag));
auto updaterImpl = updater ? [updater](const std::shared_ptr<DataStormI::Sample>& previous,
auto updaterImpl =
updater ?
[updater = std::move(updater)](const std::shared_ptr<DataStormI::Sample>& previous,
const std::shared_ptr<DataStormI::Sample>& next,
const Ice::CommunicatorPtr& communicator)
{
Value value;
if (previous)
{
value = Cloner<Value>::clone(
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));
} : std::function<void(const std::shared_ptr<DataStormI::Sample>&,
const std::shared_ptr<DataStormI::Sample>&,
const Ice::CommunicatorPtr&)>();
{
Value value;
if (previous)
{
value = Cloner<Value>::clone(
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));
} : std::function<void(const std::shared_ptr<DataStormI::Sample>&,
const std::shared_ptr<DataStormI::Sample>&,
const Ice::CommunicatorPtr&)>{};

if (_reader && !_writer)
{
Expand Down Expand Up @@ -1985,7 +1996,7 @@ namespace DataStorm
std::function<std::function<bool(const Key&)>(const Criteria&)> factory) noexcept
{
std::lock_guard<std::mutex> lock(_mutex);
_keyFilterFactories->set(std::move(name), factory);
_keyFilterFactories->set(std::move(name), std::move(factory));
}

template<typename Key, typename Value, typename UpdateTag>
Expand All @@ -1995,7 +2006,7 @@ namespace DataStorm
std::function<std::function<bool(const Sample<Key, Value, UpdateTag>&)>(const Criteria&)> factory) noexcept
{
std::lock_guard<std::mutex> lock(_mutex);
_sampleFilterFactories->set(std::move(name), factory);
_sampleFilterFactories->set(std::move(name), std::move(factory));
}

template<typename Key, typename Value, typename UpdateTag>
Expand Down
5 changes: 3 additions & 2 deletions cpp/include/DataStorm/InternalT.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ namespace DataStormI
{
std::lock_guard<std::mutex> lock(_mutex);
std::vector<std::shared_ptr<typename V::BaseClassType>> seq;
seq.reserve(values.size());
for (auto& v : values)
{
seq.push_back(createImpl(std::move(v)));
Expand Down Expand Up @@ -319,7 +320,7 @@ namespace DataStormI
const std::shared_ptr<DataStormI::Tag>& tag,
Ice::ByteSeq value,
std::int64_t timestamp)
: Sample(std::move(session), std::move(origin), id, event, key, tag, value, timestamp),
: Sample(std::move(session), std::move(origin), id, event, key, tag, std::move(value), timestamp),
_hasValue(false)
{
}
Expand Down Expand Up @@ -498,7 +499,7 @@ namespace DataStormI
{
}

[[nodiscard]] std::shared_ptr<Filter> create(Criteria criteria)
[[nodiscard]] std::shared_ptr<Filter> create(const Criteria& criteria)
{
return std::static_pointer_cast<FilterT<Criteria, ValueT>>(
filterFactory.create(criteria, name, lambda(criteria)));
Expand Down
12 changes: 6 additions & 6 deletions cpp/test/DataStorm/api/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void ::Writer::run(int argc, char* argv[])
Node n23(c2);
}
{
const Ice::CommunicatorPtr c3 = c;
const Ice::CommunicatorPtr& c3 = c;
Node n24(c3);
}
{
Expand Down Expand Up @@ -77,7 +77,7 @@ void ::Writer::run(int argc, char* argv[])
test(n6.isShutdown());
n6.waitForShutdown();

auto testException = [](function<void()> fn)
auto testException = [](const function<void()>& fn)
{
try
{
Expand Down Expand Up @@ -149,7 +149,7 @@ void ::Writer::run(int argc, char* argv[])
tc1.setWriterDefaultConfig(WriterConfig());
t2.setReaderDefaultConfig(ReaderConfig());

tc1.setUpdater<string>("test", [](string&, string) {});
tc1.setUpdater<string>("test", [](string&, const string&) {});
}
cout << "ok" << endl;

Expand All @@ -173,7 +173,7 @@ void ::Writer::run(int argc, char* argv[])
{
}
[[maybe_unused]] auto all = writer.getAll();
writer.onConnectedKeys([](vector<string>) {}, [](CallbackReason, string) {});
writer.onConnectedKeys([](const vector<string>&) {}, [](CallbackReason, const string&) {});
};

auto skw = makeSingleKeyWriter(topic, "key");
Expand Down Expand Up @@ -230,8 +230,8 @@ void ::Writer::run(int argc, char* argv[])
[[maybe_unused]] auto allUnread = reader.getAllUnread();
reader.waitForUnread(0);
[[maybe_unused]] bool hasUnread = reader.hasUnread();
reader.onConnectedKeys([](vector<string>) {}, [](CallbackReason, string) {});
reader.onSamples([](vector<Sample<string, string>>) {}, [](Sample<string, string>) {});
reader.onConnectedKeys([](const vector<string>&) {}, [](CallbackReason, const string&) {});
reader.onSamples([](const vector<Sample<string, string>>&) {}, [](const Sample<string, string>&) {});
};

auto skr = makeSingleKeyReader(topic, "key");
Expand Down
34 changes: 17 additions & 17 deletions cpp/test/DataStorm/callbacks/Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void ::Reader::run(int argc, char* argv[])
{
if (strcmp(argv[i], "--with-executor") == 0)
{
customExecutor = [](function<void()> cb) { cb(); };
customExecutor = [](const function<void()>& cb) { cb(); };
}
}
Node node(argc, argv, nullopt, customExecutor);
Expand Down Expand Up @@ -99,8 +99,8 @@ void ::Reader::run(int argc, char* argv[])
auto reader = makeSingleKeyReader(topic, "elem3", "", config);
promise<bool> p1, p2, p3;
reader.onConnectedKeys(
[&p1](vector<string> keys) { p1.set_value(keys.empty()); },
[&p2, &p3](CallbackReason action, string key)
[&p1](const vector<string>& keys) { p1.set_value(keys.empty()); },
[&p2, &p3](CallbackReason action, const string& key)
{
if (action == CallbackReason::Connect)
{
Expand All @@ -123,7 +123,7 @@ void ::Reader::run(int argc, char* argv[])
promise<bool> p1, p2;
reader.onConnectedKeys(
[&p1](vector<string> keys) { p1.set_value(!keys.empty() && keys[0] == "elem4"); },
[&p2](CallbackReason action, string key)
[&p2](CallbackReason action, const string& key)
{
if (action == CallbackReason::Connect)
{
Expand Down Expand Up @@ -152,8 +152,8 @@ void ::Reader::run(int argc, char* argv[])
auto reader = makeFilteredKeyReader(topic, Filter<string>("_regex", "elem3"), "", config);
promise<bool> p1, p2, p3;
reader.onConnectedKeys(
[&p1](vector<string> keys) { p1.set_value(keys.empty()); },
[&p2, &p3](CallbackReason action, string key)
[&p1](const vector<string>& keys) { p1.set_value(keys.empty()); },
[&p2, &p3](CallbackReason action, const string& key)
{
if (action == CallbackReason::Connect)
{
Expand All @@ -176,7 +176,7 @@ void ::Reader::run(int argc, char* argv[])
promise<bool> p1, p2;
reader.onConnectedKeys(
[&p1](vector<string> keys) { p1.set_value(!keys.empty() && keys[0] == "elem4"); },
[&p2](CallbackReason action, string key)
[&p2](CallbackReason action, const string& key)
{
if (action == CallbackReason::Connect)
{
Expand Down Expand Up @@ -206,8 +206,8 @@ void ::Reader::run(int argc, char* argv[])
auto reader = makeAnyKeyReader(topic, "", config);
promise<bool> p1, p2, p3;
reader.onConnectedKeys(
[&p1](vector<string> keys) { p1.set_value(keys.empty()); },
[&p2, &p3](CallbackReason action, string key)
[&p1](const vector<string>& keys) { p1.set_value(keys.empty()); },
[&p2, &p3](CallbackReason action, const string& key)
{
if (action == CallbackReason::Connect)
{
Expand Down Expand Up @@ -242,8 +242,8 @@ void ::Reader::run(int argc, char* argv[])
auto reader = makeSingleKeyReader(topic, "elem3", "", config);
promise<bool> p1, p2, p3;
reader.onConnectedWriters(
[&p1](vector<string> writers) { p1.set_value(writers.empty()); },
[&p2, &p3](CallbackReason action, string writer)
[&p1](const vector<string>& writers) { p1.set_value(writers.empty()); },
[&p2, &p3](CallbackReason action, const string& writer)
{
if (action == CallbackReason::Connect)
{
Expand All @@ -268,7 +268,7 @@ void ::Reader::run(int argc, char* argv[])
promise<bool> p1, p2;
reader.onConnectedWriters(
[&p1](vector<string> writers) { p1.set_value(!writers.empty() && writers[0] == "writer2"); },
[&p2](CallbackReason action, string writer)
[&p2](CallbackReason action, const string& writer)
{
if (action == CallbackReason::Connect)
{
Expand Down Expand Up @@ -299,8 +299,8 @@ void ::Reader::run(int argc, char* argv[])
auto reader = makeFilteredKeyReader(topic, Filter<string>("_regex", "elem3"), "", config);
promise<bool> p1, p2, p3;
reader.onConnectedWriters(
[&p1](vector<string> writers) { p1.set_value(writers.empty()); },
[&p2, &p3](CallbackReason action, string writer)
[&p1](const vector<string>& writers) { p1.set_value(writers.empty()); },
[&p2, &p3](CallbackReason action, const string& writer)
{
if (action == CallbackReason::Connect)
{
Expand All @@ -323,7 +323,7 @@ void ::Reader::run(int argc, char* argv[])
promise<bool> p1, p2;
reader.onConnectedWriters(
[&p1](vector<string> writers) { p1.set_value(!writers.empty() && writers[0] == "writer2"); },
[&p2](CallbackReason action, string writer)
[&p2](CallbackReason action, const string& writer)
{
if (action == CallbackReason::Connect)
{
Expand Down Expand Up @@ -353,8 +353,8 @@ void ::Reader::run(int argc, char* argv[])
auto reader = makeAnyKeyReader(topic, "", config);
promise<bool> p1, p2, p3;
reader.onConnectedWriters(
[&p1](vector<string> writers) { p1.set_value(writers.empty()); },
[&p2, &p3](CallbackReason action, string writer)
[&p1](const vector<string>& writers) { p1.set_value(writers.empty()); },
[&p2, &p3](CallbackReason action, const string& writer)
{
if (action == CallbackReason::Connect)
{
Expand Down
Loading

0 comments on commit 2f089da

Please sign in to comment.