Multiscale Universal Interface  2.0
A Concurrent Framework for Coupling Heterogeneous Solvers
stream_tuple.h
Go to the documentation of this file.
1 /*****************************************************************************
2 * Multiscale Universal Interface Code Coupling Library *
3 * *
4 * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis *
5 * *
6 * This software is jointly licensed under the Apache License, Version 2.0 *
7 * and the GNU General Public License version 3, you may use it according *
8 * to either. *
9 * *
10 * ** Apache License, version 2.0 ** *
11 * *
12 * Licensed under the Apache License, Version 2.0 (the "License"); *
13 * you may not use this file except in compliance with the License. *
14 * You may obtain a copy of the License at *
15 * *
16 * http://www.apache.org/licenses/LICENSE-2.0 *
17 * *
18 * Unless required by applicable law or agreed to in writing, software *
19 * distributed under the License is distributed on an "AS IS" BASIS, *
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
21 * See the License for the specific language governing permissions and *
22 * limitations under the License. *
23 * *
24 * ** GNU General Public License, version 3 ** *
25 * *
26 * This program is free software: you can redistribute it and/or modify *
27 * it under the terms of the GNU General Public License as published by *
28 * the Free Software Foundation, either version 3 of the License, or *
29 * (at your option) any later version. *
30 * *
31 * This program is distributed in the hope that it will be useful, *
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
34 * GNU General Public License for more details. *
35 * *
36 * You should have received a copy of the GNU General Public License *
37 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
38 *****************************************************************************/
39 
49 #ifndef MUI_STREAM_TUPLE_H
50 #define MUI_STREAM_TUPLE_H
51 
52 #include <tuple>
53 
54 #include "stream.h"
55 
56 namespace mui {
57 
58 // build integer sequence 0, 1, ... in compile time
59 template<std::size_t... indexes>
61  typedef index_sequence<indexes...,sizeof...(indexes)> next;
62 };
63 template<std::size_t N>
65  typedef typename make_index_sequence<N-1>::type::next type;
66 };
67 template<>
70 };
71 
72 
73 namespace {
74 template<std::size_t N, std::size_t MAX, typename... Args>
75 struct input_tuple_impl_ {
76  static void apply( istream& stream, std::tuple<Args...>& t){
77  stream >> std::get<N>(t);
79  }
80 };
81 template<std::size_t N, typename... Args>
82 struct input_tuple_impl_<N,N,Args...> {
83  static void apply( istream& , std::tuple<Args...>& ){}
84 };
85 }
86 
87 template<typename... Args>
88 inline istream& operator>> ( istream& stream, std::tuple<Args...>& ret )
89 {
90  std::tuple<Args...> t;
91  input_tuple_impl_<0,sizeof...(Args),Args...>::apply(stream,t);
92  ret.swap(t);
93  return stream;
94 }
95 
96 
97 namespace{
98 template<std::size_t N, std::size_t MAX, typename... Args>
99 struct output_tuple_impl_ {
100  static void apply( ostream& stream, const std::tuple<Args...>& t){
101  stream << std::get<N>(t);
103  }
104 };
105 template<std::size_t N, typename... Args>
106 struct output_tuple_impl_<N,N,Args...> {
107  static void apply( ostream& , const std::tuple<Args...>& ){}
108 };
109 }
110 
111 template<typename... Args>
112 inline ostream& operator<< ( ostream& stream, const std::tuple<Args...>& t )
113 {
114  output_tuple_impl_<0,sizeof...(Args),Args...>::apply(stream,t);
115  return stream;
116 }
117 
118 }
119 
120 #endif
Definition: stream.h:61
Definition: stream.h:67
u u u u u u u u u u u u u u u u u u u N
Definition: dim.h:317
Definition: comm.h:54
istream & operator>>(istream &stream, smalluint &sml)
Definition: comm_tcp.h:103
ostream & operator<<(ostream &stream, const smalluint &sml)
Definition: comm_tcp.h:127
vexpr_apply1< E, OP, SCALAR, D > apply(vexpr< E, SCALAR, D > const &u, OP const &op)
Definition: point.h:392
Defines base stream class container_stream and associated functors.
Definition: stream_tuple.h:60
index_sequence type
Definition: stream_tuple.h:69
Definition: stream_tuple.h:64
make_index_sequence< N-1 >::type::next type
Definition: stream_tuple.h:65