- HandlerMinelayerData: BUILD_RTI Guards für RTI-Abhängigkeiten - svcTabCommon: Export-Header-Fix via Fallback-Target - TrainingAreaBase: Stub-Header für BUILD_RTI=OFF - ddsfts: Include-Pfad und Dependency-Fixes - BUILD_RTI=OFF Compilation vollständig unterstützt Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Entire-Checkpoint: 01M0JNZA586SACX1PRZ2DJAE5S
156 lines
4.8 KiB
C++
156 lines
4.8 KiB
C++
/*
|
|
(c) Copyright, Real-Time Innovations, 2018.
|
|
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 HPP_RTI_APPUTILS_VERSIONABLECOMPONENT_HPP_
|
|
#define HPP_RTI_APPUTILS_VERSIONABLECOMPONENT_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 <sstream>
|
|
#include <string>
|
|
#include <stdint.h>
|
|
|
|
#include <assert.h>
|
|
#include "dds/core/Exception.hpp"
|
|
|
|
namespace rti { namespace apputils { namespace util {
|
|
|
|
class ComponentVersion {
|
|
public:
|
|
constexpr ComponentVersion() noexcept :
|
|
major_(0),
|
|
minor_(0)
|
|
{ }
|
|
|
|
constexpr ComponentVersion(const uint8_t major, const uint8_t minor) noexcept :
|
|
major_(major),
|
|
minor_(minor)
|
|
{ }
|
|
|
|
ComponentVersion(const std::string& version_str)
|
|
{
|
|
std::istringstream stream(version_str);
|
|
int16_t value;
|
|
|
|
stream >> value;
|
|
if (stream.fail()) {
|
|
throw dds::core::InvalidArgumentError(version_string_error(version_str));
|
|
}
|
|
major_ = static_cast<uint8_t>(value);
|
|
|
|
char separator;
|
|
stream >> separator;
|
|
if (stream.fail() || separator != '.') {
|
|
throw dds::core::InvalidArgumentError(version_string_error(version_str));
|
|
}
|
|
|
|
stream >> value;
|
|
if (stream.fail()) {
|
|
throw dds::core::InvalidArgumentError(version_string_error(version_str));
|
|
}
|
|
minor_ = static_cast<uint8_t>(value);
|
|
}
|
|
|
|
uint8_t get_major() const noexcept { return major_; }
|
|
uint8_t get_minor() const noexcept { return minor_; }
|
|
|
|
bool operator ==(const ComponentVersion& other) const noexcept
|
|
{
|
|
return (major_ == other.major_ && minor_ == other.minor_);
|
|
}
|
|
|
|
bool operator !=(const ComponentVersion& other) const noexcept
|
|
{
|
|
return !(*this == other);
|
|
}
|
|
|
|
bool operator < (const ComponentVersion& other) const noexcept
|
|
{
|
|
if ((int16_t) major_ - (int16_t) other.major_ == 0) {
|
|
return ((int16_t) minor_ - (int16_t) other.minor_ < 0);
|
|
} else {
|
|
return ((int16_t) major_ - (int16_t) other.major_ < 0);
|
|
}
|
|
}
|
|
|
|
bool operator > (const ComponentVersion& other) const noexcept
|
|
{
|
|
if ((int16_t) major_ - (int16_t) other.major_ == 0) {
|
|
return ((int16_t) minor_ - (int16_t) other.minor_ > 0);
|
|
} else {
|
|
return ((int16_t) major_ - (int16_t) other.major_ > 0);
|
|
}
|
|
}
|
|
|
|
operator std::string () const noexcept
|
|
{
|
|
return std::to_string(major_) + "." + std::to_string(minor_);
|
|
}
|
|
|
|
private:
|
|
uint8_t major_;
|
|
uint8_t minor_;
|
|
|
|
std::string version_string_error (const std::string & str) const noexcept
|
|
{
|
|
return "VersionableComponent: invalid version string: " + str;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* @brief A versionable component has a name and a version and it's used to
|
|
* keep track of the versions of the components used to record data.
|
|
* This information is kept in the 'metadata' database file. It can later
|
|
* be recovered by Replay/Converter to use exactly the same components'
|
|
* versions that were when recording.
|
|
* @param VersionType The version object to be used. By default, the Version
|
|
* type implemented above is used (a simple, two-digit, stringifyable
|
|
* version type).
|
|
*/
|
|
template<typename VersionType>
|
|
class VersionableComponent {
|
|
public:
|
|
|
|
VersionableComponent(
|
|
std::string component_name,
|
|
const VersionType& version) :
|
|
component_name_(component_name),
|
|
version_(version) { }
|
|
|
|
const VersionType& version() const { return version_; }
|
|
|
|
const std::string& component_name() const { return component_name_; }
|
|
|
|
void verify_version(const VersionType& version) const
|
|
{
|
|
if (version > version_) {
|
|
std::stringstream error_stream;
|
|
error_stream << "VersionableComponent: " << component_name_.c_str()
|
|
<< ": detected newer version. The current version of the "
|
|
<< "component in this tool ("
|
|
<< ((const std::string&) version_).c_str()
|
|
<< ") is unable to read the newer "
|
|
<< component_name_.c_str() <<" version ("
|
|
<< ((const std::string&) version).c_str() <<") found ";
|
|
throw dds::core::IllegalOperationError(error_stream.str());
|
|
}
|
|
}
|
|
|
|
private:
|
|
std::string component_name_;
|
|
VersionType version_;
|
|
};
|
|
|
|
typedef VersionableComponent<ComponentVersion> DefaultVersionableComponent;
|
|
|
|
} } } /* namespace rti::apputils::util */
|
|
|
|
#endif /* HPP_RTI_APPUTILS_VERSIONABLECOMPONENT_HPP_ */
|