Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
ObjectsPair.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <alib/pair>
9#include <core/stringApi.hpp>
10
12
13namespace core {
14
15template<class FirstType, class SecondType >
16struct stringApi < std::pair < FirstType, SecondType > > {
17 static std::pair < FirstType, SecondType > parse ( ext::istream & input );
18 static bool first ( ext::istream & input );
19 static void compose ( ext::ostream & output, const std::pair < FirstType, SecondType > & container );
20};
21
22template<class FirstType, class SecondType >
23std::pair < FirstType, SecondType > stringApi < std::pair < FirstType, SecondType > >::parse ( ext::istream & input ) {
24 container::ContainerFromStringLexer::Token token = container::ContainerFromStringLexer::next ( input );
26 throw exception::CommonException("Expected PAIR_BEGIN token.");
27
28 FirstType firstObject = stringApi < FirstType >::parse ( input );
29
32 throw exception::CommonException("Excepted COMMA token.");
33
34 SecondType secondObject = stringApi < SecondType >::parse ( input );
35
38 throw exception::CommonException("Expected PAIR_END token.");
39
40 return std::make_pair ( std::move ( firstObject ), std::move ( secondObject ) );
41}
42
43template<class FirstType, class SecondType >
45 container::ContainerFromStringLexer::Token token = container::ContainerFromStringLexer::next ( input );
48 return res;
49}
50
51template<class FirstType, class SecondType >
52void stringApi < std::pair < FirstType, SecondType > >::compose ( ext::ostream & output, const std::pair < FirstType, SecondType > & container ) {
53 output << "(";
54
56
57 output << ", ";
58
60
61 output << ")";
62}
63
64template<class FirstType, class SecondType >
65struct stringApi < ext::pair < FirstType, SecondType > > {
67 static bool first ( ext::istream & input );
68 static void compose ( ext::ostream & output, const ext::pair < FirstType, SecondType > & container );
69};
70
71template<class FirstType, class SecondType >
73 std::pair < FirstType, SecondType > tmp = stringApi < std::pair < FirstType, SecondType > >::parse ( input );
74 return ext::make_pair ( tmp.first, tmp.second );
75}
76
77template<class FirstType, class SecondType >
80}
81
82template<class FirstType, class SecondType >
85}
86
87} /* namespace core */
88
static Token next(ext::istream &input)
Definition: ContainerFromStringLexer.cpp:10
Basic exception from which all other exceptions are derived.
Definition: CommonException.h:21
static void putback(ext::istream &input, const Token &token)
Definition: lexer.hpp:61
Definition: istream.h:32
Definition: ostream.h:14
Class extending the pair class from the standard library. Original reason is to allow printing of the...
Definition: pair.hpp:43
return res
Definition: MinimizeByPartitioning.h:145
Definition: ContainerFromStringLexer.cpp:8
Definition: normalize.hpp:10
Definition: sigHandler.cpp:20
constexpr auto make_pair(T1 &&x, T2 &&y)
Definition: pair.hpp:79
Definition: FordFulkerson.hpp:16
Definition: stringApi.hpp:26