xtd 1.0.0
Loading...
Searching...
No Matches
object.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#define __XTD_STD_INTERNAL__
8#undef __XTD_STD_INTERNAL__
9#define __XTD_CORE_INTERNAL__
12#undef __XTD_CORE_INTERNAL__
14#include "core_export.hpp"
16#include "iequatable.hpp"
17#include "usize.hpp"
18#if defined(__xtd__cpp_lib_format)
19#include <cassert>
20#include <format>
21#include <memory>
22#endif
23#include <type_traits>
24
26namespace xtd {
28 class type_object;
30
46 public:
48
52 object() = default;
54
56 virtual ~object() = default;
57 auto operator ==(const object& obj) const noexcept -> bool;
58 auto operator !=(const object& obj) const noexcept -> bool;
60
62
70 [[nodiscard]] virtual auto equals(const object& obj) const noexcept -> bool;
71
74 [[nodiscard]] virtual auto get_hash_code() const noexcept -> xtd::usize;
75
81 [[nodiscard]] virtual auto get_type() const noexcept -> type_object;
82
99 template<typename object_t>
100 [[nodiscard]] auto memberwise_clone() const -> xtd::unique_ptr_object<object_t>;
101
107 [[nodiscard]] virtual auto to_string() const -> xtd::string;
109
111
120 template<typename object_a_t, typename object_b_t>
121 [[nodiscard]] static auto equals(const object_a_t& object_a, const object_b_t& object_b) noexcept -> bool {
122 static_assert(std::is_base_of<xtd::object, object_a_t>::value, "object_a does not inherit from xtd::object");
123 static_assert(std::is_base_of<xtd::object, object_b_t>::value, "object_b does not inherit from xtd::object");
124 return object_a == object_b;
125 }
126
134 template<typename object_a_t, typename object_b_t>
135 [[nodiscard]] static auto reference_equals(const object_a_t& object_a, const object_b_t& object_b) noexcept -> bool {
136 static_assert(std::is_base_of<xtd::object, object_a_t>::value, "object_a does not inherit from xtd::object");
137 static_assert(std::is_base_of<xtd::object, object_b_t>::value, "object_b does not inherit from xtd::object");
138 return &object_a == &object_b;
139 }
140
141 };
142
143 auto operator <<(std::ostream& os, const xtd::object& obj) noexcept -> std::ostream&;
145}
146
147
148#include "type.hpp"
149
150/*
153#if defined(__xtd__cpp_lib_format)
154template <>
155struct std::formatter<xtd::object> : std::formatter<std::string> {
156 template<typename object_t, typename format_context_t>
157 auto format(const object_t& obj, format_context_t& ctx) const {return std::format_to(ctx.out(), "{}", std::string {obj.to_string()});}
158};
159#endif
161*/
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
auto memberwise_clone() const -> xtd::unique_ptr_object< object_t >
Creates a shallow copy of the current object.
virtual auto get_hash_code() const noexcept -> xtd::usize
Serves as a hash function for a particular type.
virtual auto to_string() const -> xtd::string
Returns a xtd::string that represents the current object.
static auto reference_equals(const object_a_t &object_a, const object_b_t &object_b) noexcept -> bool
Determines whether the specified object instances are the same instance.
Definition object.hpp:135
virtual auto equals(const object &obj) const noexcept -> bool
Determines whether the specified object is equal to the current object.
object()=default
Create a new instance of the ultimate base class object.
virtual auto get_type() const noexcept -> type_object
Gets the type of the current instance.
Represents type declarations: class types, interface types, array types, value types,...
Definition type_object.hpp:39
Contains core_export_ keyword.
Contains generic stream output methods.
#define core_export_
Define shared library export.
Definition core_export.hpp:13
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
Contains xtd::iequatable interface.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::helpers::throw_helper class.
Contains xtd::type type.
Contains xtd::usize type.