xtd 0.2.0
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__
11#undef __XTD_CORE_INTERNAL__
13#include "core_export.hpp"
14#include "iequatable.hpp"
15#include "ptr.hpp"
16#include "types.hpp"
17#if defined(__xtd__cpp_lib_format)
18#include <cassert>
19#include <format>
20#endif
21#include <type_traits>
22
24namespace xtd {
26 class type_object;
28
44 public:
46
50 object() = default;
52
54 object(const object&) = default;
55 object& operator =(const object&) = default;
56 virtual ~object() = default;
57 bool operator ==(const object& obj) const noexcept;
58 bool operator !=(const object& obj) const noexcept;
60
62
70 virtual bool equals(const object& obj) const noexcept;
71
74 virtual xtd::size get_hash_code() const noexcept;
75
81 virtual type_object get_type() const noexcept;
82
99 template<class object_t>
100 xtd::uptr<object_t> memberwise_clone() const {
101 auto object_ptr = dynamic_cast<const object_t*>(this);
103 return xtd::new_uptr<object_t>(*object_ptr);
104 }
105
111 virtual xtd::string to_string() const noexcept;
113
115
124 template<class object_a_t, class object_b_t>
125 static bool equals(const object_a_t& object_a, const object_b_t& object_b) noexcept {
126 static_assert(std::is_base_of<xtd::object, object_a_t>::value, "object_a does not inherit from xtd::object");
127 static_assert(std::is_base_of<xtd::object, object_b_t>::value, "object_b does not inherit from xtd::object");
128 return object_a == object_b;
129 }
130
138 template<class object_a_t, class object_b_t>
139 static bool reference_equals(const object_a_t& object_a, const object_b_t& object_b) noexcept {
140 static_assert(std::is_base_of<xtd::object, object_a_t>::value, "object_a does not inherit from xtd::object");
141 static_assert(std::is_base_of<xtd::object, object_b_t>::value, "object_b does not inherit from xtd::object");
142 return &object_a == &object_b;
143 }
145 };
146}
147
149std::ostream& operator <<(std::ostream& os, const xtd::object& obj) noexcept;
151
152#include "type.hpp"
153
154/*
157#if defined(__xtd__cpp_lib_format)
158template <>
159struct std::formatter<xtd::object> : std::formatter<std::string> {
160 template<class object_t, class format_context_t>
161 auto format(const object_t& obj, format_context_t& ctx) const {return std::format_to(ctx.out(), "{}", std::string {obj.to_string()});}
162};
163#endif
165*/
Contains string definitions.
Contains __xtd_std_version definitions.
Represents text as a sequence of character units.
Definition basic_string.hpp:71
static void throws(xtd::helpers::exception_case exception_case, const source_location &location=source_location::current())
Throws an exption with specified exception case.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:43
virtual bool equals(const object &obj) const noexcept
Determines whether the specified object is equal to the current object.
virtual xtd::size get_hash_code() const noexcept
Serves as a hash function for a particular type.
static bool reference_equals(const object_a_t &object_a, const object_b_t &object_b) noexcept
Determines whether the specified object instances are the same instance.
Definition object.hpp:139
object()=default
Create a new instance of the ultimate base class object.
virtual xtd::string to_string() const noexcept
Returns a xtd::string that represents the current object.
Represents type declarations: class types, interface types, array types, value types,...
Definition type_object.hpp:39
Contains core_export_ keyword.
@ invalid_cast
The cast is not valid.
#define core_export_
Define shared library export.
Definition core_export.hpp:13
std::unique_ptr< type_t > uptr
The xtd::uptr object is a unique pointer.
Definition uptr.hpp:25
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
Contains xtd::iequatable interface.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Contains xtd::ptr type.
Contains xtd::helpers::exception_case enum class.
Contains xtd::type type.
Contains xtd fundamental types.