diff --git a/.clang-format b/.clang-format
index 1d8cdf8..da3f715 100644
--- a/.clang-format
+++ b/.clang-format
@@ -6,18 +6,19 @@ BasedOnStyle: Google
# "int& foo" for this project:
DerivePointerAlignment: false
PointerAlignment: Left
+ColumnLimit: 120
# Rules for includes
# IncludeBlocks: IBS_Regroup # Requires clang-format 6.0+
# Ordering of includes, higher priority lower in list
IncludeCategories:
-- Regex: '^\"unit/'
- Priority: 5999
-- Regex: '^\"'
- Priority: 4000
-- Regex: '^<.*/.*'
- Priority: 2000
-- Regex: '^<[^\/.]*>'
- Priority: 1000
-- Regex: '^<.*.h>'
- Priority: 500
+ - Regex: '^\"unit/'
+ Priority: 5999
+ - Regex: '^\"'
+ Priority: 4000
+ - Regex: "^<.*/.*"
+ Priority: 2000
+ - Regex: '^<[^\/.]*>'
+ Priority: 1000
+ - Regex: "^<.*.h>"
+ Priority: 500
diff --git a/.clang-tidy b/.clang-tidy
index bf4629c..3240638 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -9,7 +9,7 @@
# -readability-function-cognitive-complexity disallows large functions
# -readability-identifier-length allows short variable names
# To be corrected:
-Checks: '-*, bugprone-*, clang-*, google-readability-*, misc-*, modernize-*, readability-*, performance-*, -clang-analyzer-cplusplus*, -google-readability-namespace-comments, -bugprone-easily-swappable-parameters, -bugprone-suspicious-include, -readability-function-cognitive-complexity, -readability-identifier-length, -modernize-use-trailing-return-type'
+Checks: '-*, bugprone-*, clang-*, google-readability-*, misc-*, modernize-*, readability-*, performance-*, -clang-analyzer-cplusplus*, -readability-identifier-naming, -google-readability-namespace-comments, -bugprone-easily-swappable-parameters, -bugprone-suspicious-include, -readability-function-cognitive-complexity, -readability-identifier-length, -modernize-use-trailing-return-type'
# Most warnings should be errors
WarningsAsErrors: 'bugprone-*, clang-*, google-*, misc-*, modernize-*, readability-*, performance-*'
# Overall format style, Google Style Guide w/ extra restrictions
@@ -18,7 +18,6 @@ CheckOptions:
- { key: readability-identifier-naming.ClassCase, value: CamelCase }
- { key: readability-identifier-naming.StructCase, value: CamelCase }
- { key: readability-identifier-naming.TemplateParameterCase, value: CamelCase }
- - { key: readability-identifier-naming.FunctionCase, value: CamelCase }
- { key: readability-identifier-naming.NamespaceCase, value: lower_case }
- { key: readability-identifier-naming.VariableCase, value: lower_case }
- { key: readability-identifier-naming.LocalConstantCase, value: lower_case }
@@ -33,8 +32,6 @@ CheckOptions:
- { key: readability-identifier-naming.ProtectedMemberCase, value: lower_case }
- { key: readability-identifier-naming.ConstexprVariableCase, value: CamelCase }
- { key: readability-identifier-naming.ConstexprVariablePrefix, value: k }
- - { key: readability-identifier-naming.EnumConstantCase, value: CamelCase }
- - { key: readability-identifier-naming.EnumConstantPrefix, value: k }
- { key: readability-identifier-naming.MemberConstantCase, value: CamelCase }
- { key: readability-identifier-naming.MemberConstantPrefix, value: k }
- { key: readability-identifier-naming.StaticConstantCase, value: CamelCase }
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 17f3a8a..1d06959 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,52 +1,38 @@
cmake_minimum_required(VERSION 3.22)
-project(libsersi
- VERSION 0.1.0
+if(NOT PROJECT_NAME)
+ set(PROJECT_NAME sersi)
+endif()
+
+if(NOT PROJECT_VERSION)
+ set(PROJECT_VERSION 0.2.0)
+endif()
+
+project(${PROJECT_NAME}
+ VERSION ${PROJECT_VERSION}
+ DESCRIPTION "IEEE 1278.1-2012 Distributed Interactive Simulation library"
LANGUAGES CXX
)
-include(${CMAKE_SOURCE_DIR}/cmake/libsersi-api.cmake)
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_EXTENSIONS OFF)
-libsersi_project_defaults()
+# Export compile commands
+set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
-# Define library
-add_library(sersi "")
+# Add CXX build flags for robust warning and error checking during compilation
+if (NOT MSVC)
+ add_compile_options(-Wall -Wextra -pedantic -Werror)
+endif()
-# Add src/ to the include directories to libsersi
-target_include_directories(sersi
- PUBLIC $
- $
-)
-target_include_directories(sersi SYSTEM
- PUBLIC $
- $
- PRIVATE $
-)
+include(GNUInstallDirs)
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
# Add source directories
+add_subdirectory(include)
add_subdirectory(src)
-# Configure install target (i.e. what files to install)
-install(TARGETS sersi
- EXPORT libsersi-targets
- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
-install(EXPORT libsersi-targets
- NAMESPACE libsersi::
- DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/libsersi")
-
-# Add cmake configuration
-add_subdirectory(cmake)
-
-# configure package target (i.e. Package Types, and meta data)
-set(CPACK_GENERATOR "DEB" "RPM" "TXZ" "TGZ")
-set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})
-set(CPACK_PACKAGE_NAME "libsersi")
-set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The libsersi library")
-set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CMAKE_SYSTEM_PROCESSOR}")
-set(CPACK_PACKAGE_RPM_DIR "${CMAKE_CURRENT_BINARY_DIR}/_CPack_Packages/Linux/RPM")
-set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Cameron Howell ")
-set(CPACK_PACKAGE_PACKAGER $ENV{USER})
-set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "The libsersi library")
include(CPack)
diff --git a/CMakeUserPresets.json b/CMakeUserPresets.json
new file mode 100644
index 0000000..945b382
--- /dev/null
+++ b/CMakeUserPresets.json
@@ -0,0 +1,9 @@
+{
+ "version": 4,
+ "vendor": {
+ "conan": {}
+ },
+ "include": [
+ "build/CMakePresets.json"
+ ]
+}
\ No newline at end of file
diff --git a/LICENSE b/LICENSE
index 6d9b293..5ba8eeb 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
BSD 2-Clause License
-Copyright (c) 2024, Cameron
+Copyright (c) 2026, Cameron
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
diff --git a/README.md b/README.md
index fb1603c..0356fb2 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@
width="0px"
/>
libsersi
- (IEEE 1278.1a-1998)
+ (IEEE 1278.1-2012)
@@ -50,36 +50,59 @@
## 💠About
-C++ implementation of the IEEE 1278.1a-1998 Distributed Interactive Simulation (DIS) application protocol. This library was implemented according to the IEEE Std 1278.1a-1998 publication. The name `libsersi` is derived from the words "*ser*ialize" and "*si*mulation".
+
+C++ implementation of the IEEE 1278.1-2012 Distributed Interactive Simulation (DIS) application protocol. This library was implemented according to the IEEE Std 1278.1-2012 publication. The name `libsersi` is derived from the words "*ser*ialize" and "*si*mulation".
## 📕 Documentation
+
Will add Doxygen documentation in a future patch.
## 🔰 Getting Started
+
This library can be manually built and installed with CMake and make tools, or it can be imported
from the Conan Center.
+
### Building from Source
+
+#### With CMake
+
To build from source, CMake 3.22+ is required. On Linux, run the following commands to build and install:
+
```bash
mkdir build
cd build
cmake ..
make
```
+
To build Linux package files, run
+
```bash
make package
```
+
To install the library into your `CMAKE_INSTALL_PREFIX`, run
+
```
make install
```
-### Importing with Conan
-Conan 2.x is required to import this library.
+#### With Conan
+
+To build the library with Conan:
+
+```bash
+conan build . -of build --build=missing
+```
+
+To create the Conan package from source:
+
+```bash
+conan create .
+```
- Copyright © 2024-present
+ Copyright © 2026
Cameron Howell
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
deleted file mode 100644
index 322cd94..0000000
--- a/cmake/CMakeLists.txt
+++ /dev/null
@@ -1,45 +0,0 @@
-set(LIBSERSI_PACKAGE_DIR
- "${CMAKE_INSTALL_LIBDIR}/cmake/libsersi"
-)
-
-include(CMakePackageConfigHelpers)
-configure_package_config_file(
- ${CMAKE_CURRENT_SOURCE_DIR}/libsersi-config.cmake.in
- ${CMAKE_CURRENT_BINARY_DIR}/libsersi-config.cmake
- INSTALL_DESTINATION ${LIBSERSI_PACKAGE_DIR}
- PATH_VARS CMAKE_INSTALL_INCLUDEDIR
- CMAKE_INSTALL_LIBDIR
- CMAKE_INSTALL_BINDIR
- CMAKE_INSTALL_DOCDIR
-)
-
-write_basic_package_version_file(
- "${CMAKE_CURRENT_BINARY_DIR}/libsersi-config-version.cmake"
- VERSION "${PROJECT_VERSION}"
- COMPATIBILITY SameMajorVersion
-)
-
-export(EXPORT libsersi-targets
- FILE "${CMAKE_CURRENT_BINARY_DIR}/libsersi-targets.cmake"
- NAMESPACE libsersi::
-)
-
-install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libsersi-config.cmake
- ${CMAKE_CURRENT_BINARY_DIR}/libsersi-config-version.cmake
- ${CMAKE_CURRENT_SOURCE_DIR}/libsersi-api.cmake
- DESTINATION ${LIBSERSI_PACKAGE_DIR}
- COMPONENT devel
-)
-
-install(EXPORT libsersi-targets
- FILE libsersi-targets.cmake
- NAMESPACE libsersi::
- DESTINATION ${LIBSERSI_PACKAGE_DIR}
- COMPONENT devel
-)
-
-install(FILES
- ${CMAKE_CURRENT_SOURCE_DIR}/Modules/CodeCoverage.cmake
- DESTINATION ${LIBSERSI_PACKAGE_DIR}/Modules
- COMPONENT devel
-)
diff --git a/cmake/Modules/CodeCoverage.cmake b/cmake/Modules/CodeCoverage.cmake
deleted file mode 100644
index c500cfa..0000000
--- a/cmake/Modules/CodeCoverage.cmake
+++ /dev/null
@@ -1,750 +0,0 @@
-# Copyright (c) 2012 - 2017, Lars Bilke
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without modification,
-# are permitted provided that the following conditions are met:
-#
-# 1. Redistributions of source code must retain the above copyright notice, this
-# list of conditions and the following disclaimer.
-#
-# 2. Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-#
-# 3. Neither the name of the copyright holder nor the names of its contributors
-# may be used to endorse or promote products derived from this software without
-# specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
-# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-# CHANGES:
-#
-# 2012-01-31, Lars Bilke
-# - Enable Code Coverage
-#
-# 2013-09-17, Joakim Söderberg
-# - Added support for Clang.
-# - Some additional usage instructions.
-#
-# 2016-02-03, Lars Bilke
-# - Refactored functions to use named parameters
-#
-# 2017-06-02, Lars Bilke
-# - Merged with modified version from github.com/ufz/ogs
-#
-# 2019-05-06, Anatolii Kurotych
-# - Remove unnecessary --coverage flag
-#
-# 2019-12-13, FeRD (Frank Dana)
-# - Deprecate COVERAGE_LCOVR_EXCLUDES and COVERAGE_GCOVR_EXCLUDES lists in favor
-# of tool-agnostic COVERAGE_EXCLUDES variable, or EXCLUDE setup arguments.
-# - CMake 3.4+: All excludes can be specified relative to BASE_DIRECTORY
-# - All setup functions: accept BASE_DIRECTORY, EXCLUDE list
-# - Set lcov basedir with -b argument
-# - Add automatic --demangle-cpp in lcovr, if 'c++filt' is available (can be
-# overridden with NO_DEMANGLE option in setup_target_for_coverage_lcovr().)
-# - Delete output dir, .info file on 'make clean'
-# - Remove Python detection, since version mismatches will break gcovr
-# - Minor cleanup (lowercase function names, update examples...)
-#
-# 2019-12-19, FeRD (Frank Dana)
-# - Rename Lcov outputs, make filtered file canonical, fix cleanup for targets
-#
-# 2020-01-19, Bob Apthorpe
-# - Added gfortran support
-#
-# 2020-02-17, FeRD (Frank Dana)
-# - Make all add_custom_target()s VERBATIM to auto-escape wildcard characters
-# in EXCLUDEs, and remove manual escaping from gcovr targets
-#
-# 2021-01-19, Robin Mueller
-# - Add CODE_COVERAGE_VERBOSE option which will allow to print out commands which are run
-# - Added the option for users to set the GCOVR_ADDITIONAL_ARGS variable to supply additional
-# flags to the gcovr command
-#
-# 2020-05-04, Mihchael Davis
-# - Add -fprofile-abs-path to make gcno files contain absolute paths
-# - Fix BASE_DIRECTORY not working when defined
-# - Change BYPRODUCT from folder to index.html to stop ninja from complaining about double defines
-#
-# 2021-05-10, Martin Stump
-# - Check if the generator is multi-config before warning about non-Debug builds
-#
-# 2022-02-22, Marko Wehle
-# - Change gcovr output from -o for --xml and --html output respectively.
-# This will allow for Multiple Output Formats at the same time by making use of GCOVR_ADDITIONAL_ARGS, e.g. GCOVR_ADDITIONAL_ARGS "--txt".
-#
-# 2022-09-28, Sebastian Mueller
-# - fix append_coverage_compiler_flags_to_target to correctly add flags
-# - replace "-fprofile-arcs -ftest-coverage" with "--coverage" (equivalent)
-#
-# USAGE:
-#
-# 1. Copy this file into your cmake modules path.
-#
-# 2. Add the following line to your CMakeLists.txt (best inside an if-condition
-# using a CMake option() to enable it just optionally):
-# include(CodeCoverage)
-#
-# 3. Append necessary compiler flags for all supported source files:
-# append_coverage_compiler_flags()
-# Or for specific target:
-# append_coverage_compiler_flags_to_target(YOUR_TARGET_NAME)
-#
-# 3.a (OPTIONAL) Set appropriate optimization flags, e.g. -O0, -O1 or -Og
-#
-# 4. If you need to exclude additional directories from the report, specify them
-# using full paths in the COVERAGE_EXCLUDES variable before calling
-# setup_target_for_coverage_*().
-# Example:
-# set(COVERAGE_EXCLUDES
-# '${PROJECT_SOURCE_DIR}/src/dir1/*'
-# '/path/to/my/src/dir2/*')
-# Or, use the EXCLUDE argument to setup_target_for_coverage_*().
-# Example:
-# setup_target_for_coverage_lcov(
-# NAME coverage
-# EXECUTABLE testrunner
-# EXCLUDE "${PROJECT_SOURCE_DIR}/src/dir1/*" "/path/to/my/src/dir2/*")
-#
-# 4.a NOTE: With CMake 3.4+, COVERAGE_EXCLUDES or EXCLUDE can also be set
-# relative to the BASE_DIRECTORY (default: PROJECT_SOURCE_DIR)
-# Example:
-# set(COVERAGE_EXCLUDES "dir1/*")
-# setup_target_for_coverage_gcovr_html(
-# NAME coverage
-# EXECUTABLE testrunner
-# BASE_DIRECTORY "${PROJECT_SOURCE_DIR}/src"
-# EXCLUDE "dir2/*")
-#
-# 5. Use the functions described below to create a custom make target which
-# runs your test executable and produces a code coverage report.
-#
-# 6. Build a Debug build:
-# cmake -DCMAKE_BUILD_TYPE=Debug ..
-# make
-# make my_coverage_target
-#
-
-include(CMakeParseArguments)
-
-option(CODE_COVERAGE_VERBOSE "Verbose information" FALSE)
-
-# Check prereqs
-find_program( GCOV_PATH gcov )
-find_program( LCOV_PATH NAMES lcov lcov.bat lcov.exe lcov.perl)
-find_program( FASTCOV_PATH NAMES fastcov fastcov.py )
-find_program( GENHTML_PATH NAMES genhtml genhtml.perl genhtml.bat )
-find_program( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/scripts/test)
-find_program( CPPFILT_PATH NAMES c++filt )
-
-if(NOT GCOV_PATH)
- message(FATAL_ERROR "gcov not found! Aborting...")
-endif() # NOT GCOV_PATH
-
-# Check supported compiler (Clang, GNU and Flang)
-get_property(LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)
-foreach(LANG ${LANGUAGES})
- if("${CMAKE_${LANG}_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang")
- if("${CMAKE_${LANG}_COMPILER_VERSION}" VERSION_LESS 3)
- message(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...")
- endif()
- elseif(NOT "${CMAKE_${LANG}_COMPILER_ID}" MATCHES "GNU"
- AND NOT "${CMAKE_${LANG}_COMPILER_ID}" MATCHES "(LLVM)?[Ff]lang")
- message(FATAL_ERROR "Compiler is not GNU or Flang! Aborting...")
- endif()
-endforeach()
-
-set(COVERAGE_COMPILER_FLAGS "-g --coverage"
- CACHE INTERNAL "")
-
-if(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
- include(CheckCXXCompilerFlag)
- check_cxx_compiler_flag(-fprofile-abs-path HAVE_cxx_fprofile_abs_path)
- if(HAVE_cxx_fprofile_abs_path)
- set(COVERAGE_CXX_COMPILER_FLAGS "${COVERAGE_COMPILER_FLAGS} -fprofile-abs-path")
- endif()
-endif()
-if(CMAKE_C_COMPILER_ID MATCHES "(GNU|Clang)")
- include(CheckCCompilerFlag)
- check_c_compiler_flag(-fprofile-abs-path HAVE_c_fprofile_abs_path)
- if(HAVE_c_fprofile_abs_path)
- set(COVERAGE_C_COMPILER_FLAGS "${COVERAGE_COMPILER_FLAGS} -fprofile-abs-path")
- endif()
-endif()
-
-set(CMAKE_Fortran_FLAGS_COVERAGE
- ${COVERAGE_COMPILER_FLAGS}
- CACHE STRING "Flags used by the Fortran compiler during coverage builds."
- FORCE )
-set(CMAKE_CXX_FLAGS_COVERAGE
- ${COVERAGE_COMPILER_FLAGS}
- CACHE STRING "Flags used by the C++ compiler during coverage builds."
- FORCE )
-set(CMAKE_C_FLAGS_COVERAGE
- ${COVERAGE_COMPILER_FLAGS}
- CACHE STRING "Flags used by the C compiler during coverage builds."
- FORCE )
-set(CMAKE_EXE_LINKER_FLAGS_COVERAGE
- ""
- CACHE STRING "Flags used for linking binaries during coverage builds."
- FORCE )
-set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
- ""
- CACHE STRING "Flags used by the shared libraries linker during coverage builds."
- FORCE )
-mark_as_advanced(
- CMAKE_Fortran_FLAGS_COVERAGE
- CMAKE_CXX_FLAGS_COVERAGE
- CMAKE_C_FLAGS_COVERAGE
- CMAKE_EXE_LINKER_FLAGS_COVERAGE
- CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
-
-get_property(GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
-if(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG))
- message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading")
-endif() # NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR GENERATOR_IS_MULTI_CONFIG)
-
-if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
- link_libraries(gcov)
-endif()
-
-# Defines a target for running and collection code coverage information
-# Builds dependencies, runs the given executable and outputs reports.
-# NOTE! The executable should always have a ZERO as exit code otherwise
-# the coverage generation will not complete.
-#
-# setup_target_for_coverage_lcov(
-# NAME testrunner_coverage # New target name
-# EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
-# DEPENDENCIES testrunner # Dependencies to build first
-# BASE_DIRECTORY "../" # Base directory for report
-# # (defaults to PROJECT_SOURCE_DIR)
-# EXCLUDE "src/dir1/*" "src/dir2/*" # Patterns to exclude (can be relative
-# # to BASE_DIRECTORY, with CMake 3.4+)
-# NO_DEMANGLE # Don't demangle C++ symbols
-# # even if c++filt is found
-# )
-function(setup_target_for_coverage_lcov)
-
- set(options NO_DEMANGLE SONARQUBE)
- set(oneValueArgs BASE_DIRECTORY NAME)
- set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES LCOV_ARGS GENHTML_ARGS)
- cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
-
- if(NOT LCOV_PATH)
- message(FATAL_ERROR "lcov not found! Aborting...")
- endif() # NOT LCOV_PATH
-
- if(NOT GENHTML_PATH)
- message(FATAL_ERROR "genhtml not found! Aborting...")
- endif() # NOT GENHTML_PATH
-
- # Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR
- if(DEFINED Coverage_BASE_DIRECTORY)
- get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
- else()
- set(BASEDIR ${PROJECT_SOURCE_DIR})
- endif()
-
- # Collect excludes (CMake 3.4+: Also compute absolute paths)
- set(LCOV_EXCLUDES "")
- foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_LCOV_EXCLUDES})
- if(CMAKE_VERSION VERSION_GREATER 3.4)
- get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR})
- endif()
- list(APPEND LCOV_EXCLUDES "${EXCLUDE}")
- endforeach()
- list(REMOVE_DUPLICATES LCOV_EXCLUDES)
-
- # Conditional arguments
- if(CPPFILT_PATH AND NOT ${Coverage_NO_DEMANGLE})
- set(GENHTML_EXTRA_ARGS "--demangle-cpp")
- endif()
-
- # Setting up commands which will be run to generate coverage data.
- # Cleanup lcov
- set(LCOV_CLEAN_CMD
- ${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} -directory .
- -b ${BASEDIR} --zerocounters
- )
- # Create baseline to make sure untouched files show up in the report
- set(LCOV_BASELINE_CMD
- ${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} -c -i -d . -b
- ${BASEDIR} -o ${Coverage_NAME}.base
- )
- # Run tests
- set(LCOV_EXEC_TESTS_CMD
- ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS}
- )
- # Capturing lcov counters and generating report
- set(LCOV_CAPTURE_CMD
- ${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} --directory . -b
- ${BASEDIR} --capture --output-file ${Coverage_NAME}.capture
- )
- # add baseline counters
- set(LCOV_BASELINE_COUNT_CMD
- ${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} -a ${Coverage_NAME}.base
- -a ${Coverage_NAME}.capture --output-file ${Coverage_NAME}.total
- )
- # filter collected data to final coverage report
- set(LCOV_FILTER_CMD
- ${LCOV_PATH} ${Coverage_LCOV_ARGS} --gcov-tool ${GCOV_PATH} --remove
- ${Coverage_NAME}.total ${LCOV_EXCLUDES} --output-file ${Coverage_NAME}.info
- )
- # Generate HTML output
- set(LCOV_GEN_HTML_CMD
- ${GENHTML_PATH} ${GENHTML_EXTRA_ARGS} ${Coverage_GENHTML_ARGS} -o
- ${Coverage_NAME} ${Coverage_NAME}.info
- )
- if(${Coverage_SONARQUBE})
- # Generate SonarQube output
- set(GCOVR_XML_CMD
- ${GCOVR_PATH} --sonarqube ${Coverage_NAME}_sonarqube.xml -r ${BASEDIR} ${GCOVR_ADDITIONAL_ARGS}
- ${GCOVR_EXCLUDE_ARGS} --object-directory=${PROJECT_BINARY_DIR}
- )
- set(GCOVR_XML_CMD_COMMAND
- COMMAND ${GCOVR_XML_CMD}
- )
- set(GCOVR_XML_CMD_BYPRODUCTS ${Coverage_NAME}_sonarqube.xml)
- set(GCOVR_XML_CMD_COMMENT COMMENT "SonarQube code coverage info report saved in ${Coverage_NAME}_sonarqube.xml.")
- endif()
-
-
- if(CODE_COVERAGE_VERBOSE)
- message(STATUS "Executed command report")
- message(STATUS "Command to clean up lcov: ")
- string(REPLACE ";" " " LCOV_CLEAN_CMD_SPACED "${LCOV_CLEAN_CMD}")
- message(STATUS "${LCOV_CLEAN_CMD_SPACED}")
-
- message(STATUS "Command to create baseline: ")
- string(REPLACE ";" " " LCOV_BASELINE_CMD_SPACED "${LCOV_BASELINE_CMD}")
- message(STATUS "${LCOV_BASELINE_CMD_SPACED}")
-
- message(STATUS "Command to run the tests: ")
- string(REPLACE ";" " " LCOV_EXEC_TESTS_CMD_SPACED "${LCOV_EXEC_TESTS_CMD}")
- message(STATUS "${LCOV_EXEC_TESTS_CMD_SPACED}")
-
- message(STATUS "Command to capture counters and generate report: ")
- string(REPLACE ";" " " LCOV_CAPTURE_CMD_SPACED "${LCOV_CAPTURE_CMD}")
- message(STATUS "${LCOV_CAPTURE_CMD_SPACED}")
-
- message(STATUS "Command to add baseline counters: ")
- string(REPLACE ";" " " LCOV_BASELINE_COUNT_CMD_SPACED "${LCOV_BASELINE_COUNT_CMD}")
- message(STATUS "${LCOV_BASELINE_COUNT_CMD_SPACED}")
-
- message(STATUS "Command to filter collected data: ")
- string(REPLACE ";" " " LCOV_FILTER_CMD_SPACED "${LCOV_FILTER_CMD}")
- message(STATUS "${LCOV_FILTER_CMD_SPACED}")
-
- message(STATUS "Command to generate lcov HTML output: ")
- string(REPLACE ";" " " LCOV_GEN_HTML_CMD_SPACED "${LCOV_GEN_HTML_CMD}")
- message(STATUS "${LCOV_GEN_HTML_CMD_SPACED}")
-
- if(${Coverage_SONARQUBE})
- message(STATUS "Command to generate SonarQube XML output: ")
- string(REPLACE ";" " " GCOVR_XML_CMD_SPACED "${GCOVR_XML_CMD}")
- message(STATUS "${GCOVR_XML_CMD_SPACED}")
- endif()
- endif()
-
- # Setup target
- add_custom_target(${Coverage_NAME}
- COMMAND ${LCOV_CLEAN_CMD}
- COMMAND ${LCOV_BASELINE_CMD}
- COMMAND ${LCOV_EXEC_TESTS_CMD}
- COMMAND ${LCOV_CAPTURE_CMD}
- COMMAND ${LCOV_BASELINE_COUNT_CMD}
- COMMAND ${LCOV_FILTER_CMD}
- COMMAND ${LCOV_GEN_HTML_CMD}
- ${GCOVR_XML_CMD_COMMAND}
-
- # Set output files as GENERATED (will be removed on 'make clean')
- BYPRODUCTS
- ${Coverage_NAME}.base
- ${Coverage_NAME}.capture
- ${Coverage_NAME}.total
- ${Coverage_NAME}.info
- ${GCOVR_XML_CMD_BYPRODUCTS}
- ${Coverage_NAME}/index.html
- WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
- DEPENDS ${Coverage_DEPENDENCIES}
- VERBATIM # Protect arguments to commands
- COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
- )
-
- # Show where to find the lcov info report
- add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
- COMMAND ;
- COMMENT "Lcov code coverage info report saved in ${Coverage_NAME}.info."
- ${GCOVR_XML_CMD_COMMENT}
- )
-
- # Show info where to find the report
- add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
- COMMAND ;
- COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report."
- )
-
-endfunction() # setup_target_for_coverage_lcov
-
-# Defines a target for running and collection code coverage information
-# Builds dependencies, runs the given executable and outputs reports.
-# NOTE! The executable should always have a ZERO as exit code otherwise
-# the coverage generation will not complete.
-#
-# setup_target_for_coverage_gcovr_xml(
-# NAME ctest_coverage # New target name
-# EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
-# DEPENDENCIES executable_target # Dependencies to build first
-# BASE_DIRECTORY "../" # Base directory for report
-# # (defaults to PROJECT_SOURCE_DIR)
-# EXCLUDE "src/dir1/*" "src/dir2/*" # Patterns to exclude (can be relative
-# # to BASE_DIRECTORY, with CMake 3.4+)
-# )
-# The user can set the variable GCOVR_ADDITIONAL_ARGS to supply additional flags to the
-# GCVOR command.
-function(setup_target_for_coverage_gcovr_xml)
-
- set(options NONE)
- set(oneValueArgs BASE_DIRECTORY NAME)
- set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
- cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
-
- if(NOT GCOVR_PATH)
- message(FATAL_ERROR "gcovr not found! Aborting...")
- endif() # NOT GCOVR_PATH
-
- # Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR
- if(DEFINED Coverage_BASE_DIRECTORY)
- get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
- else()
- set(BASEDIR ${PROJECT_SOURCE_DIR})
- endif()
-
- # Collect excludes (CMake 3.4+: Also compute absolute paths)
- set(GCOVR_EXCLUDES "")
- foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_GCOVR_EXCLUDES})
- if(CMAKE_VERSION VERSION_GREATER 3.4)
- get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR})
- endif()
- list(APPEND GCOVR_EXCLUDES "${EXCLUDE}")
- endforeach()
- list(REMOVE_DUPLICATES GCOVR_EXCLUDES)
-
- # Combine excludes to several -e arguments
- set(GCOVR_EXCLUDE_ARGS "")
- foreach(EXCLUDE ${GCOVR_EXCLUDES})
- list(APPEND GCOVR_EXCLUDE_ARGS "-e")
- list(APPEND GCOVR_EXCLUDE_ARGS "${EXCLUDE}")
- endforeach()
-
- # Set up commands which will be run to generate coverage data
- # Run tests
- set(GCOVR_XML_EXEC_TESTS_CMD
- ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS}
- )
- # Running gcovr
- set(GCOVR_XML_CMD
- ${GCOVR_PATH} --xml ${Coverage_NAME}.xml -r ${BASEDIR} ${GCOVR_ADDITIONAL_ARGS}
- ${GCOVR_EXCLUDE_ARGS} --object-directory=${PROJECT_BINARY_DIR}
- )
-
- if(CODE_COVERAGE_VERBOSE)
- message(STATUS "Executed command report")
-
- message(STATUS "Command to run tests: ")
- string(REPLACE ";" " " GCOVR_XML_EXEC_TESTS_CMD_SPACED "${GCOVR_XML_EXEC_TESTS_CMD}")
- message(STATUS "${GCOVR_XML_EXEC_TESTS_CMD_SPACED}")
-
- message(STATUS "Command to generate gcovr XML coverage data: ")
- string(REPLACE ";" " " GCOVR_XML_CMD_SPACED "${GCOVR_XML_CMD}")
- message(STATUS "${GCOVR_XML_CMD_SPACED}")
- endif()
-
- add_custom_target(${Coverage_NAME}
- COMMAND ${GCOVR_XML_EXEC_TESTS_CMD}
- COMMAND ${GCOVR_XML_CMD}
-
- BYPRODUCTS ${Coverage_NAME}.xml
- WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
- DEPENDS ${Coverage_DEPENDENCIES}
- VERBATIM # Protect arguments to commands
- COMMENT "Running gcovr to produce Cobertura code coverage report."
- )
-
- # Show info where to find the report
- add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
- COMMAND ;
- COMMENT "Cobertura code coverage report saved in ${Coverage_NAME}.xml."
- )
-endfunction() # setup_target_for_coverage_gcovr_xml
-
-# Defines a target for running and collection code coverage information
-# Builds dependencies, runs the given executable and outputs reports.
-# NOTE! The executable should always have a ZERO as exit code otherwise
-# the coverage generation will not complete.
-#
-# setup_target_for_coverage_gcovr_html(
-# NAME ctest_coverage # New target name
-# EXECUTABLE ctest -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
-# DEPENDENCIES executable_target # Dependencies to build first
-# BASE_DIRECTORY "../" # Base directory for report
-# # (defaults to PROJECT_SOURCE_DIR)
-# EXCLUDE "src/dir1/*" "src/dir2/*" # Patterns to exclude (can be relative
-# # to BASE_DIRECTORY, with CMake 3.4+)
-# )
-# The user can set the variable GCOVR_ADDITIONAL_ARGS to supply additional flags to the
-# GCVOR command.
-function(setup_target_for_coverage_gcovr_html)
-
- set(options NONE)
- set(oneValueArgs BASE_DIRECTORY NAME)
- set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES)
- cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
-
- if(NOT GCOVR_PATH)
- message(FATAL_ERROR "gcovr not found! Aborting...")
- endif() # NOT GCOVR_PATH
-
- # Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR
- if(DEFINED Coverage_BASE_DIRECTORY)
- get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
- else()
- set(BASEDIR ${PROJECT_SOURCE_DIR})
- endif()
-
- # Collect excludes (CMake 3.4+: Also compute absolute paths)
- set(GCOVR_EXCLUDES "")
- foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_GCOVR_EXCLUDES})
- if(CMAKE_VERSION VERSION_GREATER 3.4)
- get_filename_component(EXCLUDE ${EXCLUDE} ABSOLUTE BASE_DIR ${BASEDIR})
- endif()
- list(APPEND GCOVR_EXCLUDES "${EXCLUDE}")
- endforeach()
- list(REMOVE_DUPLICATES GCOVR_EXCLUDES)
-
- # Combine excludes to several -e arguments
- set(GCOVR_EXCLUDE_ARGS "")
- foreach(EXCLUDE ${GCOVR_EXCLUDES})
- list(APPEND GCOVR_EXCLUDE_ARGS "-e")
- list(APPEND GCOVR_EXCLUDE_ARGS "${EXCLUDE}")
- endforeach()
-
- # Set up commands which will be run to generate coverage data
- # Run tests
- set(GCOVR_HTML_EXEC_TESTS_CMD
- ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS}
- )
- # Create folder
- set(GCOVR_HTML_FOLDER_CMD
- ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}/${Coverage_NAME}
- )
- # Running gcovr
- set(GCOVR_HTML_CMD
- ${GCOVR_PATH} --html ${Coverage_NAME}/index.html --html-details -r ${BASEDIR} ${GCOVR_ADDITIONAL_ARGS}
- ${GCOVR_EXCLUDE_ARGS} --object-directory=${PROJECT_BINARY_DIR}
- )
-
- if(CODE_COVERAGE_VERBOSE)
- message(STATUS "Executed command report")
-
- message(STATUS "Command to run tests: ")
- string(REPLACE ";" " " GCOVR_HTML_EXEC_TESTS_CMD_SPACED "${GCOVR_HTML_EXEC_TESTS_CMD}")
- message(STATUS "${GCOVR_HTML_EXEC_TESTS_CMD_SPACED}")
-
- message(STATUS "Command to create a folder: ")
- string(REPLACE ";" " " GCOVR_HTML_FOLDER_CMD_SPACED "${GCOVR_HTML_FOLDER_CMD}")
- message(STATUS "${GCOVR_HTML_FOLDER_CMD_SPACED}")
-
- message(STATUS "Command to generate gcovr HTML coverage data: ")
- string(REPLACE ";" " " GCOVR_HTML_CMD_SPACED "${GCOVR_HTML_CMD}")
- message(STATUS "${GCOVR_HTML_CMD_SPACED}")
- endif()
-
- add_custom_target(${Coverage_NAME}
- COMMAND ${GCOVR_HTML_EXEC_TESTS_CMD}
- COMMAND ${GCOVR_HTML_FOLDER_CMD}
- COMMAND ${GCOVR_HTML_CMD}
-
- BYPRODUCTS ${PROJECT_BINARY_DIR}/${Coverage_NAME}/index.html # report directory
- WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
- DEPENDS ${Coverage_DEPENDENCIES}
- VERBATIM # Protect arguments to commands
- COMMENT "Running gcovr to produce HTML code coverage report."
- )
-
- # Show info where to find the report
- add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
- COMMAND ;
- COMMENT "Open ./${Coverage_NAME}/index.html in your browser to view the coverage report."
- )
-
-endfunction() # setup_target_for_coverage_gcovr_html
-
-# Defines a target for running and collection code coverage information
-# Builds dependencies, runs the given executable and outputs reports.
-# NOTE! The executable should always have a ZERO as exit code otherwise
-# the coverage generation will not complete.
-#
-# setup_target_for_coverage_fastcov(
-# NAME testrunner_coverage # New target name
-# EXECUTABLE testrunner -j ${PROCESSOR_COUNT} # Executable in PROJECT_BINARY_DIR
-# DEPENDENCIES testrunner # Dependencies to build first
-# BASE_DIRECTORY "../" # Base directory for report
-# # (defaults to PROJECT_SOURCE_DIR)
-# EXCLUDE "src/dir1/" "src/dir2/" # Patterns to exclude.
-# NO_DEMANGLE # Don't demangle C++ symbols
-# # even if c++filt is found
-# SKIP_HTML # Don't create html report
-# POST_CMD perl -i -pe s!${PROJECT_SOURCE_DIR}/!!g ctest_coverage.json # E.g. for stripping source dir from file paths
-# )
-function(setup_target_for_coverage_fastcov)
-
- set(options NO_DEMANGLE SKIP_HTML)
- set(oneValueArgs BASE_DIRECTORY NAME)
- set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES FASTCOV_ARGS GENHTML_ARGS POST_CMD)
- cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
-
- if(NOT FASTCOV_PATH)
- message(FATAL_ERROR "fastcov not found! Aborting...")
- endif()
-
- if(NOT Coverage_SKIP_HTML AND NOT GENHTML_PATH)
- message(FATAL_ERROR "genhtml not found! Aborting...")
- endif()
-
- # Set base directory (as absolute path), or default to PROJECT_SOURCE_DIR
- if(Coverage_BASE_DIRECTORY)
- get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
- else()
- set(BASEDIR ${PROJECT_SOURCE_DIR})
- endif()
-
- # Collect excludes (Patterns, not paths, for fastcov)
- set(FASTCOV_EXCLUDES "")
- foreach(EXCLUDE ${Coverage_EXCLUDE} ${COVERAGE_EXCLUDES} ${COVERAGE_FASTCOV_EXCLUDES})
- list(APPEND FASTCOV_EXCLUDES "${EXCLUDE}")
- endforeach()
- list(REMOVE_DUPLICATES FASTCOV_EXCLUDES)
-
- # Conditional arguments
- if(CPPFILT_PATH AND NOT ${Coverage_NO_DEMANGLE})
- set(GENHTML_EXTRA_ARGS "--demangle-cpp")
- endif()
-
- # Set up commands which will be run to generate coverage data
- set(FASTCOV_EXEC_TESTS_CMD ${Coverage_EXECUTABLE} ${Coverage_EXECUTABLE_ARGS})
-
- set(FASTCOV_CAPTURE_CMD ${FASTCOV_PATH} ${Coverage_FASTCOV_ARGS} --gcov ${GCOV_PATH}
- --search-directory ${BASEDIR}
- --process-gcno
- --output ${Coverage_NAME}.json
- --exclude ${FASTCOV_EXCLUDES}
- )
-
- set(FASTCOV_CONVERT_CMD ${FASTCOV_PATH}
- -C ${Coverage_NAME}.json --lcov --output ${Coverage_NAME}.info
- )
-
- if(Coverage_SKIP_HTML)
- set(FASTCOV_HTML_CMD ";")
- else()
- set(FASTCOV_HTML_CMD ${GENHTML_PATH} ${GENHTML_EXTRA_ARGS} ${Coverage_GENHTML_ARGS}
- -o ${Coverage_NAME} ${Coverage_NAME}.info
- )
- endif()
-
- set(FASTCOV_POST_CMD ";")
- if(Coverage_POST_CMD)
- set(FASTCOV_POST_CMD ${Coverage_POST_CMD})
- endif()
-
- if(CODE_COVERAGE_VERBOSE)
- message(STATUS "Code coverage commands for target ${Coverage_NAME} (fastcov):")
-
- message(" Running tests:")
- string(REPLACE ";" " " FASTCOV_EXEC_TESTS_CMD_SPACED "${FASTCOV_EXEC_TESTS_CMD}")
- message(" ${FASTCOV_EXEC_TESTS_CMD_SPACED}")
-
- message(" Capturing fastcov counters and generating report:")
- string(REPLACE ";" " " FASTCOV_CAPTURE_CMD_SPACED "${FASTCOV_CAPTURE_CMD}")
- message(" ${FASTCOV_CAPTURE_CMD_SPACED}")
-
- message(" Converting fastcov .json to lcov .info:")
- string(REPLACE ";" " " FASTCOV_CONVERT_CMD_SPACED "${FASTCOV_CONVERT_CMD}")
- message(" ${FASTCOV_CONVERT_CMD_SPACED}")
-
- if(NOT Coverage_SKIP_HTML)
- message(" Generating HTML report: ")
- string(REPLACE ";" " " FASTCOV_HTML_CMD_SPACED "${FASTCOV_HTML_CMD}")
- message(" ${FASTCOV_HTML_CMD_SPACED}")
- endif()
- if(Coverage_POST_CMD)
- message(" Running post command: ")
- string(REPLACE ";" " " FASTCOV_POST_CMD_SPACED "${FASTCOV_POST_CMD}")
- message(" ${FASTCOV_POST_CMD_SPACED}")
- endif()
- endif()
-
- # Setup target
- add_custom_target(${Coverage_NAME}
-
- # Cleanup fastcov
- COMMAND ${FASTCOV_PATH} ${Coverage_FASTCOV_ARGS} --gcov ${GCOV_PATH}
- --search-directory ${BASEDIR}
- --zerocounters
-
- COMMAND ${FASTCOV_EXEC_TESTS_CMD}
- COMMAND ${FASTCOV_CAPTURE_CMD}
- COMMAND ${FASTCOV_CONVERT_CMD}
- COMMAND ${FASTCOV_HTML_CMD}
- COMMAND ${FASTCOV_POST_CMD}
-
- # Set output files as GENERATED (will be removed on 'make clean')
- BYPRODUCTS
- ${Coverage_NAME}.info
- ${Coverage_NAME}.json
- ${Coverage_NAME}/index.html # report directory
-
- WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
- DEPENDS ${Coverage_DEPENDENCIES}
- VERBATIM # Protect arguments to commands
- COMMENT "Resetting code coverage counters to zero. Processing code coverage counters and generating report."
- )
-
- set(INFO_MSG "fastcov code coverage info report saved in ${Coverage_NAME}.info and ${Coverage_NAME}.json.")
- if(NOT Coverage_SKIP_HTML)
- string(APPEND INFO_MSG " Open ${PROJECT_BINARY_DIR}/${Coverage_NAME}/index.html in your browser to view the coverage report.")
- endif()
- # Show where to find the fastcov info report
- add_custom_command(TARGET ${Coverage_NAME} POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E echo ${INFO_MSG}
- )
-
-endfunction() # setup_target_for_coverage_fastcov
-
-function(append_coverage_compiler_flags)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
- set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${COVERAGE_COMPILER_FLAGS}" PARENT_SCOPE)
- message(STATUS "Appending code coverage compiler flags: ${COVERAGE_COMPILER_FLAGS}")
-endfunction() # append_coverage_compiler_flags
-
-# Setup coverage for specific library
-function(append_coverage_compiler_flags_to_target name)
- separate_arguments(_flag_list NATIVE_COMMAND "${COVERAGE_COMPILER_FLAGS}")
- target_compile_options(${name} PRIVATE ${_flag_list})
- if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_Fortran_COMPILER_ID STREQUAL "GNU")
- target_link_libraries(${name} PRIVATE gcov)
- endif()
-endfunction()
diff --git a/cmake/libsersi-api.cmake b/cmake/libsersi-api.cmake
deleted file mode 100644
index d38409f..0000000
--- a/cmake/libsersi-api.cmake
+++ /dev/null
@@ -1,92 +0,0 @@
-macro(libsersi_project_defaults)
- string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER)
- set(${PROJECT_NAME_UPPER}_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
- set(${PROJECT_NAME_UPPER}_VERSION_MINOR ${PROJECT_VERSION_MINOR})
- set(${PROJECT_NAME_UPPER}_VERSION_PATCH ${PROJECT_VERSION_PATCH})
- set(${PROJECT_NAME_UPPER}_VERSION ${PROJECT_VERSION})
- set(CI_BUILD_ID 0 CACHE STRING "CI build number")
-
- message(STATUS "${PROJECT_NAME_UPPER} Version: ${PROJECT_VERSION}")
-
- # Ensure compiling for C++17
- set(CMAKE_CXX_STANDARD 17)
- set(CMAKE_CXX_STANDARD_REQUIRED ON)
- set(CMAKE_CXX_EXTENSIONS ON)
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
-
- set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
-
- if(BUILD_SHARED_LIBS)
- set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
- endif()
-
- # Use GNU installation directories
- include(GNUInstallDirs)
- set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
- set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR})
- set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_BINDIR})
-
- # CMake CCache
- find_program(CCACHE_EXE ccache)
- if(CCACHE_EXE)
- set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXE})
- set(CMAKE_CC_COMPILER_LAUNCHER ${CCACHE_EXE})
- endif()
-
- set(CMAKE_BUILD_TYPES "" None Debug Release Profile RelWithDebugInfo MinSizeRel)
- set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_BUILD_TYPES})
- if(NOT CMAKE_CXX_FLAGS_PROFILE)
- set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE} -pg"
- CACHE STRING "Flags used by the compiler during profile builds." FORCE
- )
- set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE} -pg"
- CACHE STRING "Flags used by the compiler during profile builds." FORCE
- )
- set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -pg"
- CACHE STRING "Flags used by the linker during profile builds." FORCE
- )
- set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} -pg"
- CACHE STRING "Flags used by the linker during profile builds." FORCE
- )
- mark_as_advanced(
- CMAKE_CXX_FLAGS_PROFILE
- CMAKE_C_FLAGS_PROFILE
- CMAKE_EXE_LINKER_FLAGS_PROFILE
- CMAKE_SHARED_LINKER_FLAGS_PROFILE
- )
- endif()
-
- if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
- message(STATUS "Setting build type to 'Release' as none was specified.")
- set(CMAKE_BUILD_TYPE "Release" CACHE
- STRING "Choose the type of build." FORCE
- )
- endif()
-
- if(NOT CMAKE_BUILD_TYPE IN_LIST CMAKE_BUILD_TYPES)
- message(FATAL_ERROR "CMAKE_BUILD_TYPE should be one of ${CMAKE_BUILD_TYPES}")
- endif()
-
- option(BUILD_TESTS "Build test suites" ON)
- option(BUILD_DOCS "Build documentation" ON)
- option(ENABLE_COVERAGE "Enable code coverage instrumentation" OFF)
- option(ENABLE_LINT "Enable source code linting" OFF)
-
- if(BUILD_TESTS)
- enable_testing()
- endif()
-
- if(ENABLE_LINT)
- find_program(CLANGTIDY_EXE clang-tidy)
- if(CLANGTIDY_EXE)
- set(CMAKE_CXX_CLANG_TIDY ${CLANGTIDY_EXE})
- set(CMAKE_C_CLANG_TIDY ${CLANGTIDY_EXE})
- endif()
-
- find_program(CPPLINT_EXE cpplint)
- if(CPPLINT_EXE)
- set(CMAKE_CXX_CPPLINT ${CPPLINT_EXE} --quiet)
- endif()
- endif()
-
-endmacro(libsersi_project_defaults)
diff --git a/cmake/libsersi-config.cmake.in b/cmake/libsersi-config.cmake.in
deleted file mode 100644
index 1bd20eb..0000000
--- a/cmake/libsersi-config.cmake.in
+++ /dev/null
@@ -1,20 +0,0 @@
-set(LIBSERSI_VERSION_MAJOR @PROJECT_VERSION_MAJOR@)
-set(LIBSERSI_VERSION_MINOR @PROJECT_VERSION_MINOR@)
-set(LIBSERSI_VERSION_PATCH @PROJECT_VERSION_PATCH@)
-set(LIBSERSI_VERSION @PROJECT_VERSION@)
-
-@PACKAGE_INIT@
-
-set_and_check(LIBSERSI_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
-set_and_check(LIBSERSI_LIB_DIR "@PACKAGE_CMAKE_INSTALL_LIBDIR@")
-set_and_check(LIBSERSI_PACKAGE_DIR "@PACKAGE_CMAKE_INSTALL_LIBDIR@/cmake/libsersi")
-if (${_NAME}_doc_FOUND)
- set_and_check(LIBSERSI_DOC_DIR "@PACKAGE_CMAKE_INSTALL_DOCDIR@")
-endif()
-
-include(${CMAKE_CURRENT_LIST_DIR}/libsersi-targets.cmake)
-
-list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/Modules)
-list(APPEND CMAKE_PROGRAM_PATH ${CMAKE_CURRENT_LIST_DIR}/Modules)
-
-include(${CMAKE_CURRENT_LIST_DIR}/libsersi-api.cmake)
diff --git a/conanfile.py b/conanfile.py
new file mode 100644
index 0000000..a977d09
--- /dev/null
+++ b/conanfile.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from conan import ConanFile
+from conan.tools.build import check_min_cppstd
+from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
+
+required_conan_version = ">=2.9.3"
+
+
+class SersiConan(ConanFile):
+ name = "sersi"
+ version = "0.2.0"
+
+ settings = "os", "arch", "compiler", "build_type"
+ generators = "CMakeToolchain", "CMakeDeps"
+
+ def validate(self):
+ if self.info.settings.get_safe("compiler.cppstd"):
+ check_min_cppstd(self, 17)
+
+ def build(self):
+ cmake = CMake(self)
+ cmake.configure(
+ variables={"PROJECT_NAME": self.name, "PROJECT_VERSION": self.version}
+ )
+ cmake.build()
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
new file mode 100644
index 0000000..7a77674
--- /dev/null
+++ b/include/CMakeLists.txt
@@ -0,0 +1,8 @@
+# Create list of all headers
+file(GLOB_RECURSE protocol_hdrs
+ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
+ *.hpp
+)
+
+install(FILES ${protocol_hdrs}
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libsersi)
diff --git a/include/DistributedEmissions.hpp b/include/DistributedEmissions.hpp
new file mode 100644
index 0000000..16811e5
--- /dev/null
+++ b/include/DistributedEmissions.hpp
@@ -0,0 +1,65 @@
+#pragma once
+
+namespace dis {
+// Section 5.3.7.1. Information about active electronic warfare (EW) emissions
+// and active EW countermeasures shall be communicated using an Electromagnetic
+// Emission PDU. COMPLETE (I think)
+
+class ElectromagneticEmissionsPdu : public Pdu {
+ private:
+ /** ID of the entity emitting */
+ EntityID emitting_entity_id_;
+
+ /** ID of event */
+ EventID event_id_;
+
+ /** This field shall be used to indicate if the data in the PDU represents a
+ * state update or just data that has changed since issuance of the last
+ * Electromagnetic Emission PDU [relative to the identified entity and
+ * emission system(s)]. */
+ uint8_t state_update_indicator_;
+
+ /** This field shall specify the number of emission systems being described in
+ * the current PDU. */
+ uint8_t number_of_systems_;
+
+ /** padding */
+ uint16_t padding_for_emissions_pdu_;
+
+ /** Electromagnetic emmissions systems */
+ std::vector systems_;
+
+ public:
+ ElectromagneticEmissionsPdu();
+ ~ElectromagneticEmissionsPdu() override;
+
+ Result Marshal(ByteBuffer& byte_buffer) const override;
+ Result Unmarshal(ByteBuffer& byte_buffer) override;
+
+ EntityID& GetEmittingEntityId();
+ [[nodiscard]] const EntityID& GetEmittingEntityId() const;
+ void SetEmittingEntityId(const EntityID& value);
+
+ EventID& GetEventId();
+ [[nodiscard]] const EventID& GetEventId() const;
+ void SetEventId(const EventID& value);
+
+ [[nodiscard]] uint8_t GetStateUpdateIndicator() const;
+ void SetStateUpdateIndicator(uint8_t value);
+
+ [[nodiscard]] uint8_t GetNumberOfSystems() const;
+
+ [[nodiscard]] uint16_t GetPaddingForEmissionsPdu() const;
+ void SetPaddingForEmissionsPdu(uint16_t value);
+
+ std::vector& GetSystems();
+ [[nodiscard]] const std::vector&
+ GetSystems() const;
+ void SetSystems(const std::vector& value);
+
+ [[nodiscard]] std::size_t GetMarshalledSize() const override;
+
+ bool operator==(const ElectromagneticEmissionsPdu& rhs) const;
+};
+
+}
diff --git a/include/EntityInformation.hpp b/include/EntityInformation.hpp
new file mode 100644
index 0000000..c0b0d8b
--- /dev/null
+++ b/include/EntityInformation.hpp
@@ -0,0 +1,39 @@
+#pragma once
+
+#include common/EntityID.h"
+#include common/EventID.h"
+#include common/Pdu.hpp"
+#include common/Vector3Float.h"
+
+namespace dis {
+class CollisionElasticPdu final : public Pdu {
+ FIELD(EntityID, issuing_entity_id)
+ FIELD(EntityID, colliding_entity_id)
+ FIELD(EventID, collision_event_id)
+ FIELD(uint16_t, padding)
+ FIELD(Vector3Float, contact_velocity)
+ FIELD(float, mass)
+ FIELD(Vector3Float, location)
+ FIELD(float, collision_result_xx)
+ FIELD(float, collision_result_xy)
+ FIELD(float, collision_result_xz)
+ FIELD(float, collision_result_yy)
+ FIELD(float, collision_result_yz)
+ FIELD(float, collision_result_zz)
+ FIELD(Vector3Float, unit_surface_normal)
+ FIELD(float, coefficient_of_restitution)
+
+ public:
+ CollisionElasticPdu();
+ ~CollisionElasticPdu() final;
+
+ Result Marshal(ByteBuffer& data_stream) const final;
+ Result Unmarshal(ByteBuffer& data_stream) final;
+
+ [[nodiscard]] std::size_t GetMarshalledSize() const final;
+
+ friend bool operator==(const CollisionElasticPdu& lhs, const CollisionElasticPdu& rhs) {
+ return lhs.issuing_entity_id_ == rhs.issuing_entity_id_;
+ }
+};
+} // namespace dis
diff --git a/include/EntityManagement.hpp b/include/EntityManagement.hpp
new file mode 100644
index 0000000..e69de29
diff --git a/include/Logistics.hpp b/include/Logistics.hpp
new file mode 100644
index 0000000..e69de29
diff --git a/include/Minefield.hpp b/include/Minefield.hpp
new file mode 100644
index 0000000..e69de29
diff --git a/include/RadioCommunications.hpp b/include/RadioCommunications.hpp
new file mode 100644
index 0000000..e69de29
diff --git a/include/Warfare.hpp b/include/Warfare.hpp
new file mode 100644
index 0000000..3f3375f
--- /dev/null
+++ b/include/Warfare.hpp
@@ -0,0 +1,148 @@
+// libsersi - C++ implementation of the IEEE 1278.1-2012 Distributed
+// Interactive Simulation application protocol specification
+// Copyright (C) 2026 Cameron Howell
+//
+// Licensed under the BSD-2-Clause License
+
+#pragma once
+
+#include "common/data_types/ArticulationParameter.hpp"
+#include "common/data_types/BurstDescriptor.hpp"
+#include "common/data_types/EntityID.hpp"
+#include "common/data_types/EventID.hpp"
+#include "common/Pdu.hpp"
+#include "common/data_types/Vector3Double.hpp"
+#include "common/data_types/Vector3Float.hpp"
+#include "common/data_types/ClockTime.hpp"
+#include "utils/ByteBuffer.hpp"
+
+namespace dis {
+/// Implemented according to IEEE 1278.1-2012 §7.3.2
+class FirePdu final : public Pdu {
+ FIELD(EntityID, firing_entity_id)
+ FIELD(EntityID, target_entity_id)
+ FIELD(EntityID, munition_id)
+ FIELD(EventID, event_id)
+ FIELD(int, fire_mission_index)
+ FIELD(Vector3Double, location_in_world_coordinates)
+ FIELD(BurstDescriptor, burst_descriptor)
+ FIELD(Vector3Float, velocity)
+ FIELD(float, range)
+
+ public:
+ FirePdu();
+ ~FirePdu() final;
+
+ Result Marshal(ByteBuffer& byte_buffer) const final;
+ Result Unmarshal(ByteBuffer& byte_buffer) final;
+
+ [[nodiscard]] std::size_t GetMarshalledSize() const final;
+
+ friend bool operator==(const FirePdu& lhs, const FirePdu& rhs) {
+ return lhs.firing_entity_id_ == rhs.firing_entity_id_ && lhs.target_entity_id_ == rhs.target_entity_id_ &&
+ lhs.munition_id_ == rhs.munition_id_ && lhs.event_id_ == rhs.event_id_ &&
+ lhs.fire_mission_index_ == rhs.fire_mission_index_ &&
+ lhs.location_in_world_coordinates_ == rhs.location_in_world_coordinates_ &&
+ lhs.burst_descriptor_ == rhs.burst_descriptor_ && lhs.velocity_ == rhs.velocity_ && lhs.range_ == rhs.range_;
+ }
+};
+
+/// Implemented according to IEEE 1278.1-2012 §7.3.3
+class DetonationPdu final : public Pdu {
+ FIELD(EntityID, firing_entity_id)
+ FIELD(EntityID, target_entity_id)
+ FIELD(EntityID, munition_id)
+ FIELD(EventID, event_id)
+ FIELD(Vector3Float, velocity)
+ FIELD(Vector3Double, location_in_world_coordinates)
+ FIELD(BurstDescriptor, burst_descriptor)
+ FIELD(Vector3Float, location_in_entity_coordinates)
+ FIELD(uint8_t, detonation_result)
+ FIELD(uint8_t, number_of_articulation_parameters)
+ FIELD(uint16_t, padding)
+ FIELD(std::vector, articulation_parameters)
+
+ public:
+ DetonationPdu();
+ ~DetonationPdu() final;
+
+ Result Marshal(ByteBuffer& byte_buffer) const final;
+ Result Unmarshal(ByteBuffer& byte_buffer) final;
+
+ [[nodiscard]] std::size_t GetMarshalledSize() const final;
+
+ friend bool operator==(const DetonationPdu& lhs, const DetonationPdu& rhs) {
+ return lhs.firing_entity_id_ == rhs.firing_entity_id_ && lhs.target_entity_id_ == rhs.target_entity_id_ &&
+ lhs.munition_id_ == rhs.munition_id_ && lhs.event_id_ == rhs.event_id_;
+ }
+};
+
+/// Implemented according to IEEE 1278.1-2012 §7.3.4
+class DirectedEnergyFirePdu final : public Pdu {
+ FIELD(EntityID, firing_entity_id)
+ FIELD(EventID, event_id)
+ FIELD(EntityType, munition_type)
+ FIELD(ClockTime, shot_start_time)
+ FIELD(float, cumulative_shot_time)
+ FIELD(EntityCoordinateVector, aperture_emitter_location)
+ FIELD(float, aperture_diameter)
+ FIELD(float, wavelength)
+ FIELD(uint32_t, padding)
+ FIELD(float, pulse_repetition_frequency)
+ FIELD(float, pulse_width)
+ FIELD(uint16_t, flags)
+ FIELD(DEFirePulseShape, pulse_shape)
+ FIELD(uint8_t, padding2)
+ FIELD(uint32_t, padding3)
+ FIELD(uint16_t, padding4)
+ FIELD(uint16_t, number_of_de_records)
+ FIELD(std::vector, damage_descriptions)
+
+ public:
+ DirectedEnergyFirePdu();
+ ~DirectedEnergyFirePdu() final;
+
+ Result Marshal(ByteBuffer& byte_buffer) const final;
+ Result Unmarshal(ByteBuffer& byte_buffer) final;
+
+ [[nodiscard]] std::size_t GetMarshalledSize() const final;
+
+ friend bool operator==(const DirectedEnergyFirePdu& lhs, const DirectedEnergyFirePdu& rhs) {
+ return lhs.firing_entity_id_ == rhs.firing_entity_id_ && lhs.event_id_ == rhs.event_id_ &&
+ lhs.munition_type_ == rhs.munition_type_ && lhs.shot_start_time_ == rhs.shot_start_time_ &&
+ lhs.cumulative_shot_time_ == rhs.cumulative_shot_time_ &&
+ lhs.aperture_emitter_location_ == rhs.aperture_emitter_location_ &&
+ lhs.aperture_diameter_ == rhs.aperture_diameter_ && lhs.wavelength_ == rhs.wavelength_ &&
+ lhs.padding_ == rhs.padding_ && lhs.pulse_repetition_frequency_ == rhs.pulse_repetition_frequency_ &&
+ lhs.pulse_width_ == rhs.pulse_width_ && lhs.flags_ == rhs.flags_ && lhs.pulse_shape_ == rhs.pulse_shape_ &&
+ lhs.padding2_ == rhs.padding2_ && lhs.padding3_ == rhs.padding3_ && lhs.padding4_ == rhs.padding4_ &&
+ lhs.number_of_de_records_ == rhs.number_of_de_records_ &&
+ lhs.damage_descriptions_ == rhs.damage_descriptions_;
+ }
+};
+
+/// Implemented according to IEEE 1278.1-2012 §7.3.5
+class EntityDamageStatusPdu final : public Pdu {
+ FIELD(EntityID, damaged_entity_id);
+ FIELD(uint16_t, padding);
+ FIELD(uint16_t, padding2);
+ FIELD(uint16_t, number_of_damage_descriptions);
+ FIELD(std::vector, damage_descriptions);
+
+ public:
+ EntityDamageStatusPdu();
+ ~EntityDamageStatusPdu() final;
+
+ Result Marshal(ByteBuffer& byte_buffer) const final;
+ Result Unmarshal(ByteBuffer& byte_buffer) final;
+
+ [[nodiscard]] std::size_t GetMarshalledSize() const final;
+
+ friend bool operator==(const EntityDamageStatusPdu& lhs, const EntityDamageStatusPdu& rhs) {
+ return lhs.damaged_entity_id_ == rhs.damaged_entity_id_ && lhs.padding_ == rhs.padding_ &&
+ lhs.padding2_ == rhs.padding2_ && lhs.number_of_damage_descriptions_ == rhs.number_of_damage_descriptions_ &&
+ lhs.damage_descriptions_ == rhs.damage_descriptions_;
+ }
+};
+
+} // namespace dis
diff --git a/src/libsersi/warfare/BurstDescriptor.h b/include/common/BurstDescriptor.hpp
similarity index 79%
rename from src/libsersi/warfare/BurstDescriptor.h
rename to include/common/BurstDescriptor.hpp
index 398b898..0770c40 100644
--- a/src/libsersi/warfare/BurstDescriptor.h
+++ b/include/common/BurstDescriptor.hpp
@@ -1,8 +1,8 @@
-#ifndef LIBSERSI_WARFARE_BURSTDESCRIPTOR_H_
-#define LIBSERSI_WARFARE_BURSTDESCRIPTOR_H_
+#pragma once
-#include "libsersi/common/EntityType.h"
-#include "libsersi/utils/DataStream.h"
+#include "common/data_types/EntityType.hpp"
+#include "utils/ByteBuffer.hpp"
+#include "common/Result.hpp"
namespace dis {
// Section 5.2.7. Specifies the type of muntion fired, the type of warhead, the
@@ -30,8 +30,8 @@ class BurstDescriptor {
BurstDescriptor();
~BurstDescriptor() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
EntityType& GetMunition();
[[nodiscard]] const EntityType& GetMunition() const;
@@ -54,5 +54,3 @@ class BurstDescriptor {
bool operator==(const BurstDescriptor& rhs) const;
};
} // namespace dis
-
-#endif // LIBSERSI_WARFARE_BURSTDESCRIPTOR_H_
diff --git a/include/common/Pdu.hpp b/include/common/Pdu.hpp
new file mode 100644
index 0000000..405b4ab
--- /dev/null
+++ b/include/common/Pdu.hpp
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "common/PduHeader.hpp"
+#include "common/Result.hpp"
+#include "utils/ByteBuffer.hpp"
+
+#define FIELD(type, name) \
+ private: \
+ type name##_; \
+ \
+ public: \
+ const type& name() const { return name##_; } \
+ void name(const type& value) { name##_ = value; }
+
+namespace dis {
+// The superclass for all PDUs. This incorporates the PduHeader record,
+// section 5.2.29.
+
+class Pdu {
+ protected:
+ PduHeader header_; // NOLINT
+
+ public:
+ Pdu() = default;
+ virtual ~Pdu() = default;
+
+ virtual Result Marshal(ByteBuffer& byte_buffer) const;
+ virtual Result Unmarshal(ByteBuffer& byte_buffer);
+
+ [[nodiscard]] const PduHeader header() const;
+
+ [[nodiscard]] virtual std::size_t GetMarshalledSize() const;
+
+ bool operator==(const Pdu& rhs) const;
+};
+} // namespace dis
diff --git a/include/common/PduHeader.hpp b/include/common/PduHeader.hpp
new file mode 100644
index 0000000..3ab92b5
--- /dev/null
+++ b/include/common/PduHeader.hpp
@@ -0,0 +1,74 @@
+#pragma once
+
+#include
+
+#include "common/enums.hpp"
+#include "utils/ByteBuffer.hpp"
+#include "common/Result.hpp"
+
+namespace dis {
+
+class PduStatusRecord {
+ public:
+ // TransferredEntityIdenticator tei_;
+ // LVCIndicator lvc_;
+ // CoupledExtensionIndicator cei_;
+ // B2 bit4_5_;
+ // B2 _reserved;
+};
+
+class PduHeader {
+ public:
+ PduHeader() = default;
+ ~PduHeader() = default;
+
+ uint32_t CalculateDISTimestamp();
+
+ [[nodiscard]] ProtocolVersion protocol_version() const;
+ void protocol_version(ProtocolVersion value);
+
+ [[nodiscard]] uint8_t exercise_id() const;
+ void exercise_id(uint8_t value);
+
+ [[nodiscard]] PduType pdu_type() const;
+ void pdu_type(PduType value);
+
+ [[nodiscard]] ProtocolFamily protocol_family() const;
+ void protocol_family(ProtocolFamily value);
+
+ [[nodiscard]] uint32_t timestamp() const;
+ void timestamp(uint32_t value);
+
+ [[nodiscard]] uint16_t length() const;
+ void length(uint16_t value);
+
+ [[nodiscard]] PduStatusRecord status_record() const;
+ void status_record(PduStatusRecord value);
+
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
+
+ private:
+ /// The version of the protocol
+ ProtocolVersion protocol_version_;
+
+ /// Exercise ID
+ uint8_t exercise_id_;
+
+ /// Type of PDU, unique for each PDU class
+ PduType pdu_type_;
+
+ /// Value that refers to the protocol family
+ ProtocolFamily protocol_family_;
+
+ /// Timestamp value
+ uint32_t timestamp_;
+
+ /// Length, in bytes, of the PDU
+ uint16_t length_;
+
+ /// PDU status record
+ PduStatusRecord status_record_;
+};
+
+} // namespace dis
diff --git a/src/libsersi/common/RecordSet.h b/include/common/RecordSet.hpp
similarity index 85%
rename from src/libsersi/common/RecordSet.h
rename to include/common/RecordSet.hpp
index 7fa7b56..8a8c88c 100644
--- a/src/libsersi/common/RecordSet.h
+++ b/include/common/RecordSet.hpp
@@ -2,7 +2,8 @@
#include
-#include "libsersi/utils/DataStream.h"
+#include "utils/ByteBuffer.hpp"
+#include "common/Result.hpp"
namespace dis {
// Record sets, used in transfer control request PDU
@@ -31,8 +32,8 @@ class RecordSet {
RecordSet();
~RecordSet() = default;
- void Marshal(dis::DataStream& data_stream) const;
- void Unmarshal(dis::DataStream& data_stream);
+ Result Marshal(dis::ByteBuffer& byte_buffer) const;
+ Result Unmarshal(dis::ByteBuffer& byte_buffer);
[[nodiscard]] uint32_t GetRecordId() const;
void SetRecordId(uint32_t value);
diff --git a/include/common/Result.hpp b/include/common/Result.hpp
new file mode 100644
index 0000000..9ea1fba
--- /dev/null
+++ b/include/common/Result.hpp
@@ -0,0 +1,100 @@
+#pragma once
+
+#include
+#include
+#include
+
+#define TRY(expr) \
+ do { \
+ auto _res = (expr); \
+ if (!_res) return Result::Err(*_res.err()); \
+ } while (false)
+
+template
+class Result {
+ public:
+ using value_type = T;
+ using error_type = E;
+
+ explicit operator bool() const noexcept { return is_ok(); }
+
+ static Result Ok(T value) { return Result(std::move(value)); }
+ static Result Err(E error) { return Result(std::move(error), err_tag{}); }
+
+ [[nodiscard]] bool is_ok() const noexcept { return std::holds_alternative(data_); }
+
+ [[nodiscard]] bool is_err() const noexcept { return std::holds_alternative(data_); }
+
+ const T& unwrap() const {
+ if (is_err()) {
+ throw std::logic_error("Called unwrap() on Err");
+ }
+ return std::get(data_);
+ }
+
+ const E& unwrap_err() const {
+ if (is_ok()) {
+ throw std::logic_error("Called unwrap_err() on Ok");
+ }
+ return std::get(data_);
+ }
+
+ const T* ok() const noexcept { return std::get_if(&data_); }
+
+ const E* err() const noexcept { return std::get_if(&data_); }
+
+ private:
+ struct err_tag {};
+
+ explicit Result(T value) : data_(std::move(value)) {}
+
+ Result(E error, [[maybe_unused]] err_tag et) : data_(std::move(error)) {}
+
+ std::variant data_;
+};
+
+template
+class [[nodiscard]] Result {
+ public:
+ using error_type = E;
+
+ explicit operator bool() const noexcept { return is_ok(); }
+
+ // Factory helpers
+ static Result Ok() { return Result(ok_tag{}); }
+
+ static Result Err(E error) { return Result(std::move(error)); }
+
+ // Observers
+ [[nodiscard]] bool is_ok() const noexcept { return std::holds_alternative(data_); }
+
+ [[nodiscard]] bool is_err() const noexcept { return std::holds_alternative(data_); }
+
+ // Checked accessors
+ void unwrap() const {
+ if (is_err()) {
+ throw std::logic_error("Called unwrap() on Err");
+ }
+ }
+
+ const E& unwrap_err() const {
+ if (is_ok()) {
+ throw std::logic_error("Called unwrap_err() on Ok");
+ }
+ return std::get(data_);
+ }
+
+ // Optional-style accessors
+ [[nodiscard]] bool ok() const noexcept { return is_ok(); }
+
+ const E* err() const noexcept { return std::get_if(&data_); }
+
+ private:
+ struct ok_tag {};
+
+ explicit Result(ok_tag) : data_(ok_tag{}) {} // NOLINT
+
+ explicit Result(E error) : data_(std::move(error)) {}
+
+ std::variant data_;
+};
diff --git a/src/libsersi/distributed_emissions/AcousticBeamData.h b/include/common/data_types/AcousticBeamData.h
similarity index 73%
rename from src/libsersi/distributed_emissions/AcousticBeamData.h
rename to include/common/data_types/AcousticBeamData.h
index e090113..21a572a 100644
--- a/src/libsersi/distributed_emissions/AcousticBeamData.h
+++ b/include/common/data_types/AcousticBeamData.h
@@ -1,10 +1,9 @@
-#ifndef LIBSERSI_DISTRIBUTED_EMISSIONS_ACOUSTICBEAMDATA_H_
-#define LIBSERSI_DISTRIBUTED_EMISSIONS_ACOUSTICBEAMDATA_H_
+#pragma once
#include
-#include "libsersi/distributed_emissions/AcousticBeamFundamentalParameter.h"
-#include "libsersi/utils/DataStream.h"
+#include distributed_emissions/AcousticBeamFundamentalParameter.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// Used in UA PDU
@@ -27,8 +26,8 @@ class AcousticBeamData {
AcousticBeamData();
~AcousticBeamData() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] uint16_t GetBeamDataLength() const;
void SetBeamDataLength(uint16_t value);
@@ -50,5 +49,3 @@ class AcousticBeamData {
bool operator==(const AcousticBeamData& rhs) const;
};
} // namespace dis
-
-#endif // LIBSERSI_DISTRIBUTED_EMISSIONS_ACOUSTICBEAMDATA_H_
diff --git a/src/libsersi/distributed_emissions/AcousticBeamFundamentalParameter.h b/include/common/data_types/AcousticBeamFundamentalParameter.h
similarity index 90%
rename from src/libsersi/distributed_emissions/AcousticBeamFundamentalParameter.h
rename to include/common/data_types/AcousticBeamFundamentalParameter.h
index 43739e5..fef5c33 100644
--- a/src/libsersi/distributed_emissions/AcousticBeamFundamentalParameter.h
+++ b/include/common/data_types/AcousticBeamFundamentalParameter.h
@@ -3,7 +3,7 @@
#include
-#include "libsersi/utils/DataStream.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// Used in UaPdu
@@ -32,8 +32,8 @@ class AcousticBeamFundamentalParameter {
AcousticBeamFundamentalParameter();
~AcousticBeamFundamentalParameter() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] uint16_t GetActiveEmissionParameterIndex() const;
void SetActiveEmissionParameterIndex(uint16_t value);
diff --git a/src/libsersi/distributed_emissions/AcousticEmitter.h b/include/common/data_types/AcousticEmitter.h
similarity index 86%
rename from src/libsersi/distributed_emissions/AcousticEmitter.h
rename to include/common/data_types/AcousticEmitter.h
index a6063d4..dfbf172 100644
--- a/src/libsersi/distributed_emissions/AcousticEmitter.h
+++ b/include/common/data_types/AcousticEmitter.h
@@ -3,7 +3,7 @@
#include
-#include "libsersi/utils/DataStream.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// Section 5.2.35. information about a specific UA emmtter
@@ -23,8 +23,8 @@ class AcousticEmitter {
AcousticEmitter();
~AcousticEmitter() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] uint16_t GetAcousticName() const;
void SetAcousticName(uint16_t value);
diff --git a/src/libsersi/distributed_emissions/AcousticEmitterSystem.h b/include/common/data_types/AcousticEmitterSystem.h
similarity index 89%
rename from src/libsersi/distributed_emissions/AcousticEmitterSystem.h
rename to include/common/data_types/AcousticEmitterSystem.h
index 53f6eae..c81b086 100644
--- a/src/libsersi/distributed_emissions/AcousticEmitterSystem.h
+++ b/include/common/data_types/AcousticEmitterSystem.h
@@ -2,7 +2,7 @@
#include
-#include "libsersi/utils/DataStream.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// 5.3.35: Information about a particular UA emitter shall be represented using
@@ -29,8 +29,8 @@ class AcousticEmitterSystem {
AcousticEmitterSystem();
~AcousticEmitterSystem() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] uint16_t GetAcousticName() const;
void SetAcousticName(uint16_t value);
diff --git a/src/libsersi/distributed_emissions/AcousticEmitterSystemData.h b/include/common/data_types/AcousticEmitterSystemData.h
similarity index 86%
rename from src/libsersi/distributed_emissions/AcousticEmitterSystemData.h
rename to include/common/data_types/AcousticEmitterSystemData.h
index 495217f..be8bfe6 100644
--- a/src/libsersi/distributed_emissions/AcousticEmitterSystemData.h
+++ b/include/common/data_types/AcousticEmitterSystemData.h
@@ -3,10 +3,10 @@
#include
#include
-#include "libsersi/common/Vector3Float.h"
-#include "libsersi/distributed_emissions/AcousticBeamData.h"
-#include "libsersi/distributed_emissions/AcousticEmitterSystem.h"
-#include "libsersi/utils/DataStream.h"
+#include common/Vector3Float.h"
+#include distributed_emissions/AcousticBeamData.h"
+#include distributed_emissions/AcousticEmitterSystem.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// Used in the UA pdu; ties together an emmitter and a location. This requires
@@ -38,8 +38,8 @@ class AcousticEmitterSystemData {
AcousticEmitterSystemData();
~AcousticEmitterSystemData();
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] uint8_t GetEmitterSystemDataLength() const;
void SetEmitterSystemDataLength(uint8_t value);
diff --git a/src/libsersi/distributed_emissions/ApaData.h b/include/common/data_types/ApaData.h
similarity index 79%
rename from src/libsersi/distributed_emissions/ApaData.h
rename to include/common/data_types/ApaData.h
index 3b80e89..b73d32f 100644
--- a/src/libsersi/distributed_emissions/ApaData.h
+++ b/include/common/data_types/ApaData.h
@@ -3,7 +3,7 @@
#include
#include
-#include "libsersi/utils/DataStream.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// Used in UA PDU
@@ -20,8 +20,8 @@ class ApaData {
ApaData();
~ApaData() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] uint16_t GetParameterIndex() const;
void SetParameterIndex(uint16_t value);
diff --git a/src/libsersi/common/ArticulationParameter.h b/include/common/data_types/ArticulationParameter.hpp
similarity index 80%
rename from src/libsersi/common/ArticulationParameter.h
rename to include/common/data_types/ArticulationParameter.hpp
index 8443c86..2912822 100644
--- a/src/libsersi/common/ArticulationParameter.h
+++ b/include/common/data_types/ArticulationParameter.hpp
@@ -1,9 +1,9 @@
-#ifndef LIBSERSI_COMMON_ARTICULATIONPARAMETER_H_
-#define LIBSERSI_COMMON_ARTICULATIONPARAMETER_H_
+#pragma once
#include
-#include "libsersi/utils/DataStream.h"
+#include "utils/ByteBuffer.hpp"
+#include "common/Result.hpp"
namespace dis {
// Section 5.2.5. Articulation parameters for movable parts and attached parts
@@ -27,8 +27,8 @@ class ArticulationParameter {
ArticulationParameter();
~ArticulationParameter() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] uint8_t GetParameterTypeDesignator() const;
void SetParameterTypeDesignator(uint8_t value);
@@ -51,6 +51,3 @@ class ArticulationParameter {
};
} // namespace dis
-
-#endif // LIBSERSI_COMMON_ARTICULATIONPARAMETER_H_
-
diff --git a/src/libsersi/distributed_emissions/BeamData.h b/include/common/data_types/BeamData.h
similarity index 90%
rename from src/libsersi/distributed_emissions/BeamData.h
rename to include/common/data_types/BeamData.h
index d04d36c..40ecd3c 100644
--- a/src/libsersi/distributed_emissions/BeamData.h
+++ b/include/common/data_types/BeamData.h
@@ -1,6 +1,6 @@
#pragma once
-#include "libsersi/utils/DataStream.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// Section 5.2.39. Specification of the data necessary to describe the scan
@@ -30,8 +30,8 @@ class BeamData {
BeamData();
~BeamData() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] float GetBeamAzimuthCenter() const;
void SetBeamAzimuthCenter(float value);
diff --git a/src/libsersi/common/ClockTime.h b/include/common/data_types/ClockTime.hpp
similarity index 73%
rename from src/libsersi/common/ClockTime.h
rename to include/common/data_types/ClockTime.hpp
index ab35e31..59d02a2 100644
--- a/src/libsersi/common/ClockTime.h
+++ b/include/common/data_types/ClockTime.hpp
@@ -1,6 +1,7 @@
#pragma once
-#include "libsersi/utils/DataStream.h"
+#include "common/Result.hpp"
+#include "utils/ByteBuffer.hpp"
namespace dis {
// Section 5.2.8. Time measurements that exceed one hour. Hours is the number of
@@ -16,10 +17,10 @@ class ClockTime {
public:
ClockTime();
- virtual ~ClockTime();
+ ~ClockTime() = default;
- virtual void Marshal(DataStream& data_stream) const;
- virtual void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] int GetHour() const;
void SetHour(int value);
@@ -32,4 +33,3 @@ class ClockTime {
bool operator==(const ClockTime& rhs) const;
};
} // namespace dis
-
diff --git a/src/libsersi/distributed_emissions/ElectromagneticEmissionBeamData.h b/include/common/data_types/ElectromagneticEmissionBeamData.h
similarity index 91%
rename from src/libsersi/distributed_emissions/ElectromagneticEmissionBeamData.h
rename to include/common/data_types/ElectromagneticEmissionBeamData.h
index b6a8927..20c99f4 100644
--- a/src/libsersi/distributed_emissions/ElectromagneticEmissionBeamData.h
+++ b/include/common/data_types/ElectromagneticEmissionBeamData.h
@@ -2,9 +2,9 @@
#include
-#include "libsersi/distributed_emissions/FundamentalParameterData.h"
-#include "libsersi/distributed_emissions/TrackJamTarget.h"
-#include "libsersi/utils/DataStream.h"
+#include distributed_emissions/FundamentalParameterData.h"
+#include distributed_emissions/TrackJamTarget.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// Description of one electronic emission beam
@@ -51,8 +51,8 @@ class ElectromagneticEmissionBeamData {
ElectromagneticEmissionBeamData();
~ElectromagneticEmissionBeamData();
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] uint8_t GetBeamDataLength() const;
void SetBeamDataLength(uint8_t value);
diff --git a/src/libsersi/distributed_emissions/ElectromagneticEmissionSystemData.h b/include/common/data_types/ElectromagneticEmissionSystemData.h
similarity index 86%
rename from src/libsersi/distributed_emissions/ElectromagneticEmissionSystemData.h
rename to include/common/data_types/ElectromagneticEmissionSystemData.h
index aff47c8..7fbaa8a 100644
--- a/src/libsersi/distributed_emissions/ElectromagneticEmissionSystemData.h
+++ b/include/common/data_types/ElectromagneticEmissionSystemData.h
@@ -2,10 +2,10 @@
#include
-#include "libsersi/common/Vector3Float.h"
-#include "libsersi/distributed_emissions/ElectromagneticEmissionBeamData.h"
-#include "libsersi/distributed_emissions/EmitterSystem.h"
-#include "libsersi/utils/DataStream.h"
+#include common/Vector3Float.h"
+#include distributed_emissions/ElectromagneticEmissionBeamData.h"
+#include distributed_emissions/EmitterSystem.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// Data about one electronic system
@@ -37,8 +37,8 @@ class ElectromagneticEmissionSystemData {
ElectromagneticEmissionSystemData();
~ElectromagneticEmissionSystemData();
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] uint8_t GetSystemDataLength() const;
void SetSystemDataLength(uint8_t value);
diff --git a/src/libsersi/distributed_emissions/EmitterSystem.h b/include/common/data_types/EmitterSystem.h
similarity index 83%
rename from src/libsersi/distributed_emissions/EmitterSystem.h
rename to include/common/data_types/EmitterSystem.h
index c59b3fd..8e98aaf 100644
--- a/src/libsersi/distributed_emissions/EmitterSystem.h
+++ b/include/common/data_types/EmitterSystem.h
@@ -2,7 +2,7 @@
#include
-#include "libsersi/utils/DataStream.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// Section 5.2.11. This field shall specify information about a particular
@@ -23,8 +23,8 @@ class EmitterSystem {
EmitterSystem();
~EmitterSystem() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] uint16_t GetEmitterName() const;
void SetEmitterName(uint16_t value);
diff --git a/src/libsersi/common/EntityID.h b/include/common/data_types/EntityID.hpp
similarity index 88%
rename from src/libsersi/common/EntityID.h
rename to include/common/data_types/EntityID.hpp
index f3cda0d..6806267 100644
--- a/src/libsersi/common/EntityID.h
+++ b/include/common/data_types/EntityID.hpp
@@ -1,6 +1,7 @@
#pragma once
-#include "libsersi/utils/DataStream.h"
+#include "utils/ByteBuffer.hpp"
+#include "common/Result.hpp"
namespace dis {
// Each entity in a given DIS simulation application shall be given an entity
@@ -33,8 +34,8 @@ class EntityID {
EntityID();
virtual ~EntityID();
- virtual void Marshal(DataStream& data_stream) const;
- virtual void Unmarshal(DataStream& data_stream);
+ virtual Result Marshal(ByteBuffer& byte_buffer) const;
+ virtual Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] uint16_t GetSite() const;
void SetSite(uint16_t value);
@@ -50,4 +51,3 @@ class EntityID {
bool operator==(const EntityID& rhs) const;
};
} // namespace dis
-
diff --git a/src/libsersi/common/EntityType.h b/include/common/data_types/EntityType.hpp
similarity index 87%
rename from src/libsersi/common/EntityType.h
rename to include/common/data_types/EntityType.hpp
index 11dc08c..59c9ba9 100644
--- a/src/libsersi/common/EntityType.h
+++ b/include/common/data_types/EntityType.hpp
@@ -2,7 +2,8 @@
#include
-#include "libsersi/utils/DataStream.h"
+#include "utils/ByteBuffer.hpp"
+#include "common/Result.hpp"
namespace dis {
// Section 5.2.16. Identifies the type of entity, including kind of entity,
@@ -34,8 +35,8 @@ class EntityType {
EntityType();
~EntityType() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] uint8_t GetEntityKind() const;
void SetEntityKind(uint8_t value);
diff --git a/src/libsersi/common/EventID.h b/include/common/data_types/EventID.hpp
similarity index 78%
rename from src/libsersi/common/EventID.h
rename to include/common/data_types/EventID.hpp
index 1c7966f..4bbca9a 100644
--- a/src/libsersi/common/EventID.h
+++ b/include/common/data_types/EventID.hpp
@@ -2,7 +2,8 @@
#include
-#include "libsersi/utils/DataStream.h"
+#include "utils/ByteBuffer.hpp"
+#include "common/Result.hpp"
namespace dis {
// Section 5.2.18. Identifies a unique event in a simulation via the combination
@@ -23,8 +24,8 @@ class EventID {
EventID();
~EventID() = default;
- void Marshal(dis::DataStream& data_stream) const;
- void Unmarshal(dis::DataStream& data_stream);
+ Result Marshal(dis::ByteBuffer& byte_buffer) const;
+ Result Unmarshal(dis::ByteBuffer& byte_buffer);
[[nodiscard]] uint16_t GetSite() const;
void SetSite(uint16_t value);
diff --git a/src/libsersi/common/FixedDatum.h b/include/common/data_types/FixedDatum.hpp
similarity index 74%
rename from src/libsersi/common/FixedDatum.h
rename to include/common/data_types/FixedDatum.hpp
index 2019049..4297e5e 100644
--- a/src/libsersi/common/FixedDatum.h
+++ b/include/common/data_types/FixedDatum.hpp
@@ -1,6 +1,7 @@
#pragma once
-#include "libsersi/utils/DataStream.h"
+#include "utils/ByteBuffer.hpp"
+#include "common/Result.hpp"
namespace dis {
// Section 5.2.18. Fixed Datum Record
@@ -17,8 +18,8 @@ class FixedDatum {
FixedDatum();
~FixedDatum() = default;
- void Marshal(dis::DataStream& data_stream) const;
- void Unmarshal(dis::DataStream& data_stream);
+ Result Marshal(dis::ByteBuffer& byte_buffer) const;
+ Result Unmarshal(dis::ByteBuffer& byte_buffer);
[[nodiscard]] uint32_t GetFixedDatumId() const;
void SetFixedDatumId(uint32_t value);
diff --git a/src/libsersi/distributed_emissions/FundamentalParameterData.h b/include/common/data_types/FundamentalParameterData.h
similarity index 94%
rename from src/libsersi/distributed_emissions/FundamentalParameterData.h
rename to include/common/data_types/FundamentalParameterData.h
index a054936..72d2cd3 100644
--- a/src/libsersi/distributed_emissions/FundamentalParameterData.h
+++ b/include/common/data_types/FundamentalParameterData.h
@@ -1,6 +1,6 @@
#pragma once
-#include "libsersi/utils/DataStream.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// Section 5.2.22. Contains electromagnetic emmision regineratin parameters that
@@ -48,8 +48,8 @@ class FundamentalParameterData {
FundamentalParameterData();
~FundamentalParameterData() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] float GetFrequency() const;
void SetFrequency(float value);
diff --git a/src/libsersi/distributed_emissions/FundamentalParameterDataIff.h b/include/common/data_types/FundamentalParameterDataIff.h
similarity index 88%
rename from src/libsersi/distributed_emissions/FundamentalParameterDataIff.h
rename to include/common/data_types/FundamentalParameterDataIff.h
index eca6ea8..b23d399 100644
--- a/src/libsersi/distributed_emissions/FundamentalParameterDataIff.h
+++ b/include/common/data_types/FundamentalParameterDataIff.h
@@ -1,6 +1,6 @@
#pragma once
-#include "libsersi/utils/DataStream.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// 5.2.45. Fundamental IFF atc data
@@ -35,8 +35,8 @@ class FundamentalParameterDataIff {
FundamentalParameterDataIff();
~FundamentalParameterDataIff() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] float GetErp() const;
void SetErp(float value);
diff --git a/src/libsersi/distributed_emissions/IffAtcNavAidsLayer1Pdu.h b/include/common/data_types/IffAtcNavAidsLayer1Pdu.h
similarity index 79%
rename from src/libsersi/distributed_emissions/IffAtcNavAidsLayer1Pdu.h
rename to include/common/data_types/IffAtcNavAidsLayer1Pdu.h
index 07dc7d0..1d5e099 100644
--- a/src/libsersi/distributed_emissions/IffAtcNavAidsLayer1Pdu.h
+++ b/include/common/data_types/IffAtcNavAidsLayer1Pdu.h
@@ -1,12 +1,12 @@
#pragma once
-#include "libsersi/common/EntityID.h"
-#include "libsersi/common/EventID.h"
-#include "libsersi/common/Vector3Float.h"
-#include "libsersi/distributed_emissions/DistributedEmissionsFamilyPdu.h"
-#include "libsersi/distributed_emissions/IffFundamentalData.h"
-#include "libsersi/distributed_emissions/SystemID.h"
-#include "libsersi/utils/DataStream.h"
+#include common/EntityID.h"
+#include common/EventID.h"
+#include common/Vector3Float.h"
+#include distributed_emissions/DistributedEmissionsFamilyPdu.h"
+#include distributed_emissions/IffFundamentalData.h"
+#include distributed_emissions/SystemID.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// 5.3.7.4.1: Navigational and IFF PDU. COMPLETE
@@ -36,8 +36,8 @@ class IffAtcNavAidsLayer1Pdu : public DistributedEmissionsFamilyPdu {
IffAtcNavAidsLayer1Pdu();
~IffAtcNavAidsLayer1Pdu() override = default;
- void Marshal(DataStream& data_stream) const override;
- void Unmarshal(DataStream& data_stream) override;
+ Result Marshal(ByteBuffer& byte_buffer) const override;
+ Result Unmarshal(ByteBuffer& byte_buffer) override;
EntityID& GetEmittingEntityId();
[[nodiscard]] const EntityID& GetEmittingEntityId() const;
diff --git a/src/libsersi/distributed_emissions/IffAtcNavAidsLayer2Pdu.h b/include/common/data_types/IffAtcNavAidsLayer2Pdu.h
similarity index 80%
rename from src/libsersi/distributed_emissions/IffAtcNavAidsLayer2Pdu.h
rename to include/common/data_types/IffAtcNavAidsLayer2Pdu.h
index 6c7f078..c1b2c41 100644
--- a/src/libsersi/distributed_emissions/IffAtcNavAidsLayer2Pdu.h
+++ b/include/common/data_types/IffAtcNavAidsLayer2Pdu.h
@@ -2,11 +2,11 @@
#include
-#include "libsersi/distributed_emissions/BeamData.h"
-#include "libsersi/distributed_emissions/FundamentalParameterDataIff.h"
-#include "libsersi/distributed_emissions/IffAtcNavAidsLayer1Pdu.h"
-#include "libsersi/distributed_emissions/LayerHeader.h"
-#include "libsersi/utils/DataStream.h"
+#include distributed_emissions/BeamData.h"
+#include distributed_emissions/FundamentalParameterDataIff.h"
+#include distributed_emissions/IffAtcNavAidsLayer1Pdu.h"
+#include distributed_emissions/LayerHeader.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// Section 5.3.7.4.2 When present, layer 2 should follow layer 1 and have the
@@ -30,8 +30,8 @@ class IffAtcNavAidsLayer2Pdu final : public IffAtcNavAidsLayer1Pdu {
public:
IffAtcNavAidsLayer2Pdu() = default;
~IffAtcNavAidsLayer2Pdu() final;
- void Marshal(DataStream& data_stream) const final;
- void Unmarshal(DataStream& data_stream) final;
+ Result Marshal(ByteBuffer& byte_buffer) const final;
+ Result Unmarshal(ByteBuffer& byte_buffer) final;
LayerHeader& GetLayerHeader();
[[nodiscard]] const LayerHeader& GetLayerHeader() const;
diff --git a/src/libsersi/distributed_emissions/IffFundamentalData.h b/include/common/data_types/IffFundamentalData.h
similarity index 91%
rename from src/libsersi/distributed_emissions/IffFundamentalData.h
rename to include/common/data_types/IffFundamentalData.h
index 49afd28..14a872e 100644
--- a/src/libsersi/distributed_emissions/IffFundamentalData.h
+++ b/include/common/data_types/IffFundamentalData.h
@@ -1,6 +1,6 @@
#pragma once
-#include "libsersi/utils/DataStream.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// 5.2.42. Basic operational data ofr IFF ATC NAVAIDS
@@ -41,8 +41,8 @@ class IffFundamentalData {
IffFundamentalData();
~IffFundamentalData() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] uint8_t GetSystemStatus() const;
void SetSystemStatus(uint8_t value);
diff --git a/src/libsersi/distributed_emissions/LayerHeader.h b/include/common/data_types/LayerHeader.h
similarity index 82%
rename from src/libsersi/distributed_emissions/LayerHeader.h
rename to include/common/data_types/LayerHeader.h
index a1794ba..1db63e2 100644
--- a/src/libsersi/distributed_emissions/LayerHeader.h
+++ b/include/common/data_types/LayerHeader.h
@@ -2,7 +2,7 @@
#include
-#include "libsersi/utils/DataStream.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// 5.2.47. Layer header.
@@ -22,8 +22,8 @@ class LayerHeader {
LayerHeader();
~LayerHeader() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] uint8_t GetLayerNumber() const;
void SetLayerNumber(uint8_t value);
diff --git a/src/libsersi/common/Orientation.h b/include/common/data_types/Orientation.hpp
similarity index 77%
rename from src/libsersi/common/Orientation.h
rename to include/common/data_types/Orientation.hpp
index 0c12957..66bbb51 100644
--- a/src/libsersi/common/Orientation.h
+++ b/include/common/data_types/Orientation.hpp
@@ -2,7 +2,8 @@
#include
-#include "libsersi/utils/DataStream.h"
+#include "utils/ByteBuffer.hpp"
+#include "common/Result.hpp"
namespace dis {
// Section 5.2.17. Three floating point values representing an orientation, psi,
@@ -20,8 +21,8 @@ class Orientation {
Orientation();
~Orientation() = default;
- void Marshal(dis::DataStream& data_stream) const;
- void Unmarshal(dis::DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] float GetPsi() const;
void SetPsi(float value);
diff --git a/src/libsersi/distributed_emissions/PropulsionSystemData.h b/include/common/data_types/PropulsionSystemData.h
similarity index 78%
rename from src/libsersi/distributed_emissions/PropulsionSystemData.h
rename to include/common/data_types/PropulsionSystemData.h
index a716dce..179d177 100644
--- a/src/libsersi/distributed_emissions/PropulsionSystemData.h
+++ b/include/common/data_types/PropulsionSystemData.h
@@ -2,7 +2,7 @@
#include
-#include "libsersi/utils/DataStream.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// Data about a propulsion system
@@ -19,8 +19,8 @@ class PropulsionSystemData {
PropulsionSystemData();
~PropulsionSystemData() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] float GetPowerSetting() const;
void SetPowerSetting(float value);
diff --git a/src/libsersi/distributed_emissions/ShaftRPMs.h b/include/common/data_types/ShaftRPMs.h
similarity index 83%
rename from src/libsersi/distributed_emissions/ShaftRPMs.h
rename to include/common/data_types/ShaftRPMs.h
index 79ebe37..3d95ffc 100644
--- a/src/libsersi/distributed_emissions/ShaftRPMs.h
+++ b/include/common/data_types/ShaftRPMs.h
@@ -2,7 +2,7 @@
#include
-#include "libsersi/utils/DataStream.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// Shaft RPMs, used in underwater acoustic clacluations.
@@ -22,8 +22,8 @@ class ShaftRPMs {
ShaftRPMs();
~ShaftRPMs() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] int16_t GetCurrentShaftRPMs() const;
void SetCurrentShaftRPMs(int16_t value);
diff --git a/src/libsersi/common/SimulationAddress.h b/include/common/data_types/SimulationAddress.hpp
similarity index 77%
rename from src/libsersi/common/SimulationAddress.h
rename to include/common/data_types/SimulationAddress.hpp
index 0ba8a0a..f714446 100644
--- a/src/libsersi/common/SimulationAddress.h
+++ b/include/common/data_types/SimulationAddress.hpp
@@ -2,7 +2,8 @@
#include
-#include "libsersi/utils/DataStream.h"
+#include "utils/ByteBuffer.hpp"
+#include "common/Result.hpp"
namespace dis {
// Section 5.2.14.1. A Simulation Address record shall consist of the Site
@@ -20,8 +21,8 @@ class SimulationAddress {
SimulationAddress();
~SimulationAddress() = default;
- void Marshal(dis::DataStream& data_stream) const;
- void Unmarshal(dis::DataStream& data_stream);
+ Result Marshal(dis::ByteBuffer& byte_buffer) const;
+ Result Unmarshal(dis::ByteBuffer& byte_buffer);
[[nodiscard]] uint16_t GetSite() const;
void SetSite(uint16_t value);
diff --git a/src/libsersi/distributed_emissions/SystemID.h b/include/common/data_types/SystemID.h
similarity index 83%
rename from src/libsersi/distributed_emissions/SystemID.h
rename to include/common/data_types/SystemID.h
index 173c7d0..024aa43 100644
--- a/src/libsersi/distributed_emissions/SystemID.h
+++ b/include/common/data_types/SystemID.h
@@ -2,7 +2,7 @@
#include
-#include "libsersi/utils/DataStream.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// 5.2.58. Used in IFF ATC PDU
@@ -25,8 +25,8 @@ class SystemID {
SystemID();
~SystemID() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] uint16_t GetSystemType() const;
void SetSystemType(uint16_t value);
diff --git a/src/libsersi/distributed_emissions/TrackJamTarget.h b/include/common/data_types/TrackJamTarget.h
similarity index 79%
rename from src/libsersi/distributed_emissions/TrackJamTarget.h
rename to include/common/data_types/TrackJamTarget.h
index 0036d37..5d89c69 100644
--- a/src/libsersi/distributed_emissions/TrackJamTarget.h
+++ b/include/common/data_types/TrackJamTarget.h
@@ -2,8 +2,8 @@
#include
-#include "libsersi/common/EntityID.h"
-#include "libsersi/utils/DataStream.h"
+#include common/EntityID.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// One track/jam target
@@ -23,8 +23,8 @@ class TrackJamTarget {
TrackJamTarget();
~TrackJamTarget() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
EntityID& GetTrackJam();
[[nodiscard]] const EntityID& GetTrackJam() const;
diff --git a/src/libsersi/common/VariableDatum.h b/include/common/data_types/VariableDatum.hpp
similarity index 81%
rename from src/libsersi/common/VariableDatum.h
rename to include/common/data_types/VariableDatum.hpp
index b936a25..03fc22b 100644
--- a/src/libsersi/common/VariableDatum.h
+++ b/include/common/data_types/VariableDatum.hpp
@@ -2,8 +2,11 @@
#include
#include
+#include
+#include
-#include "libsersi/utils/DataStream.h"
+#include "utils/ByteBuffer.hpp"
+#include "common/Result.hpp"
// length in bytes for the variable data. This should be a dynamically allocated
// array.
@@ -28,8 +31,8 @@ class VariableDatum {
VariableDatum();
~VariableDatum();
- void Marshal(dis::DataStream& data_stream) const;
- void Unmarshal(dis::DataStream& data_stream);
+ Result Marshal(dis::ByteBuffer& byte_buffer) const;
+ Result Unmarshal(dis::ByteBuffer& byte_buffer);
[[nodiscard]] uint32_t GetVariableDatumId() const;
void SetVariableDatumId(uint32_t value);
diff --git a/src/libsersi/common/Vector3Double.h b/include/common/data_types/Vector3Double.h
similarity index 71%
rename from src/libsersi/common/Vector3Double.h
rename to include/common/data_types/Vector3Double.h
index bca0b2a..d46f4b6 100644
--- a/src/libsersi/common/Vector3Double.h
+++ b/include/common/data_types/Vector3Double.h
@@ -1,7 +1,7 @@
-#ifndef LIBSERSI_COMMON_VECTOR3DOUBLE_H_
-#define LIBSERSI_COMMON_VECTOR3DOUBLE_H_
+#pragma once
-#include "libsersi/utils/DataStream.h"
+#include "utils/ByteBuffer.hpp"
+#include "common/Result.hpp"
namespace dis {
// Section 5.3.34. Three double precision floating point values, x, y, and z
@@ -21,8 +21,8 @@ class Vector3Double {
Vector3Double();
~Vector3Double() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] double GetX() const;
void SetX(double value);
@@ -38,6 +38,3 @@ class Vector3Double {
bool operator==(const Vector3Double& rhs) const;
};
} // namespace dis
-
-#endif // LIBSERSI_COMMON_VECTOR3DOUBLE_H_
-
diff --git a/src/libsersi/common/Vector3Float.h b/include/common/data_types/Vector3Float.h
similarity index 75%
rename from src/libsersi/common/Vector3Float.h
rename to include/common/data_types/Vector3Float.h
index b7b24d9..3f97760 100644
--- a/src/libsersi/common/Vector3Float.h
+++ b/include/common/data_types/Vector3Float.h
@@ -1,6 +1,7 @@
#pragma once
-#include "libsersi/utils/DataStream.h"
+#include "utils/ByteBuffer.hpp"
+#include "common/Result.hpp"
namespace dis {
// Section 5.2.33. Three floating point values, x, y, and z
@@ -20,8 +21,8 @@ class Vector3Float {
Vector3Float();
~Vector3Float() = default;
- void Marshal(dis::DataStream& data_stream) const;
- void Unmarshal(dis::DataStream& data_stream);
+ Result Marshal(dis::ByteBuffer& byte_buffer) const;
+ Result Unmarshal(dis::ByteBuffer& byte_buffer);
[[nodiscard]] float GetX() const;
void SetX(float value);
@@ -37,4 +38,3 @@ class Vector3Float {
bool operator==(const Vector3Float& rhs) const;
};
} // namespace dis
-
diff --git a/src/libsersi/distributed_emissions/VectoringNozzleSystemData.h b/include/common/data_types/VectoringNozzleSystemData.h
similarity index 81%
rename from src/libsersi/distributed_emissions/VectoringNozzleSystemData.h
rename to include/common/data_types/VectoringNozzleSystemData.h
index f891b8d..e1e69bd 100644
--- a/src/libsersi/distributed_emissions/VectoringNozzleSystemData.h
+++ b/include/common/data_types/VectoringNozzleSystemData.h
@@ -2,7 +2,7 @@
#include
-#include "libsersi/utils/DataStream.h"
+#include utils/ByteBuffer.hpp"
namespace dis {
// Data about a vectoring nozzle system
@@ -19,8 +19,8 @@ class VectoringNozzleSystemData {
VectoringNozzleSystemData();
~VectoringNozzleSystemData() = default;
- void Marshal(DataStream& data_stream) const;
- void Unmarshal(DataStream& data_stream);
+ Result Marshal(ByteBuffer& byte_buffer) const;
+ Result Unmarshal(ByteBuffer& byte_buffer);
[[nodiscard]] float GetHorizontalDeflectionAngle() const;
void SetHorizontalDeflectionAngle(float value);
diff --git a/include/common/enums.hpp b/include/common/enums.hpp
new file mode 100644
index 0000000..752da82
--- /dev/null
+++ b/include/common/enums.hpp
@@ -0,0 +1,110 @@
+#pragma once
+
+#include
+
+/// SISO-REF-010-2023 Protocol Version [UID 3]
+enum class ProtocolVersion : uint8_t {
+ Other = 0,
+ DIS_PDUv1 = 1,
+ IEEE1278_1993 = 2,
+ DIS_PDUv2_Third_Draft = 3,
+ DIS_PDUv2_Fourth_Draft_Revised = 4,
+ IEEE1278_1_1995 = 5,
+ IEEE1278_1A_1998 = 6,
+ IEEE1278_1_2012 = 7,
+};
+
+/// SISO-REF-010-2023 PDU Type [UID 4]
+enum class PduType : uint8_t {
+ Other = 0,
+ EntityState = 1,
+ Fire = 2,
+ Detonation = 3,
+ Collision = 4,
+ ServiceRequest = 5,
+ ResupplyOffer = 6,
+ ResupplyReceived = 7,
+ ResupplyCancel = 8,
+ RepairComplete = 9,
+ RepairResponse = 10,
+ CreateEntity = 11,
+ RemoveEntity = 12,
+ StartResume = 13,
+ StopFreeze = 14,
+ Acknowledge = 15,
+ ActionRequest = 16,
+ ActionResponse = 17,
+ DataQuery = 18,
+ SetData = 19,
+ Data = 20,
+ EventReport = 21,
+ Comment = 22,
+ ElectromagneticEmission = 23,
+ Designator = 24,
+ Transmitter = 25,
+ Signal = 26,
+ Receiver = 27,
+ IFF = 28,
+ UnderwaterAcoustic = 29,
+ SupplementalEmission = 30,
+ IntercomSignal = 31,
+ IntercomControl = 32,
+ AggregateState = 33,
+ IsGroupOf = 34,
+ TransferOwnership = 35,
+ IsPartOf = 36,
+ MinefieldState = 37,
+ MinefieldQuery = 38,
+ MinefieldData = 39,
+ MinefieldResponseNack = 40,
+ EnvironmentalProcess = 41,
+ GriddedData = 42,
+ PointObjectState = 43,
+ LinearObjectState = 44,
+ ArealObjectState = 45,
+ TimeSpacePositionInformation = 46,
+ Appearance = 47,
+ ArticulatedParts = 48,
+ LiveEntityFire = 49,
+ LiveEntityDetonation = 50,
+ CreateEntityReliable = 51,
+ RemoveEntityReliable = 52,
+ StartResumeReliable = 53,
+ StopFreezeReliable = 54,
+ AcknowledgeReliable = 55,
+ ActionRequestReliable = 56,
+ ActionResponseReliable = 57,
+ DataQueryReliable = 58,
+ SetDataReliable = 59,
+ DataReliable = 60,
+ EventReportReliable = 61,
+ CommentReliable = 62,
+ RecordReliable = 63,
+ SetRecordReliable = 64,
+ RecordQueryReliable = 65,
+ CollisionElastic = 66,
+ EntityStateUpdate = 67,
+ DirectedEnergyFire = 68,
+ EntityDamageStatus = 69,
+ InformationOperationsAction = 70,
+ InformationOperationsReport = 71,
+ Attribute = 72,
+};
+
+/// SISO-REF-010-2023 Protocol Family [UID 5]
+enum class ProtocolFamily : uint8_t {
+ Other = 0,
+ EntityInformation = 1,
+ Warfare = 2,
+ Logistics = 3,
+ RadioCommunications = 4,
+ SimulationManagement = 5,
+ DistributedEmissionRegeneration = 6,
+ EntityManagement = 7,
+ Minefield = 8,
+ SyntheticEnvironment = 9,
+ SimulationManagementWithReliability = 10,
+ LiveEntityInformationInteraction = 11,
+ NonRealTime = 12,
+ InformationOperations = 13,
+};
diff --git a/src/libsersi/utils/DataStream.h b/include/utils/ByteBuffer.hpp
similarity index 68%
rename from src/libsersi/utils/DataStream.h
rename to include/utils/ByteBuffer.hpp
index 7a80115..4271352 100644
--- a/src/libsersi/utils/DataStream.h
+++ b/include/utils/ByteBuffer.hpp
@@ -1,31 +1,30 @@
-#ifndef LIBSERSI_UTILS_DATASTREAM_H_
-#define LIBSERSI_UTILS_DATASTREAM_H_
+#pragma once
+#include
#include
#include // for std::size_t and NULL definition
#include // for memcpy
-#include // for typedef, member
#include // for typedef, member
-#include "libsersi/utils/Endian.h" // for enum
+#include "utils/Endian.hpp" // for enum
namespace dis {
/// a class to support managing a network buffer.
/// the clients are responsible for managing the char buffer memory.
/// this class explicitly defines operators for expected types.
-class DataStream {
+class ByteBuffer {
public:
/// Setup the internal buffer's Endian type.
/// @param stream the Endian type to use for the internal buffer,
/// which will be used for network socket writes.
- explicit DataStream(Endian stream);
+ explicit ByteBuffer(Endian stream);
/// Setup the internal buffer.
/// @param buffer the data to copy and manage.
/// @param length the number of bytes in the buffer.
/// @param stream the Endian type to use for the internal buffer,
- DataStream(const char* buffer, std::size_t length, Endian stream);
- ~DataStream() = default;
+ ByteBuffer(const char* buffer, std::size_t length, Endian stream);
+ ~ByteBuffer() = default;
/// a method for reading the stored buffer data.
/// @param offset the index distance with respect to the current read point.
@@ -35,30 +34,30 @@ class DataStream {
void SetStream(const char* buffer, std::size_t length, Endian order);
// write operations
- DataStream& operator<<(bool b);
- DataStream& operator<<(char c);
- DataStream& operator<<(uint8_t c);
- DataStream& operator<<(float f);
- DataStream& operator<<(double d);
- DataStream& operator<<(int d);
- DataStream& operator<<(uint32_t d);
- DataStream& operator<<(int64_t d);
- DataStream& operator<<(uint64_t d);
- DataStream& operator<<(uint16_t d);
- DataStream& operator<<(int16_t d);
+ ByteBuffer& operator<<(bool b);
+ ByteBuffer& operator<<(char c);
+ ByteBuffer& operator<<(uint8_t c);
+ ByteBuffer& operator<<(float f);
+ ByteBuffer& operator<<(double d);
+ ByteBuffer& operator<<(int d);
+ ByteBuffer& operator<<(uint32_t d);
+ ByteBuffer& operator<<(int64_t d);
+ ByteBuffer& operator<<(uint64_t d);
+ ByteBuffer& operator<<(uint16_t d);
+ ByteBuffer& operator<<(int16_t d);
// read operations
- DataStream& operator>>(bool& b);
- DataStream& operator>>(char& c);
- DataStream& operator>>(uint8_t& c);
- DataStream& operator>>(float& f);
- DataStream& operator>>(double& d);
- DataStream& operator>>(int& d);
- DataStream& operator>>(uint32_t& d);
- DataStream& operator>>(int64_t& d);
- DataStream& operator>>(uint64_t& d);
- DataStream& operator>>(uint16_t& d);
- DataStream& operator>>(int16_t& d);
+ ByteBuffer& operator>>(bool& b);
+ ByteBuffer& operator>>(char& c);
+ ByteBuffer& operator>>(uint8_t& c);
+ ByteBuffer& operator>>(float& f);
+ ByteBuffer& operator>>(double& d);
+ ByteBuffer& operator>>(int& d);
+ ByteBuffer& operator>>(uint32_t& d);
+ ByteBuffer& operator>>(int64_t& d);
+ ByteBuffer& operator>>(uint64_t& d);
+ ByteBuffer& operator>>(uint16_t& d);
+ ByteBuffer& operator>>(int16_t& d);
[[nodiscard]] Endian GetStreamEndian() const;
[[nodiscard]] Endian GetMachineEndian() const;
@@ -97,10 +96,10 @@ class DataStream {
/// because the class size takes into account the virtual function table.
template
void ReadAlgorithm(T& t) {
- char ch[sizeof(T)];
- DoRead(ch, sizeof(T));
- DoFlip(ch, sizeof(T));
- memcpy(&t, ch, sizeof(t));
+ std::array ch;
+ DoRead(ch.data(), sizeof(T));
+ DoFlip(ch.data(), sizeof(T));
+ memcpy(&t, ch.data(), sizeof(t));
IncrementPointer(read_pos_);
}
@@ -127,5 +126,3 @@ class DataStream {
Endian machine_endian_;
};
} // namespace dis
-
-#endif // LIBSERSI_UTILS_DATASTREAM_H_
diff --git a/src/libsersi/utils/Conversion.h b/include/utils/Conversion.hpp
similarity index 100%
rename from src/libsersi/utils/Conversion.h
rename to include/utils/Conversion.hpp
diff --git a/include/utils/Endian.hpp b/include/utils/Endian.hpp
new file mode 100644
index 0000000..3b39ccc
--- /dev/null
+++ b/include/utils/Endian.hpp
@@ -0,0 +1,12 @@
+#pragma once
+
+#include
+
+namespace dis {
+/// the order of bytes that are on the left
+enum class Endian : uint8_t {
+ kLittle = 1,
+ kBig = 0,
+};
+
+} // namespace dis
diff --git a/src/libsersi/utils/IBufferProcessor.h b/include/utils/IBufferProcessor.hpp
similarity index 91%
rename from src/libsersi/utils/IBufferProcessor.h
rename to include/utils/IBufferProcessor.hpp
index a1d0463..64b0261 100644
--- a/src/libsersi/utils/IBufferProcessor.h
+++ b/include/utils/IBufferProcessor.hpp
@@ -3,7 +3,7 @@
#include
-#include "libsersi/utils/Endian.h"
+#include utils/Endian.h"
namespace dis {
/// the interface class for handling read operations.
diff --git a/src/libsersi/utils/IPacketProcessor.h b/include/utils/IPacketProcessor.hpp
similarity index 100%
rename from src/libsersi/utils/IPacketProcessor.h
rename to include/utils/IPacketProcessor.hpp
diff --git a/src/libsersi/utils/IPduBank.h b/include/utils/IPduBank.hpp
similarity index 74%
rename from src/libsersi/utils/IPduBank.h
rename to include/utils/IPduBank.hpp
index 39bdb95..f003c2d 100644
--- a/src/libsersi/utils/IPduBank.h
+++ b/include/utils/IPduBank.hpp
@@ -1,7 +1,7 @@
#pragma once
-#include "libsersi/common/Pdu.h"
-#include "libsersi/utils/DataStream.h"
+#include common/Pdu.hpp"
+#include utils/ByteBuffer.hpp"
namespace dis {
/// houses instances for the set of known PDU classes to be returned
@@ -13,6 +13,6 @@ class IPduBank {
/// finds the PDU instance corresponding to the identifier
/// @param pdu_type the 8-bit PDU type identifier
/// @return NULL when the pdu_type is unknown.
- virtual Pdu* GetStaticPDU(uint8_t pdu_type, DataStream& ds) = 0;
+ virtual Pdu* GetStaticPDU(uint8_t pdu_type, ByteBuffer& ds) = 0;
};
} // namespace dis
diff --git a/src/libsersi/utils/IncomingMessage.h b/include/utils/IncomingMessage.hpp
similarity index 89%
rename from src/libsersi/utils/IncomingMessage.h
rename to include/utils/IncomingMessage.hpp
index 416d428..4777def 100644
--- a/src/libsersi/utils/IncomingMessage.h
+++ b/include/utils/IncomingMessage.hpp
@@ -3,15 +3,15 @@
#include