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