VTK  9.1.0
vtkMultiProcessStreamSerialization.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkMultiProcessSerialization.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
40#ifndef vtkMultiProcessSerialization_h
41#define vtkMultiProcessSerialization_h
42
44
45#include <array>
46#include <map>
47#include <set>
48#include <utility>
49#include <vector>
50
51template <typename T>
53{
54 static void Save(vtkMultiProcessStream& stream, const T& t) { stream << t; }
55 static void Load(vtkMultiProcessStream& stream, T& t) { stream >> t; }
56};
57
58template <typename ElementType>
59struct Serialization<std::set<ElementType>>
60{
61 static void Save(vtkMultiProcessStream& stream, const std::set<ElementType>& set)
62 {
63 stream << static_cast<vtkTypeInt64>(set.size());
64 for (const auto& elem : set)
65 {
67 }
68 }
69
70 static void Load(vtkMultiProcessStream& stream, std::set<ElementType>& set)
71 {
72 vtkTypeInt64 count;
73 stream >> count;
74 for (vtkTypeInt64 cc = 0; cc < count; ++cc)
75 {
76 ElementType elem;
78 set.insert(std::move(elem));
79 }
80 }
81};
82
83template <typename ElementType, std::size_t N>
84struct Serialization<std::array<ElementType, N>>
85{
86 static void Save(vtkMultiProcessStream& stream, const std::array<ElementType, N>& array)
87 {
88 for (const auto& elem : array)
89 {
91 }
92 }
93
94 static void Load(vtkMultiProcessStream& stream, std::array<ElementType, N>& array)
95 {
96 for (std::size_t cc = 0; cc < N; ++cc)
97 {
98 Serialization<ElementType>::Load(stream, array[cc]);
99 }
100 }
101};
102
103template <typename T1, typename T2>
104struct Serialization<std::pair<T1, T2>>
105{
106 static void Save(vtkMultiProcessStream& stream, const std::pair<T1, T2>& pair)
107 {
108 Serialization<T1>::Save(stream, pair.first);
109 Serialization<T2>::Save(stream, pair.second);
110 }
111
112 static void Load(vtkMultiProcessStream& stream, std::pair<T1, T2>& pair)
113 {
114 Serialization<T1>::Load(stream, pair.first);
115 Serialization<T2>::Load(stream, pair.second);
116 }
117};
118
119template <typename T1, typename T2>
120struct Serialization<std::map<T1, T2>>
121{
122 static void Save(vtkMultiProcessStream& stream, const std::map<T1, T2>& map)
123 {
124 stream << static_cast<vtkTypeInt64>(map.size());
125 for (const auto& pair : map)
126 {
128 }
129 }
130
131 static void Load(vtkMultiProcessStream& stream, std::map<T1, T2>& map)
132 {
133 vtkTypeInt64 count;
134 stream >> count;
135 for (vtkTypeInt64 cc = 0; cc < count; ++cc)
136 {
137 std::pair<T1, T2> pair;
139 map.insert(std::move(pair));
140 }
141 }
142};
143
144template <typename ElementType>
145struct Serialization<std::vector<ElementType>>
146{
147 static void Save(vtkMultiProcessStream& stream, const std::vector<ElementType>& vector)
148 {
149 stream << static_cast<vtkTypeInt64>(vector.size());
150 for (const auto& elem : vector)
151 {
153 }
154 }
155
156 static void Load(vtkMultiProcessStream& stream, std::vector<ElementType>& vector)
157 {
158 vtkTypeInt64 count;
159 stream >> count;
160 for (vtkTypeInt64 cc = 0; cc < count; ++cc)
161 {
162 ElementType elem;
164 vector.push_back(std::move(elem));
165 }
166 }
167};
168
169template <typename T>
171{
172 Serialization<T>::Save(stream, value);
173 return stream;
174}
175
176template <typename T>
178{
179 Serialization<T>::Load(stream, value);
180 return stream;
181}
182
183#endif
184// VTK-HeaderTest-Exclude: vtkMultiProcessStreamSerialization.h
stream used to pass data across processes using vtkMultiProcessController.
static void Save(vtkMultiProcessStream &stream, const std::array< ElementType, N > &array)
static void Load(vtkMultiProcessStream &stream, std::array< ElementType, N > &array)
static void Save(vtkMultiProcessStream &stream, const std::map< T1, T2 > &map)
static void Load(vtkMultiProcessStream &stream, std::map< T1, T2 > &map)
static void Save(vtkMultiProcessStream &stream, const std::pair< T1, T2 > &pair)
static void Load(vtkMultiProcessStream &stream, std::pair< T1, T2 > &pair)
static void Save(vtkMultiProcessStream &stream, const std::set< ElementType > &set)
static void Load(vtkMultiProcessStream &stream, std::set< ElementType > &set)
static void Save(vtkMultiProcessStream &stream, const std::vector< ElementType > &vector)
static void Load(vtkMultiProcessStream &stream, std::vector< ElementType > &vector)
static void Save(vtkMultiProcessStream &stream, const T &t)
static void Load(vtkMultiProcessStream &stream, T &t)
vtkMultiProcessStream & operator<<(vtkMultiProcessStream &stream, const T &value)
vtkMultiProcessStream & operator>>(vtkMultiProcessStream &stream, T &value)