xtd 0.2.0
object.h
Go to the documentation of this file.
1 #pragma once
5 #include "core_export.h"
6 #include "iequatable.h"
7 #include "types.h"
8 #include <string>
9 #include <memory>
10 
12 namespace xtd {
14  class type_object;
15  class ustring;
17 
32  class core_export_ object {
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 
72  static bool equals(const object& object_a, const object& object_b) noexcept;
73 
76  virtual size_t get_hash_code() const noexcept;
77 
83  virtual type_object get_type() const noexcept;
84 
90  template<typename object_t>
91  std::unique_ptr<object_t> memberwise_clone() const noexcept {return std::make_unique<object_t>(dynamic_cast<const object_t&>(*this));}
92 
100  static bool reference_equals(const object& object_a, const object& object_b) noexcept;
101 
107  virtual xtd::ustring to_string() const noexcept;
109 
111  template<typename object_t>
112  bool equals(const iequatable<object_t>& obj) const noexcept {
113  if (dynamic_cast<const iequatable<object_t>*>(this)) return dynamic_cast<const iequatable<object_t>*>(this)->equals(obj);
114  return this == &obj;
115  }
116 
117  template<typename object_t>
118  static bool equals(const iequatable<object_t>& object_a, const iequatable<object_t>& object_b) noexcept {
119  return object_a.equals(object_b);
120  }
122  };
123 
125  std::ostream& operator <<(std::ostream& os, const object& obj) noexcept;
127 }
128 
129 #include "type.h"
Contains xtd fundamental types.
std::unique_ptr< object_t > memberwise_clone() const noexcept
Creates a shallow copy of the current object.
Definition: object.h:91
virtual bool equals(const type_t &) const noexcept=0
Indicates whether the current object is equal to another object of the same type. ...
Contains xtd::iequatable interface.
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
std::string to_string(const date_time &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition: date_time.h:1063
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: iequatable.h:18
bool equals(const object &obj) const noexcept
Determines whether the specified object is equal to the current object.
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes...
Definition: object.h:32
Represents type declarations: class types, interface types, array types, value types, enumeration types, type parameters, generic type definitions, and open or closed constructed generic types.
Definition: type_object.h:36
Contains xtd::size type and xtd::size_object alias.