xtd 0.2.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__
11#undef __XTD_CORE_INTERNAL__
12#include "core_export.hpp"
13#include "iequatable.hpp"
14#include "types.hpp"
15#if defined(__xtd__cpp_lib_format)
16#include <cassert>
17#include <format>
18#endif
19#include <string>
20#include <type_traits>
21
23namespace xtd {
25 class type_object;
27
43 public:
45
49 object() = default;
51
53 object(const object&) = default;
54 object& operator =(const object&) = default;
55 virtual ~object() = default;
56 bool operator ==(const object& obj) const noexcept;
57 bool operator !=(const object& obj) const noexcept;
59
61
69 virtual bool equals(const object& obj) const noexcept;
70
73 virtual size_t get_hash_code() const noexcept;
74
80 virtual type_object get_type() const noexcept;
81
98 template<typename object_t>
99 xtd::uptr<object_t> memberwise_clone() const {
100 auto object_ptr = dynamic_cast<const object_t*>(this);
101 if (object_ptr == nullptr) __throw_invalid_cast_exception(__FILE__, __LINE__, __func__);
102 return xtd::new_uptr<object_t>(*object_ptr);
103 }
104
110 virtual xtd::string to_string() const noexcept;
112
114
123 template<typename object_a_t, typename object_b_t>
124 static bool equals(const object_a_t& object_a, const object_b_t& object_b) noexcept {
125 static_assert(std::is_base_of<xtd::object, object_a_t>::value, "object_a does not inherit from xtd::object");
126 static_assert(std::is_base_of<xtd::object, object_b_t>::value, "object_b does not inherit from xtd::object");
127 return object_a == object_b;
128 }
129
137 template<typename object_a_t, typename object_b_t>
138 static bool reference_equals(const object_a_t& object_a, const object_b_t& object_b) noexcept {
139 static_assert(std::is_base_of<xtd::object, object_a_t>::value, "object_a does not inherit from xtd::object");
140 static_assert(std::is_base_of<xtd::object, object_b_t>::value, "object_b does not inherit from xtd::object");
141 return &object_a == &object_b;
142 }
144
145 private:
146 void __throw_invalid_cast_exception(const string& file, uint32 line, const string& method) const;
147 };
148}
149
151std::ostream& operator <<(std::ostream& os, const xtd::object& obj) noexcept;
153
154#include "type.hpp"
155
156/*
159#if defined(__xtd__cpp_lib_format)
160template <>
161struct std::formatter<xtd::object> : std::formatter<std::string> {
162 template <typename object_t, typename format_context_t>
163 auto format(const object_t& obj, format_context_t& ctx) const {return std::format_to(ctx.out(), "{}", std::string {obj.to_string()});}
164};
165#endif
167*/
Contains string definitions.
Contains __xtd_std_version definitions.
Represents text as a sequence of character units.
Definition basic_string.hpp:79
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:42
virtual size_t get_hash_code() const noexcept
Serves as a hash function for a particular type.
virtual bool equals(const object &obj) const noexcept
Determines whether the specified object is equal to the current object.
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:138
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.
#define core_export_
Define shared library export.
Definition core_export.hpp:13
uint32_t uint32
Represents a 32-bit unsigned integer.
Definition uint32.hpp:23
std::unique_ptr< type_t > uptr
The xtd::uptr object is a unique pointer.
Definition uptr.hpp:25
Contains xtd::iequatable interface.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Contains xtd::type type.
Contains xtd fundamental types.