-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterface.hpp
More file actions
85 lines (71 loc) · 2.31 KB
/
interface.hpp
File metadata and controls
85 lines (71 loc) · 2.31 KB
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
/*****************************************************************//**
* \file interface.hpp
* \brief Declaration of interface Printable and Uncopyable.
*
* $ g++ -c interface.hpp -std=c++2a
* [[optional]] $ g++ -c interface.hpp -save-temps -std=c++2a
*
* \author Xuhua Huang (xuhua.huang.io@gmail.com)
* \date September 25, 2022
*********************************************************************/
#ifndef INTERFACE_HPP
#define INTERFACE_HPP
#ifndef _IOSTREAM_
#include <iostream>
#endif
#ifndef _STRING_
#include <string>
#endif
/**
* preprocessing directive below requires gcc 12.0 and standard C++23
* https://en.cppreference.com/w/cpp/preprocessor/conditional
*/
// #ifndef _IOSTREAM_
// #include <iostream>
// #elifndef _STRING_
// #include <string>
// #endif
namespace util {
namespace interface {
class Uncopyable;
template <typename T>
class Comparable {
public:
Comparable() = default;
virtual ~Comparable() = default;
protected:
virtual bool operator<(const Comparable&) = 0;
virtual bool operator<=(const Comparable&) = 0;
virtual bool operator==(const Comparable&) = 0;
virtual bool operator>(const Comparable&) = 0;
virtual bool operator>=(const Comparable&) = 0;
};
class Printable {
public:
inline virtual std::string getClassName() = 0;
inline virtual std::string getClassName() const = 0;
virtual ~Printable() = default;
};
inline void print_class_name(Printable* const printable) {
std::cout << "util::interface::print_class_name(): " << __FILE__ << " " << __LINE__ << printable->getClassName()
<< "\n";
}
class Uncopyable {
protected:
// allow construction and destruction of derived class objects
Uncopyable() = default;
virtual ~Uncopyable() = default;
private:
// compiler sees these function, will attempt to call
// declared as private, will not be called succesfully
Uncopyable(const Uncopyable&) {}
Uncopyable(Uncopyable&&) noexcept {}
Uncopyable(const Uncopyable&&) noexcept {}
Uncopyable& operator=(const Uncopyable&) {}
Uncopyable& operator=(Uncopyable&&) noexcept {}
Uncopyable& operator=(const Uncopyable&&) noexcept {}
bool operator==(const Uncopyable&) {}
};
} // namespace interface
} // namespace util
#endif // INTERFACE_HPP