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
6#include "comparable.h"
7#include "printable.h"
8#include "iterable.h"
9#include "types.h"
10
18
19namespace original {
32 template<typename TYPE, typename DERIVED>
33 class iterationStream : public printable, public iterable<TYPE>, public comparable<iterationStream<TYPE, DERIVED>> {
34 protected:
40 [[nodiscard]] std::string elementsString() const;
41
42 public:
53 integer compareTo(const iterationStream &other) const override;
54
60 [[nodiscard]] std::string className() const override;
61
70 [[nodiscard]] std::string toString(bool enter) const override;
71 };
72}
73
74template<typename TYPE, typename DERIVED>
76{
77 std::stringstream ss;
78 ss << "(";
79 bool first = true;
80 for (const auto it = this->begin(); it.isValid(); ++it) {
81 if (!first) {
82 ss << ", ";
83 }
84 ss << formatString(it.get());
85 first = false;
86 }
87 ss << ")";
88 return ss.str();
89}
90
91template<typename TYPE, typename DERIVED>
93 const auto this_it = this->begin();
94 const auto other_it = other.begin();
95 for (; this_it.isValid() && other_it.isValid(); ++this_it, ++other_it) {
96 if constexpr (Comparable<TYPE>){
97 if (*this_it != *other_it)
98 return *this_it < *other_it ? -1 : 1;
99 }
100 }
101 return this_it.isValid() - other_it.isValid();
102}
103
104template<typename TYPE, typename DERIVED>
106 return "iterationStream";
107}
108
109template<typename TYPE, typename DERIVED>
110auto original::iterationStream<TYPE, DERIVED>::toString(const bool enter) const -> std::string
111{
112 std::stringstream ss;
113 ss << this->className() << this->elementsString();
114 if (enter) ss << "\n";
115 return ss.str();
116}
117
118#endif //ITERATIONSTREAM_H
Base class for comparable objects.
Definition comparable.h:31
A base class for iterable containers that support iterators.
Definition iterable.h:32
iterAdaptor first()
Returns an iterator pointing to the first element.
Definition iterable.h:472
iterAdaptor begin()
Returns an iterator pointing to the beginning of the iterable container.
Definition iterable.h:448
A stream class that allows iteration, comparison, and printing.
Definition iterationStream.h:33
std::string elementsString() const
Returns a string representation of the elements in the stream.
Definition iterationStream.h:75
integer compareTo(const iterationStream &other) const override
Compares the current iteration stream with another iteration stream.
Definition iterationStream.h:92
std::string className() const override
Returns the class name.
Definition iterationStream.h:105
std::string toString(bool enter) const override
Converts the iteration stream to a string representation.
Definition iterationStream.h:110
Base class providing polymorphic string conversion capabilities.
Definition printable.h:25
static std::string formatString(const TYPE &t)
Universal value-to-string conversion.
Interface for objects that can be compared.
Requires type to support all comparison operators.
Definition types.h:29
Base interface for iterable container types.
Main namespace for the project Original.
Definition algorithms.h:21
std::int64_t integer
64-bit signed integer type for arithmetic operations
Definition config.h:15
Interface for polymorphic string formatting and output.
Type system foundations and concept definitions.