Multiscale Universal Interface  2.0
A Concurrent Framework for Coupling Heterogeneous Solvers
stream_ordered.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 
47 #ifndef MUI_STREAM_ORDERED_H
48 #define MUI_STREAM_ORDERED_H
49 
50 #include <map>
51 #include <set>
52 
53 #include "stream.h"
54 
55 namespace mui {
56 template<typename K, typename V>
57 inline istream& operator>>(istream& stream, std::map<K,V>& ret)
58 {
59  std::size_t size;
60  stream >> size;
61  std::map<K,V> map;
62  for( std::uint64_t i=0; i<size; ++i ) {
63  std::pair<K,V> p;
64  stream >> p;
65  map.emplace(std::move(p));
66  }
67  ret.swap(map);
68  return stream;
69 }
70 template<typename K, typename V>
71 inline ostream& operator<<(ostream& stream, const std::map<K,V>& map)
72 {
73  stream << map.size();
74  for( const auto& p : map ) stream << p;
75  return stream;
76 }
77 
78 template<typename K, typename V>
79 inline istream& operator>>(istream& stream, std::multimap<K,V>& ret)
80 {
81  std::size_t size;
82  stream >> size;
83  std::multimap<K,V> map;
84  for( std::uint64_t i=0; i<size; ++i ) {
85  std::pair<K,V> p;
86  stream >> p;
87  map.emplace(std::ove(p));
88  }
89  ret.swap(map);
90  return stream;
91 }
92 template<typename K, typename V>
93 inline ostream& operator<<(ostream& stream, const std::multimap<K,V>& map)
94 {
95  stream << map.size();
96  for( const auto& p : map ) stream << p;
97  return stream;
98 }
99 
100 template<typename K>
101 inline istream& operator>>(istream& stream, std::set<K>& ret)
102 {
103  std::size_t size;
104  stream >> size;
105  std::set<K> set;
106  for( std::uint64_t i=0; i<size; ++i ) {
107  K k;
108  stream >> k;
109  set.emplace(std::move(k));
110  }
111  ret.swap(set);
112  return stream;
113 }
114 
115 template<typename K>
116 inline ostream& operator<<(ostream& stream, const std::set<K>& set)
117 {
118  stream << set.size();
119  for( auto& k : set ) stream << k;
120  return stream;
121 }
122 
123 
124 template<typename K>
125 inline istream& operator>>(istream& stream, std::multiset<K>& ret)
126 {
127  std::size_t size;
128  stream >> size;
129  std::multiset<K> set;
130  for( std::uint64_t i=0; i<size; ++i ) {
131  K k;
132  stream >> k;
133  set.emplace(std::move(k));
134  }
135  ret.swap(set);
136  return stream;
137 }
138 
139 template<typename K>
140 inline ostream& operator<< ( ostream& stream, const std::multiset<K>& set )
141 {
142  stream << set.size();
143  for( const auto& k : set ) stream << k;
144  return stream;
145 }
146 }
147 
148 #endif
Definition: stream.h:61
Definition: stream.h:67
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
Defines base stream class container_stream and associated functors.