The Conley-Morse Graphs Software
byteutil.h
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2///
3/// @file byteutil.h
4///
5/// Utility procedures for writing and reading entire data structures
6/// with bzip2 compression, using the two classes "ByteCompressor"
7/// and "ByteDecompressor" defined elsewhere.
8///
9/// @author Pawel Pilarczyk
10///
11/////////////////////////////////////////////////////////////////////////////
12
13// Copyright (C) 1997-2014 by Pawel Pilarczyk.
14//
15// This file is part of my research software package. This is free software:
16// you can redistribute it and/or modify it under the terms of the GNU
17// General Public License as published by the Free Software Foundation,
18// either version 3 of the License, or (at your option) any later version.
19//
20// This software is distributed in the hope that it will be useful,
21// but WITHOUT ANY WARRANTY; without even the implied warranty of
22// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23// GNU General Public License for more details.
24//
25// You should have received a copy of the GNU General Public License
26// along with this software; see the file "license.txt". If not,
27// please, see <https://www.gnu.org/licenses/>.
28
29// Started on July 7, 2014. Last revision: July 8, 2014.
30
31
32#ifndef _PWP_BYTEUTIL_H_
33#define _PWP_BYTEUTIL_H_
34
35
36// include some standard C++ header files
37#include <algorithm>
38#include <new>
39#include <vector>
40#include <string>
41
42// include selected header files from the CHomP library
43#include "chomp/system/textfile.h"
44#include "chomp/cubes/pointset.h"
45#include "chomp/struct/digraph.h"
46#include "chomp/struct/multitab.h"
47#include "chomp/struct/hashsets.h"
48#include "chomp/system/timeused.h"
49
50// include local header files
51#include "config.h"
52#include "typedefs.h"
53#include "conindex.h"
54#include "morsedec.h"
55#include "typedyns.h"
56#include "utils.h"
57#include "bytecompr.h"
58
59
60// --------------------------------------------------
61// ------------------ std::string -------------------
62// --------------------------------------------------
63
65 const std::string &v)
66{
67 size_t size (v. size ());
68 c << size;
69 for (size_t i = 0; i < size; ++ i)
70 c << v [i];
71 return c;
72} /* operator << */
73
75 std::string &v)
76{
77 size_t size (0);
78 c >> size;
79 v. resize (size);
80 for (size_t i = 0; i < size; ++ i)
81 c >> v [i];
82 return c;
83} /* operator >> */
84
85
86// --------------------------------------------------
87// ------------------ std::vector -------------------
88// --------------------------------------------------
89
90template <class T>
92 const std::vector<T> &v)
93{
94 size_t size (v. size ());
95 c << size;
96 for (size_t i = 0; i < size; ++ i)
97 c << v [i];
98 return c;
99} /* operator << */
100
101template <class T>
103 std::vector<T> &v)
104{
105 size_t size (0);
106 c >> size;
107 v. resize (size);
108 for (size_t i = 0; i < size; ++ i)
109 c >> v [i];
110 return c;
111} /* operator >> */
112
113
114// --------------------------------------------------
115// ------------------- hashedset --------------------
116// --------------------------------------------------
117
118template <class T>
120 const chomp::homology::hashedset<T> &v)
121{
122 size_t size (v. size ());
123 c << size;
124 for (size_t i = 0; i < size; ++ i)
125 c << v [i];
126 return c;
127} /* operator << */
128
129template <class T>
131 chomp::homology::hashedset<T> &v)
132{
133 size_t size (0);
134 c >> size;
135 chomp::homology::hashedset<T> w;
136 for (size_t i = 0; i < size; ++ i)
137 {
138 T element;
139 c >> element;
140 w. add (element);
141 }
142 v. swap (w);
143 return c;
144} /* operator >> */
145
146
147// --------------------------------------------------
148// -------------------- spcCube ---------------------
149// --------------------------------------------------
150
152 const spcCube &q)
153{
154 spcCoord coord [spaceDim];
155 q. coord (coord);
156 for (int i = 0; i < spaceDim; ++ i)
157 c << coord [i];
158 return c;
159} /* operator << */
160
162 spcCube &q)
163{
164 spcCoord coord [spaceDim];
165 for (int i = 0; i < spaceDim; ++ i)
166 c >> coord [i];
167 q = spcCube (coord, spaceDim);
168 return c;
169} /* operator >> */
170
171
172#endif // _PWP_BYTEUTIL_H_
173
Writing and reading binary data (int, double) with bzip2 compression.
ByteCompressor & operator<<(ByteCompressor &c, const std::string &v)
Definition: byteutil.h:64
ByteDecompressor & operator>>(ByteDecompressor &c, std::string &v)
Definition: byteutil.h:74
A simple wrapper for the bzip2 data compression to an output stream.
Definition: bytecompr.h:59
A simple wrapper for the bzip2 data decompression from an input stream.
Definition: bytecompr.h:295
Choice of configuration settings.
Conley index computation routines.
Morse decompositions.
const int spaceDim
The dimension of the phase space.
Definition: p_differ.h:48
Customizable data types for the Conley-Morse graphs computation program.
Data types for the dynamical systems data structures.
int spcCoord
The type of coordinates of cubes in the phase space.
Definition: typespace.h:50
chomp::homology::tCubeBase< spcCoord > spcCube
The type of a cube in the phase space.
Definition: typespace.h:55
Utilites and helper functions.