fprime/TestUtils/OnChangeChannel.hpp
Rob Bocchino b89b5d91c4
Add DpWriter (#2593)
* Pull in framework changes from data-products branch

* Pull in changes to DpManager from data-products branch

* Pull in DpWriter from data-products branch

* Fix spelling

* Revise FileNameString

* Fix warnings in CI

* Fix static analysis warnings

* Fix static analysis warnings

* Revise formatting and comments

* Revise banner comments

* Revise FileNameString per PR comment

* Revise path names in config headers

If a header H.hpp exists in the F Prime source base, then

is dangerous. Because [project root] and [fprime root] are both
in the list of include paths, it's not clear whether this means "include
[project root]/config/H.hpp" or "include [fprime root]/config/H.hpp."

On the other hand,

or

has no such ambiguity, because only one of [project root]/config
and [fprime root]/config is in the list of include paths.

* Revise path names in config headers

If a header H.hpp exists in the F Prime source base, then

`#include "config/H.hpp"`

is dangerous. Because [project root] and [fprime root] are both
in the list of include paths, it's not clear whether this means "include
[project root]/config/H.hpp" or "include [fprime root]/config/H.hpp."

On the other hand,

include <config/H.hpp>

or

`#include "config/H.hpp"`

has no such ambiguity, because only one of [project root]/config
and [fprime root]/config is in the list of include paths.
2024-03-28 16:09:38 -07:00

53 lines
1.5 KiB
C++

// ======================================================================
// \title OnChangeChannel.hpp
// \author Rob Bocchino
// \brief A model of an on-change channel for testing
//
// \copyright
// Copyright (C) 2023 California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged. Any commercial use must be negotiated with the Office
// of Technology Transfer at the California Institute of Technology.
// ======================================================================
#ifndef TestUtils_OnChangeChannel_HPP
#define TestUtils_OnChangeChannel_HPP
#include <FpConfig.hpp>
#include <cstring>
#include "TestUtils/Option.hpp"
namespace TestUtils {
//! The status of an on-change telemetry channel
enum class OnChangeStatus { CHANGED, NOT_CHANGED };
//! A model of an on-change telemetry channel
template <typename T>
class OnChangeChannel {
public:
//! Constructor
explicit OnChangeChannel(T value) : value(value) {}
//! Update the previous value
OnChangeStatus updatePrev() {
const auto status = ((!this->prev.hasValue()) || (this->value != this->prev.get()))
? OnChangeStatus::CHANGED
: OnChangeStatus::NOT_CHANGED;
this->prev.set(this->value);
return status;
}
public:
//! The current value
T value;
private:
//! The previous value
Option<T> prev;
};
} // namespace TestUtils
#endif