xtd 0.2.0
Loading...
Searching...
No Matches
object.h
Go to the documentation of this file.
1
4#pragma once
5#include "core_export.h"
6#include "iequatable.h"
7#include "types.h"
8#include <string>
9#include <memory>
10
12namespace xtd {
14 class type_object;
15 class ustring;
17
33 public:
35
39 object() = default;
41
43 object(const object&) = default;
44 object& operator =(const object&) = default;
45 virtual ~object() = default;
46 friend bool operator ==(const object& a, const object& b) noexcept {return a.equals(b);}
47 friend bool operator !=(const object& a, const object& b) noexcept {return !a.equals(b);}
48 template<typename object_t>
49 friend bool operator ==(const iequatable<object_t>& a, const iequatable<object_t>& b) noexcept {return dynamic_cast<const iequatable<object_t>*>(&b) && a.equals(dynamic_cast<const iequatable<object_t>&>(b));}
50 template<typename object_t>
51 friend bool operator !=(const iequatable<object_t>& a, const iequatable<object_t>& b) noexcept {return !dynamic_cast<const iequatable<object_t>*>(&b) || !a.equals(dynamic_cast<const iequatable<object_t>&>(b));}
53
55
63 bool equals(const object& obj) const noexcept;
64
67 virtual size_t get_hash_code() const noexcept;
68
74 virtual type_object get_type() const noexcept;
75
89 template<typename object_t>
90 std::unique_ptr<object_t> memberwise_clone() const noexcept {return std::make_unique<object_t>(dynamic_cast<const object_t&>(*this));}
91
97 virtual xtd::ustring to_string() const noexcept;
99
101
110 static bool equals(const object& object_a, const object& object_b) noexcept;
111
119 static bool reference_equals(const object& object_a, const object& object_b) noexcept;
121
123 template<typename object_t>
124 bool equals(const iequatable<object_t>& obj) const noexcept {
125 if (dynamic_cast<const iequatable<object_t>*>(this)) return dynamic_cast<const iequatable<object_t>*>(this)->equals(obj);
126 return this == &obj;
127 }
128
129 template<typename object_t>
130 static bool equals(const iequatable<object_t>& object_a, const iequatable<object_t>& object_b) noexcept {
131 return object_a.equals(object_b);
132 }
134 };
135
137 std::ostream& operator <<(std::ostream& os, const object& obj) noexcept;
139}
140
141#include "type.h"
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
virtual size_t get_hash_code() const noexcept
Serves as a hash function for a particular type.
virtual xtd::ustring to_string() const noexcept
Returns a sxd::ustring that represents the current object.
bool equals(const object &obj) const noexcept
Determines whether the specified object is equal to the current object.
object()=default
Create a new instance of the ultimate base class object.
Represents type declarations: class types, interface types, array types, value types,...
Definition type_object.h:36
Represents text as a sequence of UTF-8 code units.
Definition ustring.h:47
Contains core_export_ keyword.
#define core_export_
Define shared library export.
Definition core_export.h:13
@ a
The A key.
@ b
The B key.
Contains xtd::iequatable interface.
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Contains xtd::size type and xtd::size_object alias.
Contains xtd fundamental types.