// // Data.hpp // Clock Signal // // Created by Thomas Harte on 04/03/2026. // Copyright © 2026 Thomas Harte. All rights reserved. // #pragma once #include namespace Bus::Data { /// A value that can be read from or written to, without effect. template struct NoValue { operator DataT() const { return DataT(~0); } NoValue() = default; constexpr NoValue(DataT) noexcept {} }; /// A value that can be written only, not read. With a DEBUG build test that it is written before it is read. template class Writeable { public: DataT operator=(const DataT value) { if constexpr (VerifyWrites) { #ifndef NDEBUG did_write_ = true; #endif } return result_ = value; } operator DataT() const { if constexpr (VerifyWrites) { assert(did_write_); } return result_; } private: DataT result_; #ifndef NDEBUG bool did_write_ = false; #endif }; enum class AccessType { Read, Write, NoData }; template struct Value; template struct Value { using type = Writeable &; }; template struct Value { using type = const DataT; }; template struct Value { using type = const NoValue; }; template using data_t = typename Data::Value::type; } // namespace Bus::Data