flatten 20260225

This commit is contained in:
Timothy Prepscius
2026-02-25 12:39:24 -05:00
commit fa54be052a
315 changed files with 49791 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
// TJP COPYRIGHT HEADER
#include "GlobalResourceVersion+IO.inl"
#include <iostream>
namespace tjp {
namespace core {
std::ostream &operator <<(std::ostream &o, const GlobalResourceVersion &v)
{
return o << v.value;
}
} // namespace
} // namespace

View File

@@ -0,0 +1,21 @@
// TJP COPYRIGHT HEADER
#pragma once
#include "GlobalResourceVersion.hpp"
#include <iosfwd>
namespace tjp {
namespace core {
template<typename IO>
inline void io_(IO &io, GlobalResourceVersion &v)
{
io.any(v.value);
}
std::ostream &operator <<(std::ostream &o, const GlobalResourceVersion &v);
} // namespace
} // namespace

View File

@@ -0,0 +1,21 @@
// TJP COPYRIGHT HEADER
#include "GlobalResourceVersion.hpp"
#include "../random/Random.h"
#include <tjp/core/log/Log.h>
namespace tjp {
namespace core {
const GlobalResourceVersion GlobalResourceVersion::Null;
std::atomic<u64> GlobalResourceVersion::nextValue = 0;
void GlobalResourceVersion::increment ()
{
value = ++nextValue;
}
} // namespace
} // namespace

View File

@@ -0,0 +1,15 @@
// TJP COPYRIGHT HEADER
#pragma once
namespace tjp::core {
struct GlobalResourceVersion;
bool operator ==(const GlobalResourceVersion &lhs, const GlobalResourceVersion &rhs);
bool operator !=(const GlobalResourceVersion &lhs, const GlobalResourceVersion &rhs);
bool operator <(const GlobalResourceVersion &lhs, const GlobalResourceVersion &rhs);
bool operator >=(const GlobalResourceVersion &lhs, const GlobalResourceVersion &rhs);
bool operator >(const GlobalResourceVersion &lhs, const GlobalResourceVersion &rhs);
} // namespace

View File

@@ -0,0 +1,162 @@
// TJP COPYRIGHT HEADER
#pragma once
#include "GlobalResourceVersion.h"
#include <atomic>
#include <tjp/core/types/Types.h>
#include <tjp/core/containers/Tuple.h>
#include "../algorithm/for_each_argument.hpp"
#include <tjp/core/algorithm/tuple_has_value.hpp>
namespace tjp::core {
struct GlobalResourceVersion
{
using Type = u64;
using Self = GlobalResourceVersion;
static std::atomic<Type> nextValue;
static const Self Null;
Type value = 0;
void increment ();
void clear()
{
value = 0;
}
bool empty() const
{
return value == 0;
}
Self &operator ++()
{
increment();
return *this;
}
// post increment
Self operator ++(int)
{
Self result { value };
increment();
return result;
}
static Self next ()
{
Self result;
++result;
return result;
}
static bool shouldUpdate (Type &value, Type rhs)
{
return value < rhs;
}
bool shouldUpdate (const Self &rhs)
{
return value < rhs.value;
}
static bool update (Type &value, Type rhs)
{
auto updated = shouldUpdate(value, rhs);
if (updated)
value = rhs;
return updated;
}
template<typename ... Args>
auto as_tuple (Args ... args)
{
return std::tuple_cat(std::forward<Args>(args)...);
}
template<typename ... Args>
auto updates (Args&& ... args)
{
auto result = std::make_tuple(shouldUpdate(args)...);
// for_each_argument(update, args...);
bool did[] = { update(args)... };
(void)did;
return result;
}
template<typename ... Args>
auto updatesAny (Args&& ... args)
{
auto result = updates(std::forward<Args>(args)...);
return tuple_has_value(result, true);
}
bool update (Type rhs)
{
return update(value, rhs);
}
bool update (const Self &rhs)
{
return update(rhs.value);
}
bool changed (Type rhs)
{
return value != rhs;
}
bool changed (const Self &rhs)
{
return changed(rhs.value);
}
} ;
inline
bool operator ==(const GlobalResourceVersion &lhs, const GlobalResourceVersion &rhs)
{
return lhs.value == rhs.value;
}
inline
bool operator !=(const GlobalResourceVersion &lhs, const GlobalResourceVersion &rhs)
{
return lhs.value != rhs.value;
}
inline
bool operator <(const GlobalResourceVersion &lhs, const GlobalResourceVersion &rhs)
{
return lhs.value < rhs.value;
}
inline
bool operator >=(const GlobalResourceVersion &lhs, const GlobalResourceVersion &rhs)
{
return lhs.value >= rhs.value;
}
inline
bool operator <=(const GlobalResourceVersion &lhs, const GlobalResourceVersion &rhs)
{
return lhs.value <= rhs.value;
}
inline
bool operator >(const GlobalResourceVersion &lhs, const GlobalResourceVersion &rhs)
{
return lhs.value > rhs.value;
}
} // namespace

View File

@@ -0,0 +1,25 @@
// TJP COPYRIGHT HEADER
#pragma once
#include "LocalResourceVersion.hpp"
#include <iosfwd>
namespace tjp {
namespace core {
template<typename IO>
inline void io_(IO &io, LocalResourceVersion &v)
{
io.any(v.value);
}
inline
std::ostream &operator <<(std::ostream &o, const LocalResourceVersion &v)
{
return o << v.value;
}
} // namespace
} // namespace

View File

@@ -0,0 +1,114 @@
// TJP COPYRIGHT HEADER
#pragma once
#include <atomic>
#include <tjp/core/types/Types.h>
namespace tjp {
namespace core {
struct LocalResourceVersion
{
using Type = u64;
using Self = LocalResourceVersion;
Type value = 0;
void clear()
{
value = 0;
}
bool empty() const
{
return value == 0;
}
Self &operator ++()
{
increment();
return *this;
}
// post increment
Self operator ++(int)
{
Self result { value };
increment();
return result;
}
void increment ()
{
value++;
}
static bool update (Type &value, Type rhs)
{
auto updated = value < rhs;
if (updated)
value = rhs;
return updated;
}
bool update (Type rhs)
{
return update(value, rhs);
}
bool update (const Self &rhs)
{
return update(rhs.value);
}
bool changed (Type rhs)
{
return value != rhs;
}
bool changed (const Self &rhs)
{
return changed(rhs.value);
}
} ;
inline
bool operator !=(const LocalResourceVersion &lhs, const LocalResourceVersion &rhs)
{
return lhs.value != rhs.value;
}
inline
bool operator ==(const LocalResourceVersion &lhs, const LocalResourceVersion &rhs)
{
return lhs.value == rhs.value;
}
inline
bool operator <(const LocalResourceVersion &lhs, const LocalResourceVersion &rhs)
{
return lhs.value < rhs.value;
}
inline
bool operator >(const LocalResourceVersion &lhs, const LocalResourceVersion &rhs)
{
return lhs.value > rhs.value;
}
inline
bool operator <=(const LocalResourceVersion &lhs, const LocalResourceVersion &rhs)
{
return lhs.value <= rhs.value;
}
inline
bool operator >=(const LocalResourceVersion &lhs, const LocalResourceVersion &rhs)
{
return lhs.value >= rhs.value;
}
} // namespace
} // namespace

View File

@@ -0,0 +1,71 @@
// TJP COPYRIGHT HEADER
#include <tjp/core/resource_version/GlobalResourceVersion.hpp>
#include <tjp/core/testing/catch.hpp>
namespace tjp {
namespace core {
namespace test {
SCENARIO("core::resource_version::GlobalResourceVersion")
{
GIVEN("a resource")
{
GlobalResourceVersion a;
auto e = a;
REQUIRE(a.empty());
WHEN("pre increment")
{
auto b = ++a;
REQUIRE(b == a);
REQUIRE(b > e);
REQUIRE(a > e);
REQUIRE(!a.empty());
REQUIRE(!b.empty());
auto c = ++a;
REQUIRE(c == a);
REQUIRE(c > b);
REQUIRE(b > e);
REQUIRE(!c.empty());
REQUIRE(!a.empty());
REQUIRE(!b.empty());
}
WHEN("post increment")
{
auto b = a++;
REQUIRE(b != a);
REQUIRE(a > b);
REQUIRE(a > e);
REQUIRE(b == e);
REQUIRE(!a.empty());
}
}
GIVEN("a multiple resources")
{
GlobalResourceVersion x, a, b, c, d;
a++;
b++;
x++;
c++;
d++;
auto [ua, ub, uc, ud] = x.updates(a, b, c, d);
REQUIRE(!ua);
REQUIRE(!ub);
REQUIRE(uc);
REQUIRE(ud);
}
}
} // namespace
} // namespace
} // namespace