Algorithms Library Toolkit
A toolkit for algorithms, especially for algorithms on formal languages
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Concepts
ObjectsVariant.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <alib/variant>
9#include <core/stringApi.hpp>
10
11namespace core {
12
13template < class ... Types >
14struct stringApi < ext::variant < Types ... > > {
15 static ext::variant < Types ... > parse ( ext::istream & input );
16 static bool first ( ext::istream & input );
17 static void compose ( ext::ostream & output, const ext::variant < Types ... > & container );
18
19private:
20 class VariantStringApiCallback {
21 ext::ostream & m_out;
22
23 public:
24 VariantStringApiCallback ( ext::ostream & out ) : m_out ( out ) {
25 }
26
27 template < class ValueType >
28 void operator ( ) ( const ValueType & value ) {
29 stringApi < ValueType >::compose ( m_out, value );
30 }
31 };
32
33 template < class T, class R, class ... Ts >
34 static ext::variant < Types ... > parse ( ext::istream & input ) {
35 if ( stringApi < T >::first ( input ) )
36 return ext::variant < Types ... > ( stringApi < T >::parse ( input ) );
37 else
38 return parse < R, Ts ... > ( input );
39 }
40
41 template < class T >
42 static ext::variant < Types ... > parse ( ext::istream & input ) {
43 return ext::variant < Types ... > ( stringApi < T >::parse ( input ) );
44 }
45};
46
47template < class ... Types >
48ext::variant < Types ... > stringApi < ext::variant < Types ... > >::parse ( ext::istream & input ) {
49 return parse < Types ... > ( input );
50}
51
52template < class ... Types >
53bool stringApi < ext::variant < Types ... > >::first ( ext::istream & input ) {
54 return ( ... && stringApi < Types >::first ( input ) );
55}
56
57template < class ... Types >
58void stringApi < ext::variant < Types ... > >::compose ( ext::ostream & output, const ext::variant < Types ... > & container ) {
59 ext::visit ( VariantStringApiCallback ( output ), container );
60}
61
62} /* namespace core */
63
Definition: istream.h:32
Definition: ostream.h:14
Implementation of the variant class allowing to store any type of those listed in the template parame...
Definition: variant.hpp:98
Definition: ContainerFromStringLexer.cpp:8
Definition: normalize.hpp:10
Definition: sigHandler.cpp:20
constexpr auto visit(Visitor &&vis, Variants &&... vars)
Definition: variant.hpp:42
static bool first(ext::istream &input)
static ext::variant< Types ... > parse(ext::istream &input)
static void compose(ext::ostream &output, const ext::variant< Types ... > &container)
Definition: stringApi.hpp:26