xtd 0.2.0
object.h
Go to the documentation of this file.
1 #pragma once
5 #include <string>
6 #include <memory>
7 #include "core_export.h"
8 #include "iequatable.h"
9 #include "types.h"
10 
12 namespace xtd {
14  class ustring;
16 
31  class core_export_ object {
32  public:
34 
38  object() = default;
40 
42  object(const object&) = default;
43  object& operator =(const object&) = default;
44  virtual ~object() = default;
45  friend bool operator ==(const object& a, const object& b) noexcept {return a.equals(b);}
46  friend bool operator !=(const object& a, const object& b) noexcept {return !a.equals(b);}
47  template<typename object_t>
48  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));}
49  template<typename object_t>
50  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));}
52 
54 
62  bool equals(const object& obj) const noexcept;
63 
71  static bool equals(const object& object_a, const object& object_b) noexcept;
72 
75  virtual size_t get_hash_code() const noexcept;
76 
82  //virtual type get_type() const;
83 
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 
99  static bool reference_equals(const object& object_a, const object& object_b) noexcept;
100 
106  virtual xtd::ustring to_string() const noexcept;
108 
110  template<typename object_t>
111  bool equals(const iequatable<object_t>& obj) const noexcept {
112  if (dynamic_cast<const iequatable<object_t>*>(this)) return dynamic_cast<const iequatable<object_t>*>(this)->equals(obj);
113  return this == &obj;
114  }
115 
116  template<typename object_t>
117  static bool equals(const iequatable<object_t>& object_a, const iequatable<object_t>& object_b) noexcept {
118  return object_a.equals(object_b);
119  }
121  };
122 
124  std::ostream& operator <<(std::ostream& os, const object& obj) noexcept;
126 }
Contains xtd fundamental types.
std::unique_ptr< object_t > memberwise_clone() const noexcept
Gets the type of the current instance.
Definition: object.h:90
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:48
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:1098
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:31