SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Pstreams.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2009 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 
30 
31 /*
32  * Pstream.h: reading/writing persistent objects
33  *
34  * Written by:
35  * Steven G. Parker
36  * Department of Computer Science
37  * University of Utah
38  * April 1994
39  *
40  */
41 
42 #ifndef SCI_project_Pstream_h
43 #define SCI_project_Pstream_h 1
44 
46 #include <cstdio>
47 #include <iosfwd>
48 
49 #include <Core/Persistent/share.h>
50 
51 namespace SCIRun {
52 
54 protected:
55  FILE* fp_;
56 
57  virtual const char *endianness();
58  virtual void reset_post_header();
59 private:
60  template <class T> void gen_io(T&, const char *);
61 
62 public:
63  BinaryPiostream(const std::string& filename, Direction dir,
65  BinaryPiostream(int fd, Direction dir, const int& v = -1,
67  virtual ~BinaryPiostream();
68 
69  virtual void io(char&);
70  virtual void io(signed char&);
71  virtual void io(unsigned char&);
72  virtual void io(short&);
73  virtual void io(unsigned short&);
74  virtual void io(int&);
75  virtual void io(unsigned int&);
76  virtual void io(long&);
77  virtual void io(unsigned long&);
78  virtual void io(long long&);
79  virtual void io(unsigned long long&);
80  virtual void io(double&);
81  virtual void io(float&);
82  virtual void io(std::string& str);
83 
84  virtual bool supports_block_io() { return (version() > 1); }
85  virtual bool block_io(void*, size_t, size_t);
86 };
87 
88 
90 protected:
91  virtual const char *endianness();
92 private:
93  template <class T> void gen_io(T&, const char *);
94 
95 public:
96  BinarySwapPiostream(const std::string& filename, Direction d,
98  BinarySwapPiostream(int fd, Direction dir, const int& v = -1,
100  virtual ~BinarySwapPiostream();
101 
102  virtual void io(short&);
103  virtual void io(unsigned short&);
104  virtual void io(int&);
105  virtual void io(unsigned int&);
106  virtual void io(long&);
107  virtual void io(unsigned long&);
108  virtual void io(long long&);
109  virtual void io(unsigned long long&);
110  virtual void io(double&);
111  virtual void io(float&);
112 
113  virtual bool supports_block_io() { return false; }
114  virtual bool block_io(void*, size_t, size_t) { return false; }
115 };
116 
117 
119 private:
120  std::istream* istr;
121  std::ostream* ostr;
122  bool ownstreams_p_;
123 
124  void expect(char);
125  void next_entry();
126  virtual void emit_pointer(int&, int&);
127  void io(int, std::string& str);
128 protected:
129  virtual void reset_post_header();
130 public:
131  TextPiostream(const std::string& filename, Direction dir,
135  virtual ~TextPiostream();
136 
137  virtual std::string peek_class();
138  virtual int begin_class(const std::string& name, int);
139  virtual void end_class();
140  virtual void begin_cheap_delim();
141  virtual void end_cheap_delim();
142 
143  virtual void io(bool&);
144  virtual void io(char&);
145  virtual void io(signed char&);
146  virtual void io(unsigned char&);
147  virtual void io(short&);
148  virtual void io(unsigned short&);
149  virtual void io(int&);
150  virtual void io(unsigned int&);
151  virtual void io(long&);
152  virtual void io(unsigned long&);
153  virtual void io(long long&);
154  virtual void io(unsigned long long&);
155  virtual void io(double&);
156  virtual void io(float&);
157  virtual void io(std::string& str);
158  virtual bool eof();
159 };
160 
161 
162 /// The Fast stream is binary, its results can only safely be used
163 /// on the architecture where the file is generated.
165 private:
166  FILE* fp_;
167 
168  void report_error(const char *);
169  template <class T> void gen_io(T&, const char *);
170 protected:
171  virtual void reset_post_header();
172 public:
173  FastPiostream(const std::string& filename, Direction dir,
175  FastPiostream(int fd, Direction dir,
177  virtual ~FastPiostream();
178 
179  virtual void io(bool&);
180  virtual void io(char&);
181  virtual void io(signed char&);
182  virtual void io(unsigned char&);
183  virtual void io(short&);
184  virtual void io(unsigned short&);
185  virtual void io(int&);
186  virtual void io(unsigned int&);
187  virtual void io(long&);
188  virtual void io(unsigned long&);
189  virtual void io(long long&);
190  virtual void io(unsigned long long&);
191  virtual void io(double&);
192  virtual void io(float&);
193  virtual void io(std::string& str);
194 
195  virtual bool supports_block_io() { return true; }
196  virtual bool block_io(void*, size_t, size_t);
197 };
198 
199 
200 } // End namespace SCIRun
201 
202 
203 #endif
boost::shared_ptr< LegacyLoggerInterface > LoggerHandle
Definition: LoggerFwd.h:42
virtual bool supports_block_io()
Definition: Pstreams.h:113
Definition: Persistent.h:89
Direction
Definition: Persistent.h:95
FILE * fp_
Definition: Pstreams.h:55
#define SCISHARE
Definition: share.h:39
Definition: Pstreams.h:164
string dir
Definition: eab.py:5
Definition: Pstreams.h:53
Base class for persistent objects...
const char * name[]
Definition: BoostGraphExampleTests.cc:87
Definition: Pstreams.h:89
virtual bool supports_block_io()
Definition: Pstreams.h:84
v
Definition: readAllFields.py:42
std::string endianness()
Definition: Endian.cc:80
Definition: Pstreams.h:118
virtual bool supports_block_io()
Definition: Pstreams.h:195
virtual bool block_io(void *, size_t, size_t)
Definition: Pstreams.h:114