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__
12#undef __XTD_CORE_INTERNAL__
14#include "core_export.hpp"
16#include "iequatable.hpp"
17#include "size.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 object(const object&) = default;
57 object& operator =(const object&) = default;
58 virtual ~object() = default;
59 bool operator ==(const object& obj) const noexcept;
60 bool operator !=(const object& obj) const noexcept;
62
64
72 virtual bool equals(const object& obj) const noexcept;
73
76 virtual xtd::size get_hash_code() const noexcept;
77
83 virtual type_object get_type() const noexcept;
84
101 template<class object_t>
102 xtd::unique_ptr_object<object_t> memberwise_clone() const;
103
109 virtual xtd::string to_string() const noexcept;
111
113
122 template<class object_a_t, class object_b_t>
123 inline static bool equals(const object_a_t& object_a, const object_b_t& object_b) noexcept {
124 static_assert(std::is_base_of<xtd::object, object_a_t>::value, "object_a does not inherit from xtd::object");
125 static_assert(std::is_base_of<xtd::object, object_b_t>::value, "object_b does not inherit from xtd::object");
126 return object_a == object_b;
127 }
128
136 template<class object_a_t, class object_b_t>
137 inline static bool reference_equals(const object_a_t& object_a, const object_b_t& object_b) noexcept {
138 static_assert(std::is_base_of<xtd::object, object_a_t>::value, "object_a does not inherit from xtd::object");
139 static_assert(std::is_base_of<xtd::object, object_b_t>::value, "object_b does not inherit from xtd::object");
140 return &object_a == &object_b;
141 }
142
143 };
144}
145
147std::ostream& operator <<(std::ostream& os, const xtd::object& obj) noexcept;
149
150#include "type.hpp"
151
152/*
155#if defined(__xtd__cpp_lib_format)
156template <>
157struct std::formatter<xtd::object> : std::formatter<std::string> {
158 template<class object_t, class format_context_t>
159 auto format(const object_t& obj, format_context_t& ctx) const {return std::format_to(ctx.out(), "{}", std::string {obj.to_string()});}
160};
161#endif
163*/
Contains string definitions.
Contains xtd::unique_ptr_object definition.
Contains __xtd_std_version definitions.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:45
virtual bool equals(const object &obj) const noexcept
Determines whether the specified object is equal to the current object.
virtual type_object get_type() const noexcept
Gets the type of the current instance.
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:137
xtd::unique_ptr_object< object_t > memberwise_clone() const
Creates a shallow copy of the current object.
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.
Contains generic stream output methods.
#define core_export_
Define shared library export.
Definition core_export.hpp:13
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 abstract_object.hpp:8
Contains xtd::helpers::throw_helper class.
Contains xtd::type type.
Contains xtd::size type.