Skip to content

Commit

Permalink
karm-base: Renamed Var<Ts...> to Union<Ts...>
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Mar 21, 2024
1 parent c113d15 commit 45e167b
Show file tree
Hide file tree
Showing 28 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/apps/hideo-calculator/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct MemStoreAction {};

struct EnterDecimalAction {};

using Action = Var<
using Action = Union<
Operator, Number, BackspaceAction, EqualAction, ClearAction, ClearAllAction,
MemClearAction, MemRecallAction, MemAddAction, MemSubAction, MemStoreAction,
EnterDecimalAction>;
Expand Down
2 changes: 1 addition & 1 deletion src/apps/hideo-clock/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct State {

struct TimeTick {};

using Action = Var<Page, TimeTick>;
using Action = Union<Page, TimeTick>;

void reduce(State &, Action);

Expand Down
2 changes: 1 addition & 1 deletion src/apps/hideo-colors/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct UpdateHsv {
Gfx::Hsv hsv;
};

using Action = Var<UpdatePage, UpdateHsv>;
using Action = Union<UpdatePage, UpdateHsv>;

inline void reduce(State &s, Action action) {
action.visit(Visitor{
Expand Down
2 changes: 1 addition & 1 deletion src/apps/hideo-counter/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct IncrementAction {};

struct DecrementAction {};

using Action = Var<ResetAction, IncrementAction, DecrementAction>;
using Action = Union<ResetAction, IncrementAction, DecrementAction>;

void reduce(State &, Action);

Expand Down
2 changes: 1 addition & 1 deletion src/apps/hideo-demos/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct SwitchAction {
usize index;
};

using Action = Var<SwitchAction>;
using Action = Union<SwitchAction>;

void reduce(State &s, Action action) {
action.visit(
Expand Down
2 changes: 1 addition & 1 deletion src/apps/hideo-files/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct Refresh {

struct AddBookmark {};

using Action = Var<GoRoot, GoBack, GoForward, GoParent, Navigate, GoTo, Refresh, AddBookmark>;
using Action = Union<GoRoot, GoBack, GoForward, GoParent, Navigate, GoTo, Refresh, AddBookmark>;

void reduce(State &, Action);

Expand Down
2 changes: 1 addition & 1 deletion src/apps/hideo-images/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct ApplyFilter {};

struct SaveImage {};

using Action = Var<
using Action = Union<
Refresh,
ToggleEditor,
SetFilter,
Expand Down
2 changes: 1 addition & 1 deletion src/apps/hideo-keyboard/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct State {
struct ToggleShift {
};

using Action = Var<ToggleShift>;
using Action = Union<ToggleShift>;

void reduce(State &, Action);

Expand Down
2 changes: 1 addition & 1 deletion src/apps/hideo-settings/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct GoBack {};

struct GoForward {};

using Action = Var<GoTo, GoBack, GoForward>;
using Action = Union<GoTo, GoBack, GoForward>;

void reduce(State &, Action);

Expand Down
2 changes: 1 addition & 1 deletion src/apps/hideo-shell/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ struct Activate {
Panel panel;
};

using Action = Var<
using Action = Union<
ToggleTablet,
Lock,
Unlock,
Expand Down
6 changes: 3 additions & 3 deletions src/apps/hideo-spreadsheet/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <karm-base/checked.h>
#include <karm-base/map.h>
#include <karm-base/string.h>
#include <karm-base/var.h>
#include <karm-base/union.h>
#include <karm-base/vec.h>
#include <karm-gfx/colors.h>
#include <karm-math/vec.h>
Expand All @@ -14,7 +14,7 @@ namespace Hideo::Spreadsheet {

/* --- Reducer -------------------------------------------------------------- */

using Value = Var<None, String, f64, bool>;
using Value = Union<None, String, f64, bool>;

struct Pos {
usize row;
Expand Down Expand Up @@ -247,7 +247,7 @@ struct SwitchSheet {

struct ToggleProperties {};

using Action = Var<
using Action = Union<
UpdateSelection,

UpdateValue,
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/hjert-api/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ struct ListenerProps {
static constexpr Type TYPE = Type::LISTENER;
};

using _Props = Var<
using _Props = Union<
DomainProps,
TaskProps,
SpaceProps,
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/hjert-core/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Hjert::Core {
struct Domain;

struct Parcel {
using Slot = Var<None, Hj::Arg, Strong<Object>>;
using Slot = Union<None, Hj::Arg, Strong<Object>>;

Hj::Arg _label;
Hj::Arg _flags;
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/hjert-core/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <karm-base/lock.h>
#include <karm-base/rc.h>
#include <karm-base/ring.h>
#include <karm-base/var.h>
#include <karm-base/union.h>
#include <karm-base/vec.h>

#include "arch.h"
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/hjert-core/vmo.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace Hjert::Core {

struct Vmo : public BaseObject<Vmo, Hj::Type::VMO> {
using _Mem = Var<Hal::PmmMem, Hal::DmaRange>;
using _Mem = Union<Hal::PmmMem, Hal::DmaRange>;
_Mem _mem;

static Res<Strong<Vmo>> alloc(usize size, Hj::VmoFlags);
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/loader/loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct Blob {
};

struct Entry {
Var<None, Mdi::Icon, Media::Image> icon = NONE;
Union<None, Mdi::Icon, Media::Image> icon = NONE;
String name;
Blob kernel;
Vec<Blob> blobs;
Expand Down
2 changes: 1 addition & 1 deletion src/kernel/loader/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct MoveSelectionAction {

struct SelectAction {};

using Action = Var<MoveSelectionAction, SelectAction>;
using Action = Union<MoveSelectionAction, SelectAction>;

void reduce(State &s, Action a) {
a.visit(Visitor{
Expand Down
4 changes: 2 additions & 2 deletions src/libs/karm-base/res.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "error.h"
#include "std.h"
#include "var.h"
#include "union.h"

namespace Karm {

Expand Down Expand Up @@ -30,7 +30,7 @@ Ok(Args &&...) -> Ok<Meta::RemoveConstVolatileRef<Args>...>;

template <typename V = None, typename E = Error>
struct [[nodiscard]] Res {
using Inner = Var<Ok<V>, E>;
using Inner = Union<Ok<V>, E>;

Inner _inner;

Expand Down
32 changes: 16 additions & 16 deletions src/libs/karm-base/var.h → src/libs/karm-base/union.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@
namespace Karm {

template <typename... Ts>
struct Var {
static_assert(sizeof...(Ts) <= 255, "Var can only hold up to 255 types");
struct Union {
static_assert(sizeof...(Ts) <= 255, "Union can only hold up to 255 types");

alignas(max(alignof(Ts)...)) char _buf[max(sizeof(Ts)...)];
u8 _index;

always_inline Var() = delete;
always_inline Union() = delete;

template <Meta::Contains<Ts...> T>
always_inline Var(T const &value)
always_inline Union(T const &value)
: _index(Meta::indexOf<T, Ts...>()) {
new (_buf) T(value);
}

template <Meta::Contains<Ts...> T>
always_inline Var(T &&value)
always_inline Union(T &&value)
: _index(Meta::indexOf<T, Ts...>()) {
new (_buf) T(std::move(value));
}

always_inline Var(Var const &other)
always_inline Union(Union const &other)
: _index(other._index) {
Meta::indexCast<Ts...>(
_index, other._buf,
Expand All @@ -38,27 +38,27 @@ struct Var {
});
}

always_inline Var(Var &&other)
always_inline Union(Union &&other)
: _index(other._index) {
Meta::indexCast<Ts...>(_index, other._buf, [this]<typename T>(T &ptr) {
new (_buf) T(std::move(ptr));
});
}

always_inline ~Var() {
always_inline ~Union() {
Meta::indexCast<Ts...>(_index, _buf, []<typename T>(T &ptr) {
ptr.~T();
});
}

template <Meta::Contains<Ts...> T>
always_inline Var &operator=(T const &value) {
*this = Var(value);
always_inline Union &operator=(T const &value) {
*this = Union(value);
return *this;
}

template <Meta::Contains<Ts...> T>
always_inline Var &operator=(T &&value) {
always_inline Union &operator=(T &&value) {
Meta::indexCast<Ts...>(_index, _buf, []<typename U>(U &ptr) {
ptr.~U();
});
Expand All @@ -69,12 +69,12 @@ struct Var {
return *this;
}

always_inline Var &operator=(Var const &other) {
*this = Var(other);
always_inline Union &operator=(Union const &other) {
*this = Union(other);
return *this;
}

always_inline Var &operator=(Var &&other) {
always_inline Union &operator=(Union &&other) {
Meta::indexCast<Ts...>(_index, _buf, []<typename T>(T &ptr) {
ptr.~T();
});
Expand Down Expand Up @@ -177,7 +177,7 @@ struct Var {
return false;
}

std::partial_ordering operator<=>(Var const &other) const {
std::partial_ordering operator<=>(Union const &other) const {
if (_index == other._index)
return visit([&]<typename T>(T const &ptr) {
if constexpr (Meta::Comparable<T>) {
Expand All @@ -189,7 +189,7 @@ struct Var {
return std::partial_ordering::unordered;
}

bool operator==(Var const &other) const {
bool operator==(Union const &other) const {
if (_index == other._index)
return visit([&]<typename T>(T const &ptr) {
if constexpr (Meta::Equatable<T>) {
Expand Down
6 changes: 3 additions & 3 deletions src/libs/karm-crypto/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ using enum HashType;
struct AnyDigest {
HashType _type;

Var<
Union<
#define ITER(NAME, TYPE) HashDigest<TYPE>,
FOR_EACH_HASH(ITER)
#undef ITER
Expand Down Expand Up @@ -61,13 +61,13 @@ struct AnyHash {
using Digest = AnyDigest;

// clang-format off
Var<
Union<
#define ITER(NAME, TYPE) TYPE,
FOR_EACH_HASH(ITER)
#undef ITER
None> _h = NONE;

using Sum = Var<
using Sum = Union<
#define ITER(NAME, TYPE) HashSum<TYPE>,
FOR_EACH_HASH(ITER)
#undef ITER
Expand Down
4 changes: 2 additions & 2 deletions src/libs/karm-gfx/buffer.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <karm-base/rc.h>
#include <karm-base/var.h>
#include <karm-base/union.h>
#include <karm-math/rect.h>

#include "color.h"
Expand Down Expand Up @@ -50,7 +50,7 @@ struct Bgra8888 {

[[gnu::used]] inline Bgra8888 BGRA8888;

using _Fmts = Var<Rgba8888, Bgra8888>;
using _Fmts = Union<Rgba8888, Bgra8888>;

struct Fmt : public _Fmts {
using _Fmts::_Fmts;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/karm-gfx/filters.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ struct FilterChain {
void apply(MutPixels) const;
};

using _Filters = Var<
using _Filters = Union<
Unfiltered,
BlurFilter,
SaturationFilter,
Expand Down
4 changes: 2 additions & 2 deletions src/libs/karm-gfx/paint.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <karm-base/var.h>
#include <karm-base/union.h>
#include <karm-base/vec.h>
#include <karm-math/trans.h>
#include <karm-media/image.h>
Expand Down Expand Up @@ -134,7 +134,7 @@ struct Gradient {
}
};

using _Paints = Var<
using _Paints = Union<
Color,
Gradient,
Media::Image>;
Expand Down
4 changes: 2 additions & 2 deletions src/libs/karm-sys/addr.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ union Ip6 {
}
};

struct Ip : public Var<Ip4, Ip6> {
using Var<Ip4, Ip6>::Var;
struct Ip : public Union<Ip4, Ip6> {
using Union<Ip4, Ip6>::Union;

static Res<Ip> parse(Io::SScan &s) {
auto saved = s;
Expand Down
2 changes: 1 addition & 1 deletion src/libs/karm-ui/scafold.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct Scafold : public Meta::NoCopy {

struct ToggleSidebar {};

using Action = Var<ToggleSidebar>;
using Action = Union<ToggleSidebar>;

static void reduce(State &s, Action a) {
a.visit(::Visitor{
Expand Down
4 changes: 2 additions & 2 deletions src/specs/json/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <karm-base/map.h>
#include <karm-base/string.h>
#include <karm-base/var.h>
#include <karm-base/union.h>
#include <karm-base/vec.h>
#include <karm-io/emit.h>
#include <karm-io/expr.h>
Expand All @@ -23,7 +23,7 @@ using Number = isize;
using Number = f64;
#endif

using Store = Var<None, Array, Object, String, Number, bool>;
using Store = Union<None, Array, Object, String, Number, bool>;

struct Value {
Store _store;
Expand Down
Loading

0 comments on commit 45e167b

Please sign in to comment.