xtd 0.2.0
Loading...
Searching...
No Matches
box.h
Go to the documentation of this file.
1
4#pragma once
5#include "convert_string.h"
6#include "icomparable.h"
7#include "iequatable.h"
9#include "iequatable.h"
10#include "enum.h"
11#include "object.h"
12#include "ustring.h"
13#include "types.h"
14
16namespace xtd {
46 template<typename type_t>
47 class box : public xtd::icomparable<box<type_t>>, public xtd::iequatable<box<type_t>>, public xtd::object {
48 public:
49 using underlying_type = type_t;
51
54 box() = default;
57 box(const type_t& value) : value_(value) {}
60 template<typename ...args_t>
61 box(args_t&& ...args) : value_(args...) {}
63
65 box(const box&) = default;
66 box(box&&) = default;
67 box& operator =(const box&) = default;
68 box& operator =(const type_t& value) {
69 value_ = value;
70 return *this;
71 };
73
75
79 const type_t& value() const noexcept {return value_;}
82 type_t& value() noexcept {return value_;}
85 box& value(const type_t& value) {
86 value_ = value;
87 return *this;
88 }
90
92
94 operator type_t() const noexcept {return value_;}
96
98
100 bool equals(const box& value) const noexcept override {return value_ == value.value_;}
101
102 int32 compare_to(const box& value) const noexcept override {
103 if (value_ == value.value_) return 0;
104 if (value_ < value.value_) return -1;
105 return 1;
106 }
107
108 xtd::ustring to_string() const noexcept override {return xtd::ustring::format("{}", value_);}
112 xtd::ustring to_string(const xtd::ustring& format) const noexcept {
113 return xtd::ustring::format(xtd::ustring::format("{{:{}}}", format), value_);
114 }
116
118
123 static type_t parse(const xtd::ustring& value) {return xtd::parse<type_t>(value);}
124
129 static bool try_parse(const xtd::ustring& value, type_t& result) noexcept {return xtd::try_parse<type_t>(value, result);}
131
132 private:
133 type_t value_ {};
134 };
135}
Represents a boxed object.
Definition box.h:47
xtd::ustring to_string(const xtd::ustring &format) const noexcept
Converts the value of this instance to its equivalent string representation, using the specified form...
Definition box.h:112
box & value(const type_t &value)
Sets de underlying value.
Definition box.h:85
type_t & value() noexcept
Gets the underlying value.
Definition box.h:82
box(args_t &&...args)
Initialize a new xtd::box object with specified value.
Definition box.h:61
bool equals(const box &value) const noexcept override
Indicates whether the current object is equal to another object of the same type.
Definition box.h:100
box(const type_t &value)
Initialize a new xtd::box object with specified value.
Definition box.h:57
box()=default
Initialize a new xtd::box object.
static type_t parse(const xtd::ustring &value)
Converts the string to its type_t equivalent.
Definition box.h:123
int32 compare_to(const box &value) const noexcept override
Compares the current instance with another object of the same type.
Definition box.h:102
const type_t & value() const noexcept
Gets the underlying value.
Definition box.h:79
static bool try_parse(const xtd::ustring &value, type_t &result) noexcept
Converts the string to its type_t equivalent. A return value indicates whether the conversion succeed...
Definition box.h:129
xtd::ustring to_string() const noexcept override
Returns a sxd::ustring that represents the current object.
Definition box.h:108
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition icomparable.h:17
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.h:18
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.h:32
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:47
Contains xtd::convert_string class.
Contains enum_ and enum_ut_ keywords.
static ustring format(const ustring &fmt, args_t &&... args)
Writes the text representation of the specified arguments list, to string using the specified format ...
Definition ustring.h:1131
int_least32_t int32
Represents a 32-bit signed integer.
Definition types.h:131
Contains xtd::icomparable interface.
Contains xtd::iequatable interface.
Contains xtd::invalid_cast_exception exception.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Contains xtd::object class.
Contains xtd fundamental types.
Contains xtd::ustring class.