ORIGINAL
Loading...
Searching...
No Matches
iterationStream.h
Go to the documentation of this file.
1#ifndef ITERATIONSTREAM_H
2#define ITERATIONSTREAM_H
3
4#include <sstream>
5#include "comparable.h"
6#include "hash.h"
7#include "printable.h"
8#include "iterable.h"
9#include "types.h"
10
21namespace original {
56 template<typename TYPE, typename DERIVED>
57 class iterationStream : public printable,
58 public iterable<TYPE>,
59 public comparable<iterationStream<TYPE, DERIVED>>,
60 public hashable<iterationStream<TYPE, DERIVED>> {
61 protected:
74 [[nodiscard]] std::string elementsString() const;
75
76 public:
93 integer compareTo(const iterationStream &other) const override;
94
106
113
127 };
128}
129
132{
133 std::stringstream ss;
134 ss << "(";
135 bool first = true;
136 for (const auto it = this->begin(); it.isValid(); ++it) {
137 if (!first) {
138 ss << ", ";
139 }
140 ss << formatString(it.get());
141 first = false;
142 }
143 ss << ")";
144 return ss.str();
145}
146
147template<typename TYPE, typename DERIVED>
149 const auto this_it = this->begin();
150 const auto other_it = other.begin();
151 for (; this_it.isValid() && other_it.isValid(); ++this_it, ++other_it) {
152 if constexpr (Comparable<TYPE>){
153 if (*this_it != *other_it)
154 return *this_it < *other_it ? -1 : 1;
155 }
156 }
157 return this_it.isValid() - other_it.isValid();
158}
159
160template <typename TYPE, typename DERIVED>
169
170template<typename TYPE, typename DERIVED>
172 return "iterationStream";
173}
174
175template<typename TYPE, typename DERIVED>
177{
178 std::stringstream ss;
179 ss << this->className() << this->elementsString();
180 if (enter) ss << "\n";
181 return ss.str();
182}
183
184#endif //ITERATIONSTREAM_H
const TYPE * get() const
Get managed pointer const version.
Definition autoPtr.h:629
Base class for comparable objects.
Definition comparable.h:35
static void hashCombine(u_integer &seed, const T &value) noexcept
Combines a hash value with another value's hash.
Definition hash.h:275
Forward declaration of hashable interface template.
Definition hash.h:220
A base class for iterable containers that support multiple iteration patterns.
Definition iterable.h:70
iterAdaptor first()
Returns an iterator adapter pointing to the first element.
Definition iterable.h:650
iterAdaptor begin()
Returns an iterator adapter pointing to the beginning of the container.
Definition iterable.h:626
A stream class that allows iteration, comparison, hashing and printing.
Definition iterationStream.h:60
u_integer toHash() const noexcept override
Computes a hash value for the iteration stream.
Definition iterationStream.h:161
std::string elementsString() const
Returns a string representation of the elements in the stream.
Definition iterationStream.h:131
integer compareTo(const iterationStream &other) const override
Compares the current iteration stream with another iteration stream.
Definition iterationStream.h:148
std::string className() const override
Returns the class name.
Definition iterationStream.h:171
std::string toString(bool enter) const override
Converts the iteration stream to a string representation.
Definition iterationStream.h:176
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:37
Base class providing polymorphic string conversion capabilities.
Definition printable.h:39
static std::string formatString(const TYPE &t)
Universal value-to-string conversion with type-specific formatting.
Definition printable.h:339
Interface for objects that can be compared.
Definition types.h:157
std::uint32_t u_integer
32-bit unsigned integer type for sizes and indexes
Definition config.h:263
std::int64_t integer
64-bit signed integer type for arithmetic operations
Definition config.h:254
Provides a generic hashing utility and interface for hashable types.
Base interface for iterable container types.
Main namespace for the project Original.
Definition algorithms.h:21
Standard namespace extensions for original::alternative.
Definition allocator.h:351
Interface for polymorphic string formatting and output.
Core type system foundations and concept definitions.