The Conley-Morse Graphs Software
datavector.h
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2///
3/// @file datavector.h
4///
5/// Data conversion for sending/receiving: std::vectors and hashed sets
6/// of any objects.
7/// This file contains the definitions of the operators << and >>
8/// for encoding some variables to the binary data structure
9/// and retrieving them. This binary data structure is used
10/// in the communication between the coordinator and workers.
11///
12/// @author Pawel Pilarczyk
13///
14/////////////////////////////////////////////////////////////////////////////
15
16// Copyright (C) 1997-2014 by Pawel Pilarczyk.
17//
18// This file is part of my research software package. This is free software:
19// you can redistribute it and/or modify it under the terms of the GNU
20// General Public License as published by the Free Software Foundation,
21// either version 3 of the License, or (at your option) any later version.
22//
23// This software is distributed in the hope that it will be useful,
24// but WITHOUT ANY WARRANTY; without even the implied warranty of
25// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26// GNU General Public License for more details.
27//
28// You should have received a copy of the GNU General Public License
29// along with this software; see the file "license.txt". If not,
30// please, see <https://www.gnu.org/licenses/>.
31
32// Started on February 15, 2008. Last revision: March 26, 2013.
33
34
35#ifndef _CMGRAPHS_DATAVECTOR_H_
36#define _CMGRAPHS_DATAVECTOR_H_
37
38
39// include some standard C++ header files
40#include <vector>
41#include <utility>
42
43// include selected header files from the CHomP library
44#include "chomp/system/config.h"
45#include "chomp/system/textfile.h"
46#include "chomp/struct/hashsets.h"
47#include "chomp/multiwork/mw.h"
48
49
50// --------------------------------------------------
51// ------------- vector of any objects --------------
52// --------------------------------------------------
53
54/// Writes a standard vector of any objects to a MultiWork data structure.
55template<class AnyType>
56inline chomp::multiwork::mwData &operator << (chomp::multiwork::mwData &data,
57 const std::vector<AnyType> &vect)
58{
59 size_t size = vect. size ();
60 data << size;
61 for (size_t i = 0; i < size; ++ i)
62 data << vect [i];
63 return data;
64} /* operator << */
65
66/// Reads a standard vector of any objects from a MultiWork data structure.
67template<class AnyType>
68inline chomp::multiwork::mwData &operator >> (chomp::multiwork::mwData &data,
69 std::vector<AnyType> &vect)
70{
71 size_t size = 0;
72 data >> size;
73 if (size > 0)
74 vect. resize (size);
75 else
76 vect. clear ();
77 for (size_t i = 0; i < size; ++ i)
78 data >> vect [i];
79 return data;
80} /* operator >> */
81
82
83// --------------------------------------------------
84// -------------- pair of any objects ---------------
85// --------------------------------------------------
86
87/// Writes a standard pair of any objects to a MultiWork data structure.
88template<class Type1, class Type2>
89inline chomp::multiwork::mwData &operator << (chomp::multiwork::mwData &data,
90 const std::pair<Type1,Type2> &p)
91{
92 data << p. first;
93 data << p. second;
94 return data;
95} /* operator << */
96
97/// Reads a standard pair of any objects from a MultiWork data structure.
98template<class Type1, class Type2>
99inline chomp::multiwork::mwData &operator >> (chomp::multiwork::mwData &data,
100 std::pair<Type1,Type2> &p)
101{
102 data >> p. first;
103 data >> p. second;
104 return data;
105} /* operator >> */
106
107
108// --------------------------------------------------
109// ----------- hashed set of any objects ------------
110// --------------------------------------------------
111
112/// Writes a standard vector of any objects to a MultiWork data structure.
113template<class AnyType>
114inline chomp::multiwork::mwData &operator << (chomp::multiwork::mwData &data,
115 const chomp::homology::hashedset<AnyType> &vect)
116{
117 int_t size = vect. size ();
118 data << size;
119 for (int_t i = 0; i < size; ++ i)
120 data << vect [i];
121 return data;
122} /* operator << */
123
124/// Reads a standard vector of any objects from a MultiWork data structure.
125template<class AnyType>
126inline chomp::multiwork::mwData &operator >> (chomp::multiwork::mwData &data,
127 chomp::homology::hashedset<AnyType> &vect)
128{
129 int_t size = 0;
130 data >> size;
131 for (int_t i = 0; i < size; ++ i)
132 {
133 AnyType object;
134 data >> object;
135 vect. add (object);
136 }
137 return data;
138} /* operator >> */
139
140
141#endif // _CMGRAPHS_DATAVECTOR_H_
142
chomp::multiwork::mwData & operator>>(chomp::multiwork::mwData &data, std::vector< AnyType > &vect)
Reads a standard vector of any objects from a MultiWork data structure.
Definition: datavector.h:68
chomp::multiwork::mwData & operator<<(chomp::multiwork::mwData &data, const std::vector< AnyType > &vect)
Writes a standard vector of any objects to a MultiWork data structure.
Definition: datavector.h:56