ORIGINAL
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
original::iterationStream< TYPE, DERIVED > Class Template Reference

A stream class that allows iteration, comparison, hashing and printing. More...

#include <iterationStream.h>

Inheritance diagram for original::iterationStream< TYPE, DERIVED >:
Inheritance graph
Collaboration diagram for original::iterationStream< TYPE, DERIVED >:
Collaboration graph

Public Member Functions

integer compareTo (const iterationStream &other) const override
 Compares the current iteration stream with another iteration stream.
 
u_integer toHash () const noexcept override
 Computes a hash value for the iteration stream.
 
std::string className () const override
 Returns the class name.
 
std::string toString (bool enter) const override
 Converts the iteration stream to a string representation.
 
- Public Member Functions inherited from original::printable
 operator std::string () const
 Explicit conversion to std::string.
 
 operator const char * () const
 Explicit conversion to C-style string.
 
const chartoCString (bool enter) const
 Direct C-string access with formatting control.
 
template<typename TYPE >
auto formatString (const TYPE &t) -> std::string
 
template<typename TYPE >
auto formatCString (const TYPE &t) -> const char *
 
template<typename TYPE >
auto formatEnum (const TYPE &t) -> std::string
 
template<typename TYPE >
auto formatString (TYPE *const &ptr) -> std::string
 
- Public Member Functions inherited from original::iterable< TYPE >
iterAdaptor begin ()
 Returns an iterator adapter pointing to the beginning of the container.
 
iterAdaptor end ()
 Returns an iterator adapter pointing to the end sentinel of the container.
 
iterAdaptor begin () const
 Returns a const iterator adapter pointing to the beginning of the container.
 
iterAdaptor end () const
 Returns a const iterator adapter pointing to the end sentinel of the container.
 
iterAdaptor first ()
 Returns an iterator adapter pointing to the first element.
 
iterAdaptor last ()
 Returns an iterator adapter pointing to the last element.
 
iterAdaptor first () const
 Returns a const iterator adapter pointing to the first element.
 
iterAdaptor last () const
 Returns a const iterator adapter pointing to the last element.
 
virtual baseIterator< TYPE > * begins () const =0
 Returns the iterator to the beginning of the container.
 
virtual baseIterator< TYPE > * ends () const =0
 Returns the iterator to the end of the container.
 
template<typename Callback = transform<TYPE>>
requires Operation<Callback, TYPE>
void forEach (Callback operation=Callback{})
 Applies a given operation to each element in the iterable container.
 
template<typename Callback = transform<TYPE>>
requires Operation<Callback, TYPE>
void forEach (const Callback &operation=Callback{}) const
 Applies a given operation to each element in the iterable container (const version).
 
coroutine::generator< T > generator () const
 Creates a coroutine generator that yields elements from this container.
 
template<typename Callback >
requires original::Operation<Callback, TYPE>
auto forEach (Callback operation) -> void
 
template<typename Callback >
requires original::Operation<Callback, TYPE>
auto forEach (const Callback &operation) const -> void
 
- Public Member Functions inherited from original::comparable< iterationStream< TYPE, DERIVED > >
bool operator== (const iterationStream< TYPE, DERIVED > &other) const
 Checks if the current object is equal to another.
 
bool operator!= (const iterationStream< TYPE, DERIVED > &other) const
 Checks if the current object is not equal to another.
 
bool operator< (const iterationStream< TYPE, DERIVED > &other) const
 Checks if the current object is less than another.
 
bool operator> (const iterationStream< TYPE, DERIVED > &other) const
 Checks if the current object is greater than another.
 
bool operator<= (const iterationStream< TYPE, DERIVED > &other) const
 Checks if the current object is less than or equal to another.
 
bool operator>= (const iterationStream< TYPE, DERIVED > &other) const
 Checks if the current object is greater than or equal to another.
 
virtual ~comparable ()=default
 Virtual destructor for proper cleanup of derived objects.
 
- Public Member Functions inherited from original::hashable< iterationStream< TYPE, DERIVED > >
virtual bool equals (const iterationStream< TYPE, DERIVED > &other) const noexcept
 Compares two objects for equality.
 
virtual ~hashable ()=0
 Virtual destructor.
 

Protected Member Functions

std::string elementsString () const
 Returns a string representation of the elements in the stream.
 

Additional Inherited Members

- Public Types inherited from original::iterable< TYPE >
using T = std::remove_const_t< TYPE >
 
- Static Public Member Functions inherited from original::printable
template<typename TYPE >
static std::string formatString (const TYPE &t)
 Universal value-to-string conversion with type-specific formatting.
 
template<Printable TYPE>
static std::string formatString (const TYPE &t)
 Specialization for types deriving from printable.
 
template<EnumType TYPE>
static std::string formatString (const TYPE &t)
 Specialization for enum types with type-safe formatting.
 
template<typename TYPE >
static std::string formatString (TYPE *const &ptr)
 Pointer-specific formatting with null safety.
 
template<typename TYPE >
static const charformatCString (const TYPE &t)
 C-string cache for temporary usage with static storage.
 
template<typename TYPE >
static std::string formatEnum (const TYPE &t)
 Enum formatting utility with underlying value extraction.
 
template<>
auto formatString (const char &t) -> std::string
 
template<>
auto formatString (const bool &t) -> std::string
 
template<>
auto formatString (const char *const &ptr) -> std::string
 

Detailed Description

template<typename TYPE, typename DERIVED>
class original::iterationStream< TYPE, DERIVED >

A stream class that allows iteration, comparison, hashing and printing.

Template Parameters
TYPEThe type of elements contained in the stream.
DERIVEDThe derived class type using CRTP pattern.

This class provides a unified interface for streams that need to support:

The class uses CRTP to enable static polymorphism, allowing derived classes to inherit common functionality while maintaining their specific type identity.

Provides string conversion capabilities Provides element iteration support Enables stream comparison Provides hash computation

Note
Derived classes must implement the iterable interface methods (begins()/ends()) to provide actual element access.

Example usage:

class MyStream : public iterationStream<int, MyStream> {
// Implement begins()/ends() and other specific methods
};
if (stream1 == stream2) { ... } // Uses compareTo
auto hash = stream1.toHash(); // Uses element-based hashing
std::cout << stream1.toString(); // Formatted output
u_integer toHash() const noexcept override
Compute hash value for the pointer.
Definition autoPtr.h:735
std::string toString(bool enter) const override
String representation formatter.
Definition autoPtr.h:724
A stream class that allows iteration, comparison, hashing and printing.
Definition iterationStream.h:60
Unique ownership smart pointer with move semantics.
Definition ownerPtr.h:37

Member Function Documentation

◆ className()

template<typename TYPE , typename DERIVED >
auto original::iterationStream< TYPE, DERIVED >::className ( ) const
overridevirtual

◆ compareTo()

template<typename TYPE , typename DERIVED >
auto original::iterationStream< TYPE, DERIVED >::compareTo ( const iterationStream< TYPE, DERIVED > &  other) const
overridevirtual

Compares the current iteration stream with another iteration stream.

Parameters
otherAnother iteration stream to compare with.

Performs lexicographical comparison of the two streams:

  • Compares elements sequentially using their natural ordering
  • If TYPE is Comparable, uses element comparison operators
  • If elements are equal, continues to next elements
  • If one stream is a prefix of the other, the shorter stream is considered less
  • The comparison stops at the first unequal element
Returns
A value indicating the comparison result: -1 if the current stream is less than the other, 1 if greater, and 0 if equal.
Note
For non-Comparable TYPE, element comparison is not performed and only length comparison applies after exhausting equal elements.

Implements original::comparable< iterationStream< TYPE, DERIVED > >.

◆ elementsString()

template<typename TYPE , typename DERIVED >
auto original::iterationStream< TYPE, DERIVED >::elementsString ( ) const
protected

Returns a string representation of the elements in the stream.

This method iterates over all elements and formats them into a comma-separated list enclosed in parentheses. Each element is formatted using formatString function for consistent representation.

Example output: "(element1, element2, element3)"

Returns
A string that lists all elements in the stream in iteration order.
Note
Uses the iterable interface to traverse elements. Empty streams return "()".

◆ toHash()

template<typename TYPE , typename DERIVED >
original::u_integer original::iterationStream< TYPE, DERIVED >::toHash ( ) const
overridevirtualnoexcept

Computes a hash value for the iteration stream.

Returns
A hash value computed from all elements in the stream.

Uses hash combination algorithm to create a single hash value from all elements. The hash is computed by iterating through all elements and combining their individual hash values.

Note
Provides noexcept guarantee. For empty streams, returns 0.
Warning
Hash quality depends on the quality of hash<TYPE> specialization.

Reimplemented from original::hashable< iterationStream< TYPE, DERIVED > >.

◆ toString()

template<typename TYPE , typename DERIVED >
auto original::iterationStream< TYPE, DERIVED >::toString ( bool  enter) const
overridevirtual

Converts the iteration stream to a string representation.

Parameters
enterWhether to add a newline at the end of the string.

This method returns a string containing the class name followed by a string representation of the stream elements in parentheses. An optional newline character can be appended based on the enter parameter.

Example output with enter=true: "iterationStream(element1, element2)\n"

Returns
A complete string representation of the stream including class name and formatted elements.

Reimplemented from original::printable.


The documentation for this class was generated from the following file: