2#ifndef _TINYPBRT_ERROR_HPP_
3#define _TINYPBRT_ERROR_HPP_
181 constexpr result(
const error_type err) noexcept : _data(std::in_place_type<error_type>, err) {}
187 constexpr result(
value_type&& val)
noexcept(std::is_nothrow_move_constructible_v<value_type>)
188 : _data(std::in_place_type<
value_type>, std::move(val)) {}
191 [[nodiscard]]
constexpr bool_t has_value() const noexcept {
return std::holds_alternative<value_type>(_data); }
194 [[nodiscard]]
constexpr explicit operator bool() const noexcept {
return has_value(); }
198 if (
has_value()) {
return error_type::NONE; }
199 return *std::get_if<error_type>(&_data);
214 return has_value() ? *std::get_if<value_type>(&_data) :
static_cast<value_type>(std::forward<U>(default_value));
221 template<
class Visitor>
222 constexpr decltype(
auto)
visit(Visitor&& visitor)
const {
223 return std::visit(std::forward<Visitor>(visitor), _data);
227 [[nodiscard]]
constexpr const value_type&
operator*() const& noexcept {
return *std::get_if<value_type>(&_data); }
233 [[nodiscard]]
constexpr value_type&&
operator*() &&
noexcept {
return std::move(*std::get_if<value_type>(&_data)); }
236 [[nodiscard]]
constexpr const value_type*
operator->() const noexcept {
return std::get_if<value_type>(&_data); }
244 return _data == rhs._data;
260 const size_t buffer_size)
noexcept {
271 constexpr size_t BufferSize = 256;
272 char_t buffer[BufferSize];
275 return std::string { buffer, count };
constexpr std::string_view to_string(const accelerator_type type) noexcept
Converts accelerator_type enum value to string.
Definition accelerator.hpp:39
@ MAX_NUM
Count of available accelerator types.
tpbrt_char_t char_t
Char type.
Definition fwd.hpp:29
tpbrt_uchar_t uchar_t
Unsigned char type.
Definition fwd.hpp:34
error
Error type (used as result type where success = TPBRT_ERROR_NONE = 0).
Definition error.hpp:25
size_t get_error_message(const error error_code, char_t *const buffer, const size_t buffer_size) noexcept
Writes error message to given buffer.
Definition error.hpp:259
@ INVALID_POINTER
Provided NULL where it is not allowed.
@ WORLD_ALREADY_STARTED
WorldBegin directive already called.
@ INVALID_COLOR_SPACE
Invalid color space.
@ INCLUDES_STACK_OVERFLOW
Includes stack overflown.
@ INVALID_TEXTURE_MAPPING
Invalid texture mapping.
@ PARSE_BOOL
Error while parsing bool.
@ INVALID_FILTER_TYPE
Invalid filter type.
@ INVALID_PARAM_VALUE
Invalid parameter value.
@ INVALID_SAMPLER_RANDOM
Invalid sampler random method.
@ INVALID_MEDIA_TYPE
Invalid media type.
@ INVALID_INTEGRATOR_TYPE
Invalid integrator type.
@ INVALID_OBJECT_TYPE
Invalid object type.
@ PARSE_FLOAT
Error while parsing float.
@ INVALID_PARAM_NAME
Invalid parameter name.
@ INVALID_TEXTURE_TYPE
Invalid texture type.
@ INVALID_ACCELERATOR_BVH_SPLIT_METHOD
Invalid accelerator bvh split method.
@ INVALID_TOKEN
Invalid token.
@ INDEX_OUT_OF_RANGE
Index out of range.
@ END_OF_FILE
End of file.
@ INVALID_SPECTRUM_BUILTIN
Invalid spectrum builtin.
@ INVALID_SCATTERING_BUILTIN
Invalid scattering builtin.
@ INVALID_CAMERA_REALISTIC_APERTURE_BUILTIN
Invalid realistic camera aperture builtin.
@ INVALID_AREA_LIGHT_TYPE
Invalid area light type.
@ INVALID_TEXTURE_ENCODING
Invalid texture encoding.
@ INVALID_LIGHT_SOURCE_TYPE
Invalid light source type.
@ INVALID_TEXTURE_WRAP
Invalid texture wrap.
@ INVALID_OPTION
Invalid option.
@ INVALID_CAMERA_SPHERICAL_MAPPING
Invalid spherical camera mapping.
@ INVALID_INTEGRATOR_LIGHT_SAMPLER
Invalid integrator light sampler.
@ DUPLICATE_PARAM_NAME
Duplicate parameter name.
@ INVALID_STRING
Invalid string.
@ INVALID_TEXTURE_CLASS
Invalid texture class.
@ UNEXPECTED_TOKEN
Unexpected token.
@ PARAM_TYPE_MISMATCH
Parameter type mismatch.
@ NOT_FOUND
Something was not found. For example texture with given name.
@ DUPLICATE_MEDIUM_NAME
Duplicate medium name.
@ INVALID_PARAM_TYPE
Invalid parameter type.
@ INVALID_HANDLE
Invalid handle.
@ TOO_MANY_END_ATTRIBUTES
Too many AttributeEnd directives called.
@ INVALID_SHAPE_CURVE_BASIS
Invalid curve shape basis.
@ DUPLICATE_TEXTURE_NAME
Duplicate texture name.
@ INVALID_TEXTURE_FILTER
Invalid texture filter.
@ INVALID_COORD_SYSTEM_NAME
Invalid coordinate system name.
@ NONE
No error -> Success.
@ WRONG_TEXTURE_TYPE
Wrong texture type.
@ MISSING_REQUIRED_PARAMETER
Required parameter is missing.
@ INVALID_SAMPLER_TYPE
Invalid sampler type.
@ INVALID_CAMERA_TYPE
Invalid camera type.
@ PARSE_INT
Error while parsing int.
@ OUT_OF_MEMORY
Out of memory.
@ INVALID_DIRECTIVE
Invalid directive.
@ INVALID_MATERIAL_TYPE
Invalid material type.
@ FILE_NOT_FOUND
Provided file not found.
@ DUPLICATE_OBJECT_NAME
Duplicate object name.
@ TOO_MANY_VALUES
Too many values provided.
@ PARSE_STRING
Error while parsing string.
@ PARSE_UINT
Error while parsing uint.
@ INVALID_FILM_SENSOR
Invalid film sensor.
@ INVALID_FILM_TYPE
Invalid film type.
@ INVALID_ACCELERATOR_TYPE
Invalid accelerator type.
@ INVALID_SHAPE_TYPE
Invalid shape type.
@ INVALID_COORD_SYSTEM_TYPE
Invalid coordinate system type.
@ DUPLICATE_MATERIAL_NAME
Duplicate material name.
@ INVALID_SHAPE_CURVE_TYPE
Invalid curve shape type.
tpbrt_size_t tpbrt_get_error_message(tpbrt_error_t error, tpbrt_char_t *buffer, tpbrt_size_t buffer_size)
Writes error message to given buffer.
tpbrt_error_t
Error type (used as result type where success = TPBRT_ERROR_NONE = 0).
Definition error.h:20
@ TPBRT_ERROR_INVALID_SAMPLER_TYPE
Invalid sampler type.
Definition error.h:90
@ TPBRT_ERROR_WRONG_TEXTURE_TYPE
Wrong texture type.
Definition error.h:134
@ TPBRT_ERROR_DUPLICATE_TEXTURE_NAME
Duplicate texture name.
Definition error.h:110
@ TPBRT_ERROR_DUPLICATE_MEDIUM_NAME
Duplicate medium name.
Definition error.h:146
@ TPBRT_ERROR_INVALID_CAMERA_SPHERICAL_MAPPING
Invalid spherical camera mapping.
Definition error.h:78
@ TPBRT_ERROR_INVALID_PARAM_VALUE
Invalid parameter value.
Definition error.h:124
@ TPBRT_ERROR_INVALID_COORD_SYSTEM_NAME
Invalid coordinate system name.
Definition error.h:136
@ TPBRT_ERROR_INVALID_PARAM_TYPE
Invalid parameter type.
Definition error.h:44
@ TPBRT_ERROR_INVALID_ACCELERATOR_TYPE
Invalid accelerator type.
Definition error.h:86
@ TPBRT_ERROR_INVALID_OPTION
Invalid option.
Definition error.h:38
@ TPBRT_ERROR_FILE_NOT_FOUND
Provided file not found.
Definition error.h:128
@ TPBRT_ERROR_PARAM_TYPE_MISMATCH
Parameter type mismatch.
Definition error.h:142
@ TPBRT_ERROR_INVALID_CAMERA_REALISTIC_APERTURE_BUILTIN
Invalid realistic camera aperture builtin.
Definition error.h:80
@ TPBRT_ERROR_NOT_FOUND
Something was not found. For example texture with given name.
Definition error.h:58
@ TPBRT_ERROR_OUT_OF_MEMORY
Out of memory.
Definition error.h:60
@ TPBRT_ERROR_UNEXPECTED_TOKEN
Unexpected token.
Definition error.h:54
@ TPBRT_ERROR_INVALID_AREA_LIGHT_TYPE
Invalid area light type.
Definition error.h:96
@ TPBRT_ERROR_PARSE_BOOL
Error while parsing bool.
Definition error.h:32
@ TPBRT_ERROR_TOO_MANY_VALUES
Too many values provided.
Definition error.h:72
@ TPBRT_ERROR_INVALID_COORD_SYSTEM_TYPE
Invalid coordinate system type.
Definition error.h:40
@ TPBRT_ERROR_INVALID_SHAPE_CURVE_TYPE
Invalid curve shape type.
Definition error.h:122
@ TPBRT_ERROR_INVALID_COLOR_SPACE
Invalid color space.
Definition error.h:68
@ TPBRT_ERROR_PARSE_INT
Error while parsing int.
Definition error.h:30
@ TPBRT_ERROR_MAX_NUM
Count of available error codes.
Definition error.h:150
@ TPBRT_ERROR_INVALID_TEXTURE_ENCODING
Invalid texture encoding.
Definition error.h:106
@ TPBRT_ERROR_INVALID_TEXTURE_CLASS
Invalid texture class.
Definition error.h:100
@ TPBRT_ERROR_INVALID_INTEGRATOR_TYPE
Invalid integrator type.
Definition error.h:82
@ TPBRT_ERROR_END_OF_FILE
End of file.
Definition error.h:24
@ TPBRT_ERROR_INVALID_MEDIA_TYPE
Invalid media type.
Definition error.h:126
@ TPBRT_ERROR_WORLD_ALREADY_STARTED
WorldBegin directive already called.
Definition error.h:48
@ TPBRT_ERROR_INVALID_OBJECT_TYPE
Invalid object type.
Definition error.h:52
@ TPBRT_ERROR_INVALID_CAMERA_TYPE
Invalid camera type.
Definition error.h:76
@ TPBRT_ERROR_INVALID_TEXTURE_WRAP
Invalid texture wrap.
Definition error.h:102
@ TPBRT_ERROR_INVALID_LIGHT_SOURCE_TYPE
Invalid light source type.
Definition error.h:94
@ TPBRT_ERROR_DUPLICATE_PARAM_NAME
Duplicate parameter name.
Definition error.h:46
@ TPBRT_ERROR_NONE
No error -> Success.
Definition error.h:22
@ TPBRT_ERROR_PARSE_STRING
Error while parsing string.
Definition error.h:116
@ TPBRT_ERROR_INDEX_OUT_OF_RANGE
Index out of range.
Definition error.h:138
@ TPBRT_ERROR_DUPLICATE_OBJECT_NAME
Duplicate object name.
Definition error.h:130
@ TPBRT_ERROR_INVALID_SCATTERING_BUILTIN
Invalid scattering builtin.
Definition error.h:148
@ TPBRT_ERROR_INVALID_SPECTRUM_BUILTIN
Invalid spectrum builtin.
Definition error.h:70
@ TPBRT_ERROR_INVALID_TEXTURE_TYPE
Invalid texture type.
Definition error.h:98
@ TPBRT_ERROR_DUPLICATE_MATERIAL_NAME
Duplicate material name.
Definition error.h:144
@ TPBRT_ERROR_INVALID_MATERIAL_TYPE
Invalid material type.
Definition error.h:114
@ TPBRT_ERROR_INVALID_ACCELERATOR_BVH_SPLIT_METHOD
Invalid accelerator bvh split method.
Definition error.h:88
@ TPBRT_ERROR_INVALID_TEXTURE_MAPPING
Invalid texture mapping.
Definition error.h:108
@ TPBRT_ERROR_INVALID_SHAPE_TYPE
Invalid shape type.
Definition error.h:118
@ TPBRT_ERROR_INVALID_SHAPE_CURVE_BASIS
Invalid curve shape basis.
Definition error.h:120
@ TPBRT_ERROR_TOO_MANY_END_ATTRIBUTES
Too many AttributeEnd directives called.
Definition error.h:50
@ TPBRT_ERROR_INVALID_TOKEN
Invalid token.
Definition error.h:26
@ TPBRT_ERROR_INVALID_PARAM_NAME
Invalid parameter name.
Definition error.h:42
@ TPBRT_ERROR_PARSE_UINT
Error while parsing uint.
Definition error.h:66
@ TPBRT_ERROR_INVALID_HANDLE
Invalid handle.
Definition error.h:112
@ TPBRT_ERROR_PARSE_FLOAT
Error while parsing float.
Definition error.h:28
@ TPBRT_ERROR_INVALID_POINTER
Provided NULL where it is not allowed.
Definition error.h:62
@ TPBRT_ERROR_MISSING_REQUIRED_PARAMETER
Required parameter is missing.
Definition error.h:56
@ TPBRT_ERROR_INVALID_TEXTURE_FILTER
Invalid texture filter.
Definition error.h:104
@ TPBRT_ERROR_INVALID_FILTER_TYPE
Invalid filter type.
Definition error.h:132
@ TPBRT_ERROR_INVALID_FILM_TYPE
Invalid film type.
Definition error.h:64
@ TPBRT_ERROR_INVALID_SAMPLER_RANDOM
Invalid sampler random method.
Definition error.h:92
@ TPBRT_ERROR_INCLUDES_STACK_OVERFLOW
Includes stack overflown.
Definition error.h:140
@ TPBRT_ERROR_INVALID_FILM_SENSOR
Invalid film sensor.
Definition error.h:74
@ TPBRT_ERROR_INVALID_DIRECTIVE
Invalid directive.
Definition error.h:34
@ TPBRT_ERROR_INVALID_STRING
Invalid string.
Definition error.h:36
@ TPBRT_ERROR_INVALID_INTEGRATOR_LIGHT_SAMPLER
Invalid integrator light sampler.
Definition error.h:84
bool bool_t
Bool type.
Definition fwd.hpp:82
Definition accelerator.hpp:14
Result of an operation: either a value or an error code (similar to C++23 std::expected).
Definition error.hpp:165
constexpr value_type value_or(U &&default_value) const &
Returns value or given default value when result holds an error.
Definition error.hpp:213
constexpr bool_t operator==(const error_type err) const noexcept
Equality operator (true when result holds given error).
Definition error.hpp:248
T value_type
Value type.
Definition error.hpp:167
constexpr result(const error_type err) noexcept
Conversion constructor for error.
Definition error.hpp:181
constexpr error_type get_error() const noexcept
Returns error code (error::NONE when result has value).
Definition error.hpp:197
constexpr value_type & get_value() &
Returns value (throws std::bad_variant_access when result holds an error).
Definition error.hpp:206
constexpr bool_t has_value() const noexcept
Returns true if result has value.
Definition error.hpp:191
constexpr const value_type * operator->() const noexcept
Returns pointer to value (unchecked, like std::optional).
Definition error.hpp:236
constexpr value_type & operator*() &noexcept
Returns value (unchecked, like std::optional).
Definition error.hpp:230
constexpr const variant_type & to_variant() const noexcept
Conversion to variant.
Definition error.hpp:218
constexpr bool_t operator==(const result &rhs) const
Equality operator.
Definition error.hpp:242
constexpr value_type && operator*() &&noexcept
Returns value (unchecked, like std::optional).
Definition error.hpp:233
constexpr result(value_type &&val) noexcept(std::is_nothrow_move_constructible_v< value_type >)
Conversion constructor for r-value value.
Definition error.hpp:187
constexpr result(const value_type &val)
Conversion constructor for value.
Definition error.hpp:184
constexpr const value_type & operator*() const &noexcept
Returns value (unchecked, like std::optional).
Definition error.hpp:227
constexpr const value_type & get_value() const &
Returns value (throws std::bad_variant_access when result holds an error).
Definition error.hpp:203
std::variant< value_type, error_type > variant_type
Variant type of result.
Definition error.hpp:173
constexpr value_type && get_value() &&
Returns value (throws std::bad_variant_access when result holds an error).
Definition error.hpp:209
constexpr value_type * operator->() noexcept
Returns pointer to value (unchecked, like std::optional).
Definition error.hpp:239
constexpr decltype(auto) visit(Visitor &&visitor) const
Visits value or error.
Definition error.hpp:222