tetengo 1.8.2
A multipurpose library set
Loading...
Searching...
No Matches
input.hpp
Go to the documentation of this file.
1
7#if !defined(TETENGO_LATTICE_INPUT_HPP)
8#define TETENGO_LATTICE_INPUT_HPP
9
10#include <cassert>
11#include <cstddef>
12#include <memory>
13
14#include <boost/core/noncopyable.hpp>
15#include <boost/operators.hpp>
16
17
18namespace tetengo::lattice
19{
23 class input : public boost::equality_comparable<input>, private boost::noncopyable
24 {
25 public:
26 // constructors
27
31 virtual ~input();
32
33
34 // functions
35
45 friend bool operator==(const input& one, const input& another);
46
52 [[nodiscard]] std::size_t hash_value() const;
53
59 [[nodiscard]] std::size_t length() const;
60
66 [[nodiscard]] std::unique_ptr<input> clone() const;
67
78 [[nodiscard]] std::unique_ptr<input> create_subrange(std::size_t offset, std::size_t length) const;
79
87 void append(std::unique_ptr<input>&& p_another);
88
97 template <typename C>
98 [[nodiscard]] bool is() const
99 {
100 return dynamic_cast<const C*>(this);
101 }
102
110 template <typename C>
111 [[nodiscard]] const C& as() const
112 {
113 assert(is<C>());
114 return static_cast<const C&>(*this);
115 }
116
124 template <typename C>
125 [[nodiscard]] C& as()
126 {
127 assert(is<C>());
128 return static_cast<C&>(*this);
129 }
130
131
132 private:
133 // virtual functions
134
135 virtual bool equal_to_impl(const input& another) const = 0;
136
137 virtual std::size_t hash_value_impl() const = 0;
138
139 virtual std::size_t length_impl() const = 0;
140
141 virtual std::unique_ptr<input> clone_impl() const = 0;
142
143 virtual std::unique_ptr<input> create_subrange_impl(std::size_t offset, std::size_t length) const = 0;
144
145 virtual void append_impl(std::unique_ptr<input>&& p_another) = 0;
146 };
147
148
149}
150
151
152#endif
An input.
Definition input.hpp:24
const C & as() const
Casts this object to the specified concrete input.
Definition input.hpp:111
void append(std::unique_ptr< input > &&p_another)
Appends another input.
friend bool operator==(const input &one, const input &another)
Returns true if one input is equal to another.
C & as()
Casts this object to the specified concrete input.
Definition input.hpp:125
bool is() const
Returns true when this object can be casted to the specified concrete input.
Definition input.hpp:98
std::size_t hash_value() const
Returns the hash value.
std::unique_ptr< input > create_subrange(std::size_t offset, std::size_t length) const
Creates a subrange.
virtual ~input()
Destroys the input.
std::size_t length() const
Returns the length.
std::unique_ptr< input > clone() const
Clone this input.
A lattice library.