mn_any_ptr.hpp
Go to the documentation of this file.
1 /*
2 *This file is part of the Mini Thread Library (https://github.com/RoseLeBlood/MiniThread ).
3 *Copyright (c) 2021 Amber-Sophia Schroeck
4 *
5 *The Mini Thread Library is free software; you can redistribute it and/or modify
6 *it under the terms of the GNU Lesser General Public License as published by
7 *the Free Software Foundation, version 3, or (at your option) any later version.
8 
9 *The Mini Thread Library is distributed in the hope that it will be useful, but
10 *WITHOUT ANY WARRANTY; without even the implied warranty of
11 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 *General Public License for more details.
13 *
14 *You should have received a copy of the GNU Lesser General Public
15 *License along with the Mini Thread Library; if not, see
16 *<https://www.gnu.org/licenses/>.
17 */
18 #ifndef MINLIB_de6432e5_32f4_4ce2_bec3_0a8f4e20a0f4_H_
19 #define MINLIB_de6432e5_32f4_4ce2_bec3_0a8f4e20a0f4_H_
20 
21 #include "../mn_config.hpp"
22 
23 #include "../mn_def.hpp"
24 
25 namespace mn {
26  namespace pointer {
27 
28  template <typename T>
29  class basic_any_ptr {
30  public:
31  using element_type = T;
32  using size_type = size_t;
33  using pointer = T*;
34  using const_pointer = const T*;
36 
37  // Default Constructor
38 
42  basic_any_ptr() : m_pObject(nullptr) { }
47  : m_pObject( const_cast<const_pointer>(m_pObject) ) { }
48 
53  : m_pObject( const_cast<const_pointer>(other.m_pObject) ) { }
54 
60  template <typename U>
62  : m_pObject( const_cast<const_pointer>(other.m_pObject) ) { }
63 
69  const self_type& operator = (const self_type &other) {
70  m_pObject = const_cast<const_pointer>(other.m_pObject);
71  return *this;
72  }
73 
80  template <class U>
81  const self_type &operator = (const basic_any_ptr<U> &other) {
82  m_pObject = const_cast<const_pointer>(other.m_pObject); return *this;
83  }
84 
88  template <class U>
89  const self_type& operator = (const U* pObject) {
90  m_pObject = const_cast<const_pointer>(m_pObject);
91  return (*this);
92  }
93 
97  operator const_pointer() { return static_cast<T*>( m_pObject ); }
98 
99 
103  template <class U>
104  operator const U*() { return static_cast<U*>( m_pObject ); }
105 
111  bool is_null() { return (m_pObject == 0); }
112 
113  private:
115  };
116 
118  }
119 }
120 
121 #endif
Definition: mn_any_ptr.hpp:29
bool is_null()
Is the pointer null.
Definition: mn_any_ptr.hpp:111
const self_type & operator=(const self_type &other)
Assignment Operator.
Definition: mn_any_ptr.hpp:69
size_t size_type
Definition: mn_any_ptr.hpp:32
T * pointer
Definition: mn_any_ptr.hpp:33
basic_any_ptr(const_pointer pObject)
Construct a new basic any ptr object.
Definition: mn_any_ptr.hpp:46
const T * const_pointer
Definition: mn_any_ptr.hpp:34
const_pointer m_pObject
Definition: mn_any_ptr.hpp:114
basic_any_ptr(const basic_any_ptr &other)
Construct a new basic any ptr object from a copy.
Definition: mn_any_ptr.hpp:52
basic_any_ptr()
Construct a new basic any ptr object.
Definition: mn_any_ptr.hpp:42
basic_any_ptr(const basic_any_ptr< U > &other)
Construct a new basic any ptr object from a copy.
Definition: mn_any_ptr.hpp:61
T element_type
Definition: mn_any_ptr.hpp:31
struct mn::memory::detail::ptr_difference T
Definition: mn_atomic_singleton.hpp:38
Definition: mn_allocator_typetraits.hpp:25
MN_THREAD_CONFIG_SIZE_TYPE size_t
Definition: mn_def.hpp:48