Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default equality operators #22

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 53 additions & 3 deletions include/gs_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,27 @@
namespace gs
{
// Primitive types
struct VarUint { std::uint64_t value; };
struct VarInt { std::int64_t value; };
struct Float16 { float value; };
struct VarUint
{
std::uint64_t value;

auto operator<=>(const VarUint &other) const = default;
};

struct VarInt
{
std::int64_t value;

auto operator<=>(const VarInt &other) const = default;
};

struct Float16
{
float value;

auto operator<=>(const Float16 &other) const = default;
};

typedef float Float32;
typedef double Float64;
typedef std::uint8_t Uint8;
Expand Down Expand Up @@ -104,6 +122,8 @@ namespace gs
Float32 x;
Float32 y;
Float32 z;

auto operator<=>(const Loc1 &other) const = default;
};

struct Loc2
Expand All @@ -114,26 +134,34 @@ namespace gs
Float16 vy;
Float16 vx;
Float16 vz;

auto operator<=>(const Loc2 &other) const = default;
};

struct Norm1
{
Float16 x;
Float16 y;
Float16 z;

auto operator<=>(const Norm1 &other) const = default;
};

struct TextureUV1
{
VarUint u;
VarUint v;

auto operator<=>(const TextureUV1 &other) const = default;
};

struct Rot1
{
Float16 i;
Float16 j;
Float16 k;

auto operator<=>(const Rot1 &other) const = default;
};

struct Rot2
Expand All @@ -144,13 +172,17 @@ namespace gs
Float16 ei;
Float16 ej;
Float16 ek;

auto operator<=>(const Rot2 &other) const = default;
};

struct Transform1
{
Float16 tx;
Float16 ty;
Float16 tz;

auto operator<=>(const Transform1 &other) const = default;
};

struct Object1
Expand All @@ -162,11 +194,15 @@ namespace gs
Loc1 scale;
Boolean active;
std::optional<ObjectID> parent;

bool operator==(const Object1 &other) const = default;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this one (and a couple of others) use operator== and the most use operator<=>?

Copy link
Contributor Author

@RichLogan RichLogan Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some issues with <=> not being defined on std::optional or std::vector (which might vary by implementation?), so for the types using those I just stuck with the equality that I needed.

};

struct HeadIPD1
{
Float16 ipd;

auto operator<=>(const HeadIPD1 &other) const = default;
};

struct Head1
Expand All @@ -176,6 +212,8 @@ namespace gs
Loc2 location;
Rot2 rotation;
std::optional<HeadIPD1> ipd;

bool operator==(const Head1 &other) const = default;
};

struct Mesh1
Expand All @@ -185,6 +223,8 @@ namespace gs
std::vector<Norm1> normals;
std::vector<TextureUV1> textures;
std::vector<VarUint> triangles;

bool operator==(const Mesh1 &other) const = default;
};

struct Hand1
Expand All @@ -194,6 +234,8 @@ namespace gs
Boolean left;
Loc2 location;
Rot2 rotation;

auto operator<=>(const Hand1 &other) const = default;
};

struct Thumb
Expand All @@ -202,6 +244,8 @@ namespace gs
Transform1 ip;
Transform1 mcp;
Transform1 cmc;

auto operator<=>(const Thumb &other) const = default;
};

struct Finger
Expand All @@ -211,6 +255,8 @@ namespace gs
Transform1 pip;
Transform1 mcp;
Transform1 cmc;

auto operator<=>(const Finger &other) const = default;
};

struct Hand2
Expand All @@ -226,12 +272,16 @@ namespace gs
Finger middle;
Finger ring;
Finger pinky;

auto operator<=>(const Hand2 &other) const = default;
};

struct UnknownObject
{
VarUint tag;
Blob data;

bool operator==(const UnknownObject &other) const = default;
};

// Variant type that can contain any object type
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ add_library(gse

set_target_properties(gse
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD 20
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is everyone dependent on this code OK with the move to C++20?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)
target_compile_options(gse PRIVATE
Expand Down
2 changes: 1 addition & 1 deletion test/test_databuffer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ add_executable(test_databuffer test_databuffer.cpp)

set_target_properties(test_databuffer
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)

Expand Down
2 changes: 1 addition & 1 deletion test/test_float/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ add_executable(test_float test_float.cpp)

set_target_properties(test_float
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)

Expand Down
2 changes: 1 addition & 1 deletion test/test_gs_api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ add_executable(test_gs_api test_gs_api.cpp)

set_target_properties(test_gs_api
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)

Expand Down
2 changes: 1 addition & 1 deletion test/test_gs_decoder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ add_executable(test_gs_decoder test_gs_decoder.cpp)

set_target_properties(test_gs_decoder
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)

Expand Down
2 changes: 1 addition & 1 deletion test/test_gs_deserializer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ add_executable(test_gs_deserializer test_gs_deserializer.cpp)

set_target_properties(test_gs_deserializer
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)

Expand Down
2 changes: 1 addition & 1 deletion test/test_gs_encoder/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ add_executable(test_gs_encoder test_gs_encoder.cpp)

set_target_properties(test_gs_encoder
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)

Expand Down
2 changes: 1 addition & 1 deletion test/test_gs_serializer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ add_executable(test_gs_serializer test_gs_serializer.cpp)

set_target_properties(test_gs_serializer
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)

Expand Down
2 changes: 1 addition & 1 deletion test/test_half_float/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ add_executable(test_half_float test_half_float.cpp)

set_target_properties(test_half_float
PROPERTIES
CXX_STANDARD 17
CXX_STANDARD 20
CXX_STANDARD_REQUIRED YES
CXX_EXTENSIONS NO)

Expand Down