Skip to content

Commit 8f2ed19

Browse files
authored
build: move to c++17 (#223)
Upgrade the codebase to C++17 by removing custom portability helpers (SilKit::Filesystem, Util::Optional) in favor of std::filesystem and std::optional, updates CMake configurations, and adds SPDX license headers. - Replace all uses of SilKit::Filesystem and Util::Optional with standard library equivalents. - Remove obsolete helper headers and tests for custom filesystem and optional. - Update CMakeLists to require C++17 and disable compiler extensions. Details: * use std::filsystem * use std::optional * use [[fallthrough]] attribute * use std::void_t * use: if constexpr and structured binding * use is_integral_v
1 parent 70a010b commit 8f2ed19

48 files changed

Lines changed: 219 additions & 1036 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

SilKit/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ cmake_minimum_required(VERSION 3.13)
2727

2828
project("SilKit-Library" LANGUAGES CXX C)
2929

30-
set(CMAKE_CXX_STANDARD 14)
30+
set(CMAKE_CXX_STANDARD 17)
31+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
32+
set(CMAKE_CXX_STANDARD_EXTENSIONS OFF)
3133

3234
include(SilKitVersion)
3335
configure_silkit_version(${PROJECT_NAME})

SilKit/IntegrationTests/SimTestHarness/SimTestHarness.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,16 +225,15 @@ bool SimTestHarness::Run(std::chrono::nanoseconds testRunTimeout, const std::vec
225225
bool runStatus = true;
226226
const auto startTime = Now();
227227
auto timeRemaining = testRunTimeout;
228-
//C++17: for (auto& [name, participant] : _simParticipants)
229-
for (auto& kv : _simParticipants)
228+
229+
for (auto& [name, participant]: _simParticipants)
230230
{
231-
if (std::find(keepAlive.begin(), keepAlive.end(), kv.first) != keepAlive.end())
231+
if (std::find(keepAlive.begin(), keepAlive.end(), name) != keepAlive.end())
232232
{
233233
// Ignore waiting for participants in keepAlive list
234234
continue;
235235
}
236236

237-
auto& participant = kv.second;
238237
if (noTimeout)
239238
{
240239
participant->Result().wait();

SilKit/source/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ list(APPEND SilKitImplObjectLibraries
188188
O_SilKit_Util
189189
O_SilKit_Util_FileHelpers
190190
O_SilKit_Util_StringHelpers
191-
O_SilKit_Util_Filesystem
192191
O_SilKit_Util_SetThreadName
193192
O_SilKit_Util_SignalHandler
194193
O_SilKit_Util_Uuid

SilKit/source/capi/CapiImpl.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2626
#include "silkit/participant/exception.hpp"
2727

2828
#include "CapiExceptions.hpp"
29-
#include "TypeUtils.hpp"
3029

3130
#define CAPI_CATCH_EXCEPTIONS \
3231
catch (const SilKit::CapiBadParameterError& e) \
@@ -183,7 +182,7 @@ struct HasStructHeader : std::false_type
183182

184183
template <typename T>
185184
struct HasStructHeader<
186-
T, SilKit::Util::VoidT<decltype(std::declval<std::decay_t<T>>().structHeader = SilKit_StructHeader{})>>
185+
T, std::void_t<decltype(std::declval<std::decay_t<T>>().structHeader = SilKit_StructHeader{})>>
187186
: std::true_type
188187
{
189188
};

SilKit/source/config/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ target_link_libraries(O_SilKit_Config
5757
PUBLIC I_SilKit_Config
5858

5959
PRIVATE SilKitInterface
60-
PRIVATE O_SilKit_Util_Filesystem
6160
PRIVATE I_SilKit_Util_FileHelpers
6261
PUBLIC rapidyaml
6362
PRIVATE fmt::fmt

SilKit/source/config/Configuration.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2323

2424
#include <algorithm>
2525
#include <iostream>
26+
#include <optional>
2627
#include <sstream>
2728
#include <stdexcept>
2829
#include <string>
@@ -34,7 +35,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
3435
#include "silkit/SilKitMacros.hpp"
3536
#include "silkit/services/logging/LoggingDatatypes.hpp"
3637

37-
#include "Optional.hpp"
3838
#include "StringHelpers.hpp"
3939

4040
namespace SilKit {
@@ -145,13 +145,13 @@ struct TraceSource
145145
struct MdfChannel
146146
{
147147
// A user supplied empty string in the configuration is valid
148-
SilKit::Util::Optional<std::string> channelName; //!< maps to MDF cn_tx_name
149-
SilKit::Util::Optional<std::string> channelSource; //!< maps to MDF si_tx_name of cn_si_source
150-
SilKit::Util::Optional<std::string> channelPath; //!< maps to MDF si_tx_path of cn_si_source
148+
std::optional<std::string> channelName; //!< maps to MDF cn_tx_name
149+
std::optional<std::string> channelSource; //!< maps to MDF si_tx_name of cn_si_source
150+
std::optional<std::string> channelPath; //!< maps to MDF si_tx_path of cn_si_source
151151

152-
SilKit::Util::Optional<std::string> groupName; //!< maps to MDF cg_tx_name
153-
SilKit::Util::Optional<std::string> groupSource; //!< maps to MDF si_tx_name of cg_si_acq_source
154-
SilKit::Util::Optional<std::string> groupPath; //!< maps to MDF si_tx_path of cn_si_acq_source
152+
std::optional<std::string> groupName; //!< maps to MDF cg_tx_name
153+
std::optional<std::string> groupSource; //!< maps to MDF si_tx_name of cg_si_acq_source
154+
std::optional<std::string> groupPath; //!< maps to MDF si_tx_path of cn_si_acq_source
155155
};
156156

157157
struct Replay

SilKit/source/config/ParticipantConfiguration.hpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
2424
#include <array>
2525
#include <chrono>
2626
#include <iostream>
27+
#include <optional>
2728
#include <ostream>
2829
#include <string>
2930
#include <vector>
@@ -36,7 +37,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
3637
#include "silkit/services/datatypes.hpp"
3738

3839
#include "Configuration.hpp"
39-
#include "Optional.hpp"
4040

4141
namespace SilKit {
4242
namespace Config {
@@ -55,7 +55,7 @@ struct InternalController
5555
}
5656

5757
std::string name;
58-
SilKit::Util::Optional<std::string> network;
58+
std::optional<std::string> network;
5959
};
6060

6161
// ================================================================================
@@ -71,7 +71,7 @@ struct CanController
7171
}
7272

7373
std::string name;
74-
SilKit::Util::Optional<std::string> network;
74+
std::optional<std::string> network;
7575

7676
std::vector<std::string> useTraceSinks;
7777
Replay replay;
@@ -90,7 +90,7 @@ struct LinController
9090
}
9191

9292
std::string name;
93-
SilKit::Util::Optional<std::string> network;
93+
std::optional<std::string> network;
9494

9595
std::vector<std::string> useTraceSinks;
9696
Replay replay;
@@ -109,7 +109,7 @@ struct EthernetController
109109
}
110110

111111
std::string name;
112-
SilKit::Util::Optional<std::string> network;
112+
std::optional<std::string> network;
113113

114114
std::vector<std::string> useTraceSinks;
115115
Replay replay;
@@ -128,10 +128,10 @@ struct FlexrayController
128128
}
129129

130130
std::string name;
131-
SilKit::Util::Optional<std::string> network;
131+
std::optional<std::string> network;
132132

133-
SilKit::Util::Optional<Services::Flexray::FlexrayClusterParameters> clusterParameters;
134-
SilKit::Util::Optional<Services::Flexray::FlexrayNodeParameters> nodeParameters;
133+
std::optional<Services::Flexray::FlexrayClusterParameters> clusterParameters;
134+
std::optional<Services::Flexray::FlexrayNodeParameters> nodeParameters;
135135
std::vector<Services::Flexray::FlexrayTxBufferConfig> txBufferConfigurations;
136136

137137
std::vector<std::string> useTraceSinks;
@@ -172,11 +172,11 @@ struct DataPublisher
172172
}
173173

174174
std::string name;
175-
SilKit::Util::Optional<std::string> topic;
176-
SilKit::Util::Optional<std::vector<Label>> labels;
175+
std::optional<std::string> topic;
176+
std::optional<std::vector<Label>> labels;
177177

178178
//! \brief History length of a DataPublisher.
179-
SilKit::Util::Optional<size_t> history{0};
179+
std::optional<size_t> history{0};
180180

181181
std::vector<std::string> useTraceSinks;
182182
Replay replay;
@@ -191,8 +191,8 @@ struct DataSubscriber
191191
}
192192

193193
std::string name;
194-
SilKit::Util::Optional<std::string> topic;
195-
SilKit::Util::Optional<std::vector<Label>> labels;
194+
std::optional<std::string> topic;
195+
std::optional<std::vector<Label>> labels;
196196

197197
std::vector<std::string> useTraceSinks;
198198
Replay replay;
@@ -211,8 +211,8 @@ struct RpcServer
211211
}
212212

213213
std::string name;
214-
SilKit::Util::Optional<std::string> functionName;
215-
SilKit::Util::Optional<std::vector<Label>> labels;
214+
std::optional<std::string> functionName;
215+
std::optional<std::vector<Label>> labels;
216216

217217
std::vector<std::string> useTraceSinks;
218218
Replay replay;
@@ -227,8 +227,8 @@ struct RpcClient
227227
}
228228

229229
std::string name;
230-
SilKit::Util::Optional<std::string> functionName;
231-
SilKit::Util::Optional<std::vector<Label>> labels;
230+
std::optional<std::string> functionName;
231+
std::optional<std::vector<Label>> labels;
232232

233233
std::vector<std::string> useTraceSinks;
234234
Replay replay;
@@ -241,8 +241,8 @@ struct RpcClient
241241
//! \brief Health checking service
242242
struct HealthCheck
243243
{
244-
SilKit::Util::Optional<std::chrono::milliseconds> softResponseTimeout;
245-
SilKit::Util::Optional<std::chrono::milliseconds> hardResponseTimeout;
244+
std::optional<std::chrono::milliseconds> softResponseTimeout;
245+
std::optional<std::chrono::milliseconds> hardResponseTimeout;
246246
};
247247

248248
// ================================================================================
@@ -446,9 +446,9 @@ struct RegistryConfiguration
446446
{
447447
std::string description{""};
448448
std::string schemaVersion{""};
449-
SilKit::Util::Optional<std::string> listenUri;
450-
SilKit::Util::Optional<bool> enableDomainSockets;
451-
SilKit::Util::Optional<std::string> dashboardUri;
449+
std::optional<std::string> listenUri;
450+
std::optional<bool> enableDomainSockets;
451+
std::optional<std::string> dashboardUri;
452452
SilKit::Config::Logging logging{};
453453
Experimental experimental{};
454454
};

SilKit/source/config/ParticipantConfigurationFromXImpl.cpp

Lines changed: 30 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,14 @@
1-
/* Copyright (c) 2022 Vector Informatik GmbH
2-
3-
Permission is hereby granted, free of charge, to any person obtaining
4-
a copy of this software and associated documentation files (the
5-
"Software"), to deal in the Software without restriction, including
6-
without limitation the rights to use, copy, modify, merge, publish,
7-
distribute, sublicense, and/or sell copies of the Software, and to
8-
permit persons to whom the Software is furnished to do so, subject to
9-
the following conditions:
10-
11-
The above copyright notice and this permission notice shall be
12-
included in all copies or substantial portions of the Software.
13-
14-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
1+
// SPDX-FileCopyrightText: 2022-2025 Vector Informatik GmbH
2+
//
3+
// SPDX-License-Identifier: MIT
214

225
#include "ParticipantConfiguration.hpp"
23-
#include "Filesystem.hpp"
246

7+
#include <filesystem>
258
#include <fstream>
269
#include <sstream>
2710
#include <iomanip>
11+
#include <optional>
2812
#include <set>
2913
#include <utility>
3014
#include <vector>
@@ -52,40 +36,40 @@ using ConfigInclude = std::pair<std::string, SilKit::Config::V1::ParticipantConf
5236
struct MiddlewareCache
5337
{
5438
std::vector<std::string> acceptorUris;
55-
SilKit::Util::Optional<std::string> registryUri;
56-
SilKit::Util::Optional<double> connectTimeoutSeconds;
57-
SilKit::Util::Optional<int> connectAttempts;
58-
SilKit::Util::Optional<int> tcpReceiveBufferSize;
59-
SilKit::Util::Optional<int> tcpSendBufferSize;
60-
SilKit::Util::Optional<bool> tcpNoDelay;
61-
SilKit::Util::Optional<bool> tcpQuickAck;
62-
SilKit::Util::Optional<bool> enableDomainSockets;
63-
SilKit::Util::Optional<bool> registryAsFallbackProxy;
64-
SilKit::Util::Optional<bool> experimentalRemoteParticipantConnection;
39+
std::optional<std::string> registryUri;
40+
std::optional<double> connectTimeoutSeconds;
41+
std::optional<int> connectAttempts;
42+
std::optional<int> tcpReceiveBufferSize;
43+
std::optional<int> tcpSendBufferSize;
44+
std::optional<bool> tcpNoDelay;
45+
std::optional<bool> tcpQuickAck;
46+
std::optional<bool> enableDomainSockets;
47+
std::optional<bool> registryAsFallbackProxy;
48+
std::optional<bool> experimentalRemoteParticipantConnection;
6549
};
6650

6751
struct GlobalLogCache
6852
{
69-
SilKit::Util::Optional<bool> logFromRemotes;
70-
SilKit::Util::Optional<Services::Logging::Level> flushLevel;
53+
std::optional<bool> logFromRemotes;
54+
std::optional<Services::Logging::Level> flushLevel;
7155
std::set<Sink> fileSinks;
72-
SilKit::Util::Optional<Sink> stdOutSink;
73-
SilKit::Util::Optional<Sink> remoteSink;
56+
std::optional<Sink> stdOutSink;
57+
std::optional<Sink> remoteSink;
7458
std::set<std::string> fileNames;
7559
};
7660

7761
struct TimeSynchronizationCache
7862
{
79-
SilKit::Util::Optional<double> animationFactor;
80-
SilKit::Util::Optional<Aggregation> enableMessageAggregation;
63+
std::optional<double> animationFactor;
64+
std::optional<Aggregation> enableMessageAggregation;
8165
};
8266

8367
struct MetricsCache
8468
{
85-
SilKit::Util::Optional<bool> collectFromRemote;
69+
std::optional<bool> collectFromRemote;
8670
std::set<MetricsSink> jsonFileSinks;
8771
std::set<std::string> fileNames;
88-
SilKit::Util::Optional<MetricsSink> remoteSink;
72+
std::optional<MetricsSink> remoteSink;
8973
};
9074

9175
struct ExperimentalCache
@@ -137,9 +121,9 @@ void Validate(const std::string& text)
137121
// ================================================================================
138122
std::string GetConfigParentPath(const std::string& configFile)
139123
{
140-
namespace fs = SilKit::Filesystem;
141-
auto filePath = fs::concatenate_paths(fs::current_path().string(), configFile);
142-
return fs::parent_path(filePath).string();
124+
namespace fs = std::filesystem;
125+
const auto filePath = fs::current_path() / configFile;
126+
return filePath.parent_path().string();
143127
}
144128

145129
void AppendToSearchPaths(const ParticipantConfiguration& config, ConfigIncludeData& configData)
@@ -158,7 +142,7 @@ void AppendToSearchPaths(const ParticipantConfiguration& config, ConfigIncludeDa
158142
// Make sure they have a seperator
159143
if (lastChar != '/' && lastChar != '\\')
160144
{
161-
suffix = SilKit::Filesystem::path::preferred_separator;
145+
suffix = std::filesystem::path::preferred_separator;
162146
}
163147

164148
configData.searchPaths.insert(searchPath + suffix);
@@ -200,7 +184,7 @@ std::string OpenFileWithSearchHints(const std::string& configFile, const std::se
200184
// Helper functions to merge config fields/vectors/sets
201185
// ================================================================================
202186
template <typename FieldT>
203-
void MergeCacheField(const SilKit::Util::Optional<FieldT>& includeObject, FieldT& rootObject)
187+
void MergeCacheField(const std::optional<FieldT>& includeObject, FieldT& rootObject)
204188
{
205189
if (includeObject.has_value())
206190
{
@@ -254,11 +238,11 @@ void MergeCacheSet(const std::set<T>& cache, std::vector<T>& root)
254238

255239
template <typename T>
256240
void CacheNonDefault(const T& defaultValue, const T& value, const std::string& configName,
257-
SilKit::Util::Optional<T>& cacheValue)
241+
std::optional<T>& cacheValue)
258242
{
259243
if (defaultValue != value)
260244
{
261-
SilKit::Util::Optional<T> optValue{value};
245+
std::optional<T> optValue{value};
262246

263247
if (cacheValue.has_value() && (cacheValue != optValue))
264248
{

0 commit comments

Comments
 (0)