ORIGINAL
Loading...
Searching...
No Matches
iterationStream.h
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
10namespace original{
11 template<typename TYPE, typename DERIVED>
12 class iterationStream : public printable, public iterable<TYPE>, public comparable<iterationStream<TYPE, DERIVED>>{
13 protected:
14 [[nodiscard]] std::string elementsString() const;
15 public:
16 int compareTo(const iterationStream& other) const override;
17 [[nodiscard]] std::string className() const override;
18 [[nodiscard]] std::string toString(bool enter) const override;
19 };
20}
21
22 template<typename TYPE, typename DERIVED>
23 auto original::iterationStream<TYPE, DERIVED>::elementsString() const -> std::string
24 {
25 std::stringstream ss;
26 ss << "(";
27 bool first = true;
28 for (const auto it = this->begin(); it.isValid(); ++it) {
29 if (!first) {
30 ss << ", ";
31 }
32 ss << formatString(it.get());
33 first = false;
34 }
35 ss << ")";
36 return ss.str();
37 }
38
39 template<typename TYPE, typename DERIVED>
40 auto original::iterationStream<TYPE, DERIVED>::compareTo(const iterationStream &other) const -> int {
41 const auto this_it = this->begin();
42 const auto other_it = other.begin();
43 for (;this_it.isValid() && other_it.isValid(); ++this_it, ++other_it) {
44 if (*this_it != *other_it)
45 return *this_it < *other_it ? -1 : 1;
46 }
47 return this_it.isValid() - other_it.isValid();
48 }
49
50 template<typename TYPE, typename DERIVED>
51 auto original::iterationStream<TYPE, DERIVED>::className() const -> std::string {
52 return "iterationStream";
53 }
54
55 template<typename TYPE, typename DERIVED>
56 auto original::iterationStream<TYPE, DERIVED>::toString(const bool enter) const -> std::string
57 {
58 std::stringstream ss;
59 ss << this->className() << this->elementsString();
60 if (enter) ss << "\n";
61 return ss.str();
62 }
63
64#endif //ITERATIONSTREAM_H
Definition comparable.h:6
Definition iterable.h:10
Definition iterationStream.h:12
Definition printable.h:9