Files
qt6-migration-pipeline/external/rti_connext_dds-7.7.0/include/rti/apputils/util/Utils.hpp
T
torsten 77c67c12ca Execute the same instructions but now for tools in folders you are getti
Entire-Metadata: .entire/metadata/fb87247f-2a75-407e-b336-cbc8c20ba5a6
Entire-Session: fb87247f-2a75-407e-b336-cbc8c20ba5a6
Entire-Strategy: manual-commit
2026-09-24 16:24:51 +00:00

123 lines
2.9 KiB
C++

/*
* (c) Copyright, Real-Time Innovations, 2016-.
* All rights reserved.
* No duplications, whole or partial, manual or electronic, may be made
* without express written permission. Any such copies, or
* revisions thereof, must display this notice unaltered.
* This code contains trade secrets of Real-Time Innovations, Inc.
*/
#ifndef APPUTILS_HPP_
#define APPUTILS_HPP_
// IMPORTANT: macros.hpp must be the first RTI header included in every header
// file so that symbols are exported correctly on Windows
#include <dds/core/macros.hpp>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <limits>
#include <string>
#include <sstream>
#include "osapi/osapi_utility.h"
#include <dds/core/types.hpp>
#include <rti/core/Exception.hpp>
#include "dds/core/Time.hpp"
#define STATIC_CONST_STRING_DEFINITION(classname, name, value) \
const std::string& classname::name() \
{ \
static std::string name##var(value); \
return name##var; \
}
#define RECORDER_FILE_PATH_MAX_LENGTH (4096)
namespace rti { namespace apputils { namespace util {
constexpr int64_t g_int64_max = 0x7FFFFFFFFFFFFFFFULL;
constexpr uint64_t g_uint64_max = 0xFFFFFFFFFFFFFFFFULL;
inline
std::string normalize_path(const std::string& file_name)
{
char normalized[RECORDER_FILE_PATH_MAX_LENGTH] = {'\0'};
if (!RTIOsapiUtility_normalizePath(
normalized,
RECORDER_FILE_PATH_MAX_LENGTH,
file_name.c_str())) {
std::stringstream error_msg;
error_msg << "!normalize path " << file_name.c_str() << "\n";
throw dds::core::IllegalOperationError(error_msg.str());
}
return normalized;
}
inline
int64_t convert_uint64_into_int64(uint64_t value)
{
int64_t signed_int64 = 0;
if (value > g_int64_max) {
signed_int64 = g_int64_max;
} else {
signed_int64 = (int64_t) value;
}
return signed_int64;
}
inline
uint64_t to_nanosecs(dds::core::Time time)
{
uint64_t nanosec;
try {
nanosec = time.to_nanosecs();
} catch (std::overflow_error&) {
nanosec = g_uint64_max;
}
return nanosec;
}
/**
* @brief Check if the sum of two values would produce an overflow.
*
* @tparam T type of the elements to be summed.
*
* @param lhs Left-hand side of the sum
* @param rhs Right-hand side of the sum
*
* @return true if the sum overflows, false otherwise.
*/
template <typename T>
bool sum_overflows(T lhs, T rhs)
{
return lhs > 0 && rhs > 0 && (std::numeric_limits<T>::max)() - lhs < rhs;
}
/**
* @brief Check if the sum of two values would produce an underflow.
*
* @tparam T type of the elements to be summed.
*
* @param lhs Left-hand side of the sum
* @param rhs Right-hand side of the sum
*
* @return true if the sum underflows, false otherwise.
*/
template <typename T>
bool sum_underflows(T lhs, T rhs)
{
return lhs < 0 && rhs < 0 && std::numeric_limits<T>::lowest() - lhs > rhs;
}
} } } // namespace rti:apputils::util
#endif /* APPUTILS_HPP_ */