Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
CommonSupportStream.h
1// trax track library
2// AD 2021
3//
4// "the resolution of all the fruitless searches"
5//
6// Peter Gabriel
7//
8// Copyright (c) 2025 Trend Redaktions- und Verlagsgesellschaft mbH
9// Copyright (c) 2019 Marc-Michael Horstmann
10//
11// Permission is hereby granted to any person obtaining a copy of this software
12// and associated source code (the "Software"), to use, view, and study the
13// Software for personal or internal business purposes, subject to the following
14// conditions:
15//
16// 1. Redistribution, modification, sublicensing, or commercial use of the
17// Software is NOT permitted without prior written consent from the copyright
18// holder.
19//
20// 2. The Software is provided "AS IS", without warranty of any kind, express
21// or implied.
22//
23// 3. All copies of the Software must retain this license notice.
24//
25// For further information, please contact: horstmann.marc@trendverlag.de
26
27#pragma once
28
29#include "../Interval.h"
30
31#include <iostream>
32
33namespace common{
34
37
41
44 template<typename Valtype>
45 std::ostream& operator << ( std::ostream& os, const common::Interval<Valtype>& i );
46
49 template<typename Valtype>
50 std::istream& operator >> ( std::istream& is, common::Interval<Valtype>& i );
52
53
54
55template<typename Valtype> inline
56std::ostream& operator << ( std::ostream& os, const common::Interval<Valtype>& i ){
57 os << "Interval( " << i.Near() << ", " << i.Far() << " )";
58 return os;
59}
60
61inline void StreamInHead( std::istream& is, const std::string& head ){
62 std::string token;
63 std::getline( is, token, '(' );
64 token.erase( std::remove_if( token.begin(), token.end(), [](unsigned char x) { return std::isspace(x); }), token.end() );
65 if( token != head ){
66 is.setstate( std::ios_base::failbit );
67 throw std::runtime_error( "Stream in head: " + token + " is not " + head );
68 }
69}
70
71template<typename Valtype> inline
72std::istream& operator >> ( std::istream& is, common::Interval<Valtype>& i )
73{
74 StreamInHead( is, "Interval" );
75
76 char c;
77 is >> i.m_Near;
78 is >> c; assert( c == ',' );
79 is >> i.m_Far;
80 is >> c; assert( c == ')' );
81 return is;
82}
83
84}
std::istream & operator>>(std::istream &is, common::Interval< Valtype > &i)
Streams Interval data in.
Definition CommonSupportStream.h:72
Namespace of common utility classes and methods.
Definition Helpers.h:43
An interval describes the area between two numbers. It is understood to contain the near one and exlu...
Definition Interval.h:42
constexpr Valtype Near() const noexcept
Definition Interval.h:381
constexpr Valtype Far() const noexcept
Definition Interval.h:386
Valtype m_Far
The 'right' side of the interval; usually the bigger value.
Definition Interval.h:45
Valtype m_Near
The 'left' side of the interval; usually the smaller value.
Definition Interval.h:44