-
Notifications
You must be signed in to change notification settings - Fork 72
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
ffi: Add Value
class to represent all supported primitive values for the key-value pair IR format.
#502
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. PR title is also fine by me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part 2
REQUIRE(int_value.is<value_int_t>()); | ||
REQUIRE((int_value.get_immutable_view<value_int_t>() == cIntVal)); | ||
REQUIRE_FALSE(int_value.is_null()); | ||
REQUIRE_FALSE(int_value.is<value_float_t>()); | ||
REQUIRE_FALSE(int_value.is<value_bool_t>()); | ||
REQUIRE_FALSE(int_value.is<string>()); | ||
REQUIRE_FALSE(int_value.is<EightByteEncodedTextAst>()); | ||
REQUIRE_FALSE(int_value.is<FourByteEncodedTextAst>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can extract this into a method that basically tests
REQUIRE((std::is_same_v<value_int_t, Type> == value.is<value_int_t>()));
for each type, and then just passes in the values defined here, right?
REQUIRE_THROWS(int_value.get_immutable_view<value_float_t>()); | ||
REQUIRE_THROWS(int_value.get_immutable_view<value_bool_t>()); | ||
REQUIRE_THROWS(int_value.get_immutable_view<string>()); | ||
REQUIRE_THROWS(int_value.get_immutable_view<EightByteEncodedTextAst>()); | ||
REQUIRE_THROWS(int_value.get_immutable_view<FourByteEncodedTextAst>()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can extract this into a method that does something like:
if constexpr (std::is_same_v<value_int_t, Type>) {
REQUIRE(value.get_immutable_view<Type>() == typed_value);
} else {
REQUIRE_THROWS(value.get_immutable_view<value_int_t>());
}
for each type, right?
Co-authored-by: kirkrodrigues <[email protected]>
To be consistent within the same file, and also not be confusing with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the PR title, how about:
ffi: Add Value
class to represent all supported primitive values for the key-value pair IR format.
Value
class to represent all supported primitive values in the key-value pair IR format.Value
class to represent all supported primitive values for the key-value pair IR format.
…r the key-value pair IR format. (y-scope#502) Co-authored-by: kirkrodrigues <[email protected]>
Description
This PR adds a class named
Value
, which wrapsstd::variant
to implement a supertype for all the supported value types in the key-value pair IR format. The core idea of theValue
class is to provide type safety, using templates to guard the supported types, as well as the methods to:The current implementation's support types include
int64_t
,double
,bool
,std::string
, andEncodedTextAst
(both four-byte encoding and eight-byte encoding). The value can also benull
if it is constructed without any input (implemented usingstd::monostate
).With the current design, it should be easy to extend the supported types in future development.
Validation performed