xtd 0.2.0
Loading...
Searching...
No Matches
box_integer.hpp
Go to the documentation of this file.
1
4#pragma once
5
7// Workaround : Like Windows.h (with NOMINMAX defined), some includes define max as a macro and this causes compilation errors.
8#if defined(_MSC_VER) && defined(max)
9# if __cplusplus < 202302L
10# pragma message("The macro `max` is defined. If you include the `Windows.h` file, please define the 'NOMINMAX' constant before including `Windows.h`. xtd will undef the `max` macro.")
11# else
12# warning "The macro `max` is defined. If you include the `Windows.h` file, please define the 'NOMINMAX' constant before including `Windows.h`. xtd will undef the `max` macro."
13# endif
14# undef max
15#endif
17
18#include "box.hpp"
19#include "int64.hpp"
20#include "number_styles.hpp"
21#include "signed_integer.hpp"
22#include "unsigned_integer.hpp"
23
25namespace xtd {
54 template<typename type_t>
55 class box_integer : public xtd::box<type_t> {
56 public:
58 box_integer() = default;
59 box_integer(const type_t& value) : xtd::box<type_t>(value) {}
60 box_integer(const box_integer&) = default;
61 box_integer(box_integer&&) = default;
62 box_integer& operator =(const box_integer&) = default;
63 box_integer& operator =(box_integer&&) = default;
65
67
71 static constexpr type_t max_value = std::numeric_limits<type_t>::max();
74 static constexpr type_t min_value = std::numeric_limits<type_t>::lowest();
76
78
85 [[nodiscard]] static auto is_valid(type_t value) noexcept -> bool {return internal_is_valid(value);}
86
87 using box<type_t>::parse;
91 [[nodiscard]] static auto parse(const xtd::string& value, xtd::number_styles styles) -> type_t {return xtd::parse<type_t>(value, styles);}
92
93 using box<type_t>::try_parse;
97 [[nodiscard]] static auto try_parse(const xtd::string& value, type_t& result, xtd::number_styles styles) -> bool {return xtd::try_parse<type_t>(value, result, styles);}
99
100 private:
101 [[nodiscard]] static auto internal_is_valid(xtd::signed_integer auto value) noexcept -> bool {
102 if (std::unsigned_integral<type_t>) return value > 0 && static_cast<xtd::uint64>(value) <= static_cast<xtd::uint64>(max_value);
103 return static_cast<xtd::int64>(value) >= static_cast<xtd::int64>(min_value) && static_cast<xtd::int64>(value) <= static_cast<xtd::int64>(max_value);
104 }
110 [[nodiscard]] static auto internal_is_valid(xtd::unsigned_integer auto value) noexcept -> auto {
112 }
113
114 };
115}
Contains xtd::box struct.
Represents a boxed integer object.
Definition box_integer.hpp:55
static constexpr xtd::byte max_value
Definition box_integer.hpp:71
static auto parse(const xtd::string &value, xtd::number_styles styles) -> type_t
Converts the string to its type_t equivalent.
Definition box_integer.hpp:91
static auto try_parse(const xtd::string &value, type_t &result, xtd::number_styles styles) -> bool
Converts the string to its type_t equivalent.
Definition box_integer.hpp:97
static constexpr xtd::byte min_value
Definition box_integer.hpp:74
static auto is_valid(type_t value) noexcept -> bool
Determines whether the specified signed integral value is within the range of type_t.
Definition box_integer.hpp:85
Definition signed_integer.hpp:14
Definition unsigned_integer.hpp:14
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
std::int64_t int64
Represents a 64-bit signed integer.
Definition int64.hpp:23
std::uint64_t uint64
Represents a 64-bit unsigned integer.
Definition uint64.hpp:23
number_styles
Determines the styles permitted in numeric string arguments that are passed to the xtd::parse and xtd...
Definition number_styles.hpp:16
value_t parse(const std::string &str)
Convert a string into a type.
Definition parse.hpp:34
bool try_parse(const std::basic_string< char > &str, value_t &value) noexcept
Convert a string into a type.
Definition parse.hpp:416
Contains xtd::int64 type.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::number_styles enum class.
Contains xtd::signed_integer concept.
Represents a boxed object.
Definition box.hpp:56
value_type value
Gets or sets the underlying value.
Definition box.hpp:106
Contains xtd::unsigned_integer concept.