source: Sophya/trunk/SophyaLib/BaseTools/rawstream.cc@ 2703

Last change on this file since 2703 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

File size: 4.4 KB
RevLine 
[2615]1#include "sopnamsp.h"
[2458]2#include "rawstream.h"
3#include "pexceptions.h"
4
5/*!
6 \class SOPHYA::RawInOutStream
7 \ingroup BaseTools
8 This class defines the interface for a raw input/output stream.
9 It has been designed primarily to be used by PPF streams
10 (Sophya Persistence).
11*/
12
13/* --Methode-- */
14RawInOutStream::RawInOutStream()
15{
16}
17
18/* --Methode-- */
19RawInOutStream::~RawInOutStream()
20{
21}
22
23/* --Methode-- */
24bool RawInOutStream::isSeekable() const
25{
26 return false;
27}
28
29/* --Methode-- */
30int_8 RawInOutStream::tellg()
31{
32 throw NotAvailableOperation("RawInOutStream::tellg() - Not implemented ");
33}
34
35/* --Methode-- */
36RawInOutStream& RawInOutStream::seekg(int_8, int)
37{
38 throw NotAvailableOperation("RawInOutStream::seekg() - Not implemented ");
39}
40
41/* --Methode-- */
42RawInOutStream& RawInOutStream::read(char* s, uint_8 n)
43{
44 throw NotAvailableOperation("RawInOutStream::seekg() - Not implemented ");
45}
46/* --Methode-- */
47int_8 RawInOutStream::tellp()
48{
49 throw NotAvailableOperation("RawInOutStream::tellp() - Not implemented ");
50}
51
52/* --Methode-- */
53RawInOutStream& RawInOutStream::seekp(int_8, int)
54{
55 throw NotAvailableOperation("RawInOutStream::seekp() - Not implemented ");
56}
57
58/* --Methode-- */
59RawInOutStream& RawInOutStream::write(const char* s, uint_8 n)
60{
61 throw NotAvailableOperation("RawInOutStream::seekp() - Not implemented ");
62}
63
64
65/*!
66 \class SOPHYA::RawInFileStream
67 \ingroup BaseTools
68 Implements the input interface (reading) of RawInOutStream
69 on a disk file using the standard C library (fopen, fread, ...)
70*/
71
72/* --Methode-- */
73RawInFileStream::RawInFileStream(const char * path)
74 : RawInOutStream()
75{
76 fip = fopen(path,"rb");
77 if (fip == NULL) {
78 string errmsg = "RawInFileStream() - fopen(rb) ERROR - File= ";
79 errmsg += path;
80 throw IOExc(errmsg);
81 }
82 _filename = path;
83}
84
85/* --Methode-- */
86RawInFileStream::RawInFileStream(string const & path)
87 : RawInOutStream()
88{
89 fip = fopen(path.c_str(),"rb");
90 if (fip == NULL) {
91 string errmsg = "RawInFileStream() - fopen(rb) ERROR - File= ";
92 errmsg += path;
93 throw IOExc(errmsg);
94 }
95 _filename = path;
96}
97
98/* --Methode-- */
99RawInFileStream::~RawInFileStream()
100{
101 fclose(fip);
102}
103
104
105/* --Methode-- */
106bool RawInFileStream::isSeekable() const
107{
108 return true;
109}
110
111/* --Methode-- */
112int_8 RawInFileStream::tellg()
113{
114 return ftell(fip) ;
115}
116
117/* --Methode-- */
118RawInOutStream& RawInFileStream::seekg(int_8 off, int dir)
119{
120 int fsd = SEEK_SET;
121 if (dir == ios::beg) fsd = SEEK_SET;
122 else if (dir == ios::end) fsd = SEEK_END;
123 else fsd = SEEK_CUR;
124 fseek(fip, (long int)off, fsd);
125 return (*this);
126}
127
128/* --Methode-- */
129RawInOutStream& RawInFileStream::read(char* s, uint_8 n)
130{
131 size_t rc = fread((void *)s, 1, (size_t)n, fip);
132 if (rc != (size_t)n) {
133 string errmsg = "RawInFileStream::read() ERROR - File= ";
134 errmsg += _filename;
135 throw IOExc(errmsg);
136 }
137 return (*this);
138}
139
140/*!
141 \class SOPHYA::RawOutFileStream
142 \ingroup BaseTools
143 Implements the output interface (writing) of RawInOutStream
144 on a disk file using the standard C library (fopen, fwrite, ...)
145*/
146
147/* --Methode-- */
148RawOutFileStream::RawOutFileStream(const char * path)
149 : RawInOutStream()
150{
151 fip = fopen(path,"wb");
152 if (fip == NULL) {
153 string errmsg = "RawOutFileStream() - fopen(wb) ERROR - File= ";
154 errmsg += path;
155 throw IOExc(errmsg);
156 }
157 _filename = path;
158}
159
160/* --Methode-- */
161RawOutFileStream::RawOutFileStream(string const & path)
162 : RawInOutStream()
163{
[2459]164 fip = fopen(path.c_str(),"wb");
[2458]165 if (fip == NULL) {
166 string errmsg = "RawOutFileStream() - fopen(wb) ERROR - File= ";
167 errmsg += path;
168 throw IOExc(errmsg);
169 }
170 _filename = path;
171}
172
173/* --Methode-- */
174RawOutFileStream::~RawOutFileStream()
175{
176 fclose(fip);
177}
178
179
180/* --Methode-- */
181bool RawOutFileStream::isSeekable() const
182{
183 return true;
184}
185
186/* --Methode-- */
187int_8 RawOutFileStream::tellp()
188{
189 return ftell(fip) ;
190}
191
192/* --Methode-- */
193RawInOutStream& RawOutFileStream::seekp(int_8 off, int dir)
194{
195 int fsd = SEEK_SET;
196 if (dir == ios::beg) fsd = SEEK_SET;
197 else if (dir == ios::end) fsd = SEEK_END;
198 else fsd = SEEK_CUR;
199 fseek(fip, (long int)off, fsd);
200 return (*this);
201}
202
203/* --Methode-- */
204RawInOutStream& RawOutFileStream::write(const char* s, uint_8 n)
205{
206 size_t rc = fwrite((void *)s, 1, (size_t)n, fip);
207 if (rc != (size_t)n) {
208 string errmsg = "RawOutFileStream::write() ERROR - File= ";
209 errmsg += _filename;
210 throw IOExc(errmsg);
211 }
212 return (*this);
213}
Note: See TracBrowser for help on using the repository browser.