Skip to content

Commit bda9c73

Browse files
egecetinseladb
andauthored
Clang tidy fixes for Common++ (#1884)
* clang-tidy fixes * revert '\n' --------- Co-authored-by: seladb <[email protected]>
1 parent 5fa5981 commit bda9c73

File tree

9 files changed

+28
-25
lines changed

9 files changed

+28
-25
lines changed

Common++/header/GeneralUtils.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,11 @@ namespace pcpp
5757

5858
/// A template class to calculate enum class hash
5959
/// @tparam EnumClass
60-
template <typename EnumClass, typename std::enable_if<std::is_enum<EnumClass>::value, bool>::type = false>
61-
struct EnumClassHash
60+
template <typename EnumClass, std::enable_if_t<std::is_enum<EnumClass>::value, bool> = false> struct EnumClassHash
6261
{
6362
size_t operator()(EnumClass value) const
6463
{
65-
return static_cast<typename std::underlying_type<EnumClass>::type>(value);
64+
return static_cast<std::underlying_type_t<EnumClass>>(value);
6665
}
6766
};
6867
} // namespace pcpp

Common++/header/Logger.h

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ namespace pcpp
143143

144144
/// An enum representing the log level. Currently 4 log levels are supported: Off, Error, Info and Debug. Info is
145145
/// the default log level
146-
enum class LogLevel
146+
enum class LogLevel : uint8_t
147147
{
148148
Off = PCPP_LOG_LEVEL_OFF, ///< No log messages are emitted.
149149
Error = PCPP_LOG_LEVEL_ERROR, ///< Error level logs are emitted.
@@ -152,9 +152,9 @@ namespace pcpp
152152
Debug = PCPP_LOG_LEVEL_DEBUG ///< Debug level logs and above are emitted.
153153
};
154154

155-
inline std::ostream& operator<<(std::ostream& s, LogLevel v)
155+
inline std::ostream& operator<<(std::ostream& ostr, LogLevel lvl)
156156
{
157-
return s << static_cast<std::underlying_type<LogLevel>::type>(v);
157+
return ostr << static_cast<std::underlying_type_t<LogLevel>>(lvl);
158158
}
159159

160160
// Forward declaration
@@ -192,7 +192,7 @@ namespace pcpp
192192
/// @brief Appends to the message.
193193
/// @param value The value to append.
194194
/// @return A reference to this context.
195-
template <class T> inline LogContext& operator<<(T const& value)
195+
template <class T> LogContext& operator<<(T const& value)
196196
{
197197
m_Stream << value;
198198
return *this;
@@ -245,9 +245,8 @@ namespace pcpp
245245
/// @param[in] method The method in PcapPlusPlus code the log message is coming from
246246
/// @param[in] line The line in PcapPlusPlus code the log message is coming from
247247
/// @remarks The printer callback should support being called from multiple threads simultaneously.
248-
using LogPrinter =
249-
std::add_pointer<void(LogLevel logLevel, const std::string& logMessage, const std::string& file,
250-
const std::string& method, const int line)>::type;
248+
using LogPrinter = std::add_pointer_t<void(LogLevel logLevel, const std::string& logMessage,
249+
const std::string& file, const std::string& method, const int line)>;
251250

252251
/// A static method for converting the log level enum to a string.
253252
/// @param[in] logLevel A log level enum
@@ -313,7 +312,7 @@ namespace pcpp
313312
/// @return Get the last error message
314313
std::string getLastError() const
315314
{
316-
std::lock_guard<std::mutex> lock(m_LastErrorMtx);
315+
std::lock_guard<std::mutex> const lock(m_LastErrorMtx);
317316
return m_LastError;
318317
}
319318

@@ -394,7 +393,7 @@ namespace pcpp
394393

395394
private:
396395
bool m_LogsEnabled;
397-
std::array<LogLevel, NumOfLogModules> m_LogModulesArray;
396+
std::array<LogLevel, NumOfLogModules> m_LogModulesArray{};
398397
LogPrinter m_LogPrinter;
399398

400399
mutable std::mutex m_LastErrorMtx;

Common++/header/MacAddress.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace pcpp
5757
/// A template constructor that creates an instance of the class out of a string convertible to std::string.
5858
/// If the string doesn't represent a valid MAC address, the constructor throws an exception.
5959
/// @param[in] addr the string representing the MAC address in format "00:00:00:00:00:00"
60-
template <typename T, typename = typename std::enable_if<std::is_convertible<T, std::string>::value>::type>
60+
template <typename T, typename = std::enable_if_t<std::is_convertible<T, std::string>::value>>
6161
MacAddress(const T& addr) : MacAddress(static_cast<std::string>(addr))
6262
{}
6363

Common++/header/ObjectPool.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <stack>
44
#include <mutex>
55
#include <memory>
6+
#include <stdexcept>
67
#include <limits>
78
#include <type_traits>
89

@@ -18,7 +19,7 @@ namespace pcpp
1819
/// created. If the pool is full when releasing an object, the object will be deleted.
1920
///
2021
/// @tparam T The type of objects managed by the pool. Must be default constructable.
21-
template <class T, typename std::enable_if<std::is_default_constructible<T>::value, bool>::type = true>
22+
template <class T, std::enable_if_t<std::is_default_constructible<T>::value, bool> = true>
2223
class DynamicObjectPool
2324
{
2425
public:
@@ -35,10 +36,14 @@ namespace pcpp
3536
: m_MaxPoolSize(maxPoolSize)
3637
{
3738
if (initialSize > maxPoolSize)
39+
{
3840
throw std::invalid_argument("Preallocated objects cannot exceed the maximum pool size");
41+
}
3942

4043
if (initialSize > 0)
44+
{
4145
this->preallocate(initialSize);
46+
}
4247
}
4348

4449
// These don't strictly need to be deleted, but don't need to be implemented for now either.

Common++/header/PointerVector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace pcpp
3131

3232
/// @brief A specialization of Copier to facilitate the safe copying of polymorphic objects via clone() method.
3333
/// @tparam T The type of object to copy.
34-
template <class T> struct Copier<T, typename std::enable_if<std::is_polymorphic<T>::value>::type>
34+
template <class T> struct Copier<T, std::enable_if_t<std::is_polymorphic<T>::value>>
3535
{
3636
std::unique_ptr<T> operator()(const T& obj) const
3737
{

Common++/header/SystemUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ namespace pcpp
163163
int clockGetTime(long& sec, long& nsec);
164164

165165
/// Convert std::tm to time_t in UTC time, ignoring local timezone
166-
/// @param[in] tm The time to convert
166+
/// @param[in] time The time to convert
167167
/// @return A time_t object representing the input time
168168
/// @throws std::runtime_error if a conversion error occurs
169-
time_t mkUtcTime(std::tm& tm);
169+
time_t mkUtcTime(std::tm& time);
170170

171171
/// A multi-platform version of the popular sleep method. This method simply runs the right sleep method, according
172172
/// to the platform it is running on.

Common++/header/TimespecTimeval.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ namespace pcpp
4040
/// Converts a timespec structure to a timeval structure
4141
inline timeval toTimeval(timespec value)
4242
{
43-
timeval tv = {};
44-
TIMESPEC_TO_TIMEVAL(&tv, &value);
45-
return tv;
43+
timeval tmVal = {};
44+
TIMESPEC_TO_TIMEVAL(&tmVal, &value);
45+
return tmVal;
4646
}
4747
} // namespace internal
4848
} // namespace pcpp

Common++/src/Logger.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ namespace pcpp
8585
// If the log level is an error, save the error to the last error message variable.
8686
if (logLevel == LogLevel::Error)
8787
{
88-
std::lock_guard<std::mutex> lock(m_LastErrorMtx);
88+
std::lock_guard<std::mutex> const lock(m_LastErrorMtx);
8989
m_LastError = message;
9090
}
9191
if (m_LogsEnabled)
@@ -103,7 +103,7 @@ namespace pcpp
103103
std::ostringstream sstream;
104104
sstream << file << ": " << method << ":" << line;
105105

106-
std::unique_lock<std::mutex> lock(logMutex);
106+
std::unique_lock<std::mutex> const lock(logMutex);
107107
std::cerr << std::left << "[" << std::setw(5) << Logger::logLevelAsString(logLevel) << ": " << std::setw(45)
108108
<< sstream.str() << "] " << logMessage << std::endl;
109109
}

Common++/src/SystemUtils.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,12 @@ namespace pcpp
221221
return 0;
222222
}
223223

224-
time_t mkUtcTime(std::tm& tm)
224+
time_t mkUtcTime(std::tm& time)
225225
{
226226
#if defined(_WIN32)
227-
return _mkgmtime(&tm);
227+
return _mkgmtime(&time);
228228
#else
229-
return timegm(&tm);
229+
return timegm(&time);
230230
#endif
231231
}
232232

0 commit comments

Comments
 (0)