-
Notifications
You must be signed in to change notification settings - Fork 0
/
ptr.hpp
146 lines (105 loc) · 3.16 KB
/
ptr.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#ifndef DCDEVELOP_PTR_CLASS
#define DCDEVELOP_PTR_CLASS
#include <stddef.h>
// #define DCDEVELOP_PTR_CLASS_CSTRING
#ifdef DCDEVELOP_PTR_CLASS_CSTRING
#include <cstring>
#endif
namespace dcdevelop {
namespace parent {
template <typename T>
class ptr {
protected:
T* raw_pointer;
public:
ptr();
ptr(T* pointer);
explicit ptr(T& reference);
T* addr();
inline T* address();
operator T*();
T& deref();
inline T& dereference();
explicit operator T&();
template <typename Result>
Result& map(Result& (*fp)(T value));
template <typename Result>
Result& map_with_default(Result& (*fp)(T value), Result& default_value);
bool is_null();
void set_null();
ptr<T> operator+(ptrdiff_t number);
ptr<T> next();
ptr<T>& operator++();
ptr<T> operator++(int);
template <typename IncrementType>
void operator+=(IncrementType number);
ptrdiff_t operator-(const ptr<T>& other_ptr);
ptrdiff_t operator-(T* other_pointer);
ptr<T> operator-(ptrdiff_t number);
ptr<T> prev();
ptr<T>& operator--();
ptr<T> operator--(int);
template <typename DecrementType>
void operator-=(DecrementType number);
bool operator==(T*& compareTo);
bool operator==(ptr<T>& compareTo);
template <typename EqualType>
bool operator==(EqualType& compareTo);
template <typename EqualType>
bool operator!=(EqualType& compareTo);
template <typename ComparisonType>
bool operator>(ComparisonType& compareTo);
bool operator>(ptr<T>& compareTo);
template <typename ComparisonType>
bool operator>=(ComparisonType& compareTo);
template <typename ComparisonType>
bool operator<(ComparisonType& compareTo);
template <typename ComparisonType>
bool operator<=(ComparisonType& compareTo);
};
}
template <typename T>
class ptr : public parent::ptr<T> {
using parent::ptr<T>::ptr;
};
template<>
class ptr<char> : public parent::ptr<char> {
using parent::ptr<char>::ptr;
public:
inline char* cstring();
inline bool is_empty();
#ifdef DCDEVELOP_PTR_CLASS_CSTRING
bool operator==(const char*& compareTo);
bool operator==(const ptr<char>& compareTo);
bool operator>(const char*& compareTo);
void copy_to(char* destination);
inline void copy_to(ptr<char>& destination);
void replace_with(char* source);
inline void replace_with(ptr<char>& source);
void append(char* source);
inline void append(const ptr<char>& source);
inline void concat(char* source);
inline void concat(const ptr<char>& source);
ptr<char> find(char character);
ptr<char> find(const char*& cstring);
inline ptr<char> find(const ptr<char>& cstring);
ptr<char> find_any(const char*& cstring);
inline ptr<char> find_any(const ptr<char>& cstring);
ptr<char> find_last(char character);
size_t span_until(const char*& cstring);
size_t span_until(const ptr<char>& cstring);
size_t span_containing(const char*& cstring);
size_t span_containing(const ptr<char>& cstring);
size_t length();
#endif
};
#ifdef DCDEVELOP_PTR_CLASS_CSTRING
class ptr_char_raw : public parent::ptr<char> {
using parent::ptr<char>::ptr;
};
#else
typedef ptr<char> ptr_char_raw;
#endif
}
#include "ptr.cpp"
#endif