Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lints in DataStorm demos #228

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ WarningsAsErrors: '*'
HeaderFilterRegex: ''
UseColor: true
FormatStyle: 'file'
ExtraArgs: ['-std=c++17']
CheckOptions:
modernize-use-nullptr.NullMacros: 'NULL'
# std::exception_ptr is a cheap to copy, pointer-like type; we pass it by value all the time.
Expand Down
2 changes: 1 addition & 1 deletion cpp/DataStorm/clock/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace DataStorm
static chrono::system_clock::time_point decode(const Ice::ByteSeq&)
{
assert(false); // Not used by the reader but it still needs to be declared.
return chrono::system_clock::time_point();
return {};
}
};
};
Expand Down
10 changes: 5 additions & 5 deletions cpp/DataStorm/stock/Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,16 @@ main(int argc, char* argv[])
// Get the set of stocks connected with the any reader and display their ticker.
std::promise<void> p;
stocks.onConnectedKeys(
[&p](vector<string> tickers)
[&p](const vector<string>& tickers)
{
cout << "Available stock(s): " << endl;
for (auto ticker : tickers)
for (const auto& ticker : tickers)
{
cout << ticker << endl;
}
p.set_value();
},
[](DataStorm::CallbackReason action, string ticker)
[](DataStorm::CallbackReason action, const string& ticker)
{
if (action == DataStorm::CallbackReason::Connect)
{
Expand Down Expand Up @@ -90,11 +90,11 @@ main(int argc, char* argv[])
// Wait for the writer to be connected.
reader->waitForWriters();

auto displaySample = [](DataStorm::Sample<string, Stock> s)
auto displaySample = [](const DataStorm::Sample<string, Stock>& s)
{
if (s.getEvent() == DataStorm::SampleEvent::Add || s.getEvent() == DataStorm::SampleEvent::Update)
{
auto value = s.getValue();
const auto& value = s.getValue();
cout << "Stock: " << value.name << " (" << s.getKey() << ")" << endl;
cout << "Price: " << value.price << endl;
cout << "Best bid/ask: " << value.bestBid << '/' << value.bestAsk << endl;
Expand Down
14 changes: 6 additions & 8 deletions cpp/DataStorm/stock/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,19 @@ using namespace Demo;

namespace
{

std::random_device random;

DataStorm::SingleKeyWriter<string, Stock>
makeStock(DataStorm::Topic<string, Stock>& topic, string ticker, Stock stock)
makeStock(DataStorm::Topic<string, Stock>& topic, const string& ticker, const Stock& stock)
{
// Create a stock writer for the given ticker and add the initial stock value.
auto writer = DataStorm::makeSingleKeyWriter(topic, std::move(ticker));
writer.add(std::move(stock));
auto writer = DataStorm::makeSingleKeyWriter(topic, ticker);
writer.add(stock);
return writer;
}

void updateStock(DataStorm::SingleKeyWriter<string, Stock>& stock)
{
static std::random_device random;

// Send a partial update to either update the price or the volume with the given writer.
if (uniform_int_distribution<int>(1, 10)(random) < 8)
{
Expand All @@ -41,7 +40,6 @@ namespace
uniform_int_distribution<int>(volume * 95 / 100, volume * 105 / 100)(random));
}
}

}

int
Expand Down Expand Up @@ -140,7 +138,7 @@ main(int argc, char* argv[])
cout << "unknown stock `" << stockName << "'" << endl;
return 1;
}
writers.push_back(makeStock(topic, std::move(stockName), stocks[stockName]));
writers.push_back(makeStock(topic, stockName, stocks[stockName]));
}

// Update the stock value or volume attributes.
Expand Down
Loading