OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimIoStream.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: See top level LICENSE.txt file.
4 //
5 // Author: Garrett Potts
6 //
7 // Description:
8 //
9 // Class definitiaons for:
10 //
11 // ossimIStream
12 // ossimOStream
13 // ossimIOStream
14 // ossimIOMemoryStream
15 // ossimIMemoryStream
16 // ossimOMemoryStream
17 // ossimIOFStream
18 // ossimIFStream
19 // ossimOFStream
20 //
21 //*******************************************************************
22 // $Id: ossimIoStream.cpp 23002 2014-11-24 17:11:17Z dburken $
24 /*
25 ossimIStream::ossimIStream()
26  : ossimStreamBase(),
27 #if defined(_MSC_VER)
28  std::istream((std::_Uninitialized)0)
29 #else
30  std::istream()
31 #endif
32 {}
33 */
34 ossimIStream::ossimIStream(std::streambuf* sb)
35  : ossimStreamBase(),
36  std::basic_istream<char>(sb)
37 {}
38 
40 {}
41 
42 /*
43 ossimOStream::ossimOStream()
44  : ossimStreamBase(),
45 #ifdef _MSC_VER
46  std::ostream((std::_Uninitialized)0)
47 #else
48  std::ostream()
49 #endif
50 {}
51 */
52 ossimOStream::ossimOStream(std::streambuf* sb)
53  : ossimStreamBase(),
54  std::basic_ostream<char>(sb)
55 {}
56 
58 {}
59 
60 ossimIOStream::ossimIOStream(std::streambuf* sb)
61 :std::basic_iostream<char>(sb)
62 {
63 
64 }
65 /*
66 ossimIOStream::ossimIOStream()
67  : ossimStreamBase(),
68 #ifdef _MSC_VER
69  std::iostream((std::_Uninitialized)0)
70 #else
71  std::iostream()
72 #endif
73 {}
74 */
76 {}
77 
79  : ossimIOStream(&theBuf),
80  theBuf(std::ios::in|std::ios::out)
81 {
82  ossimIOStream::init(&theBuf);
83 }
84 
86 {
87 }
88 
90 {
91  return true;
92 }
93 
94 void ossimIOMemoryStream::open(const char* /* protocolString */,
95  int /* openMode */)
96 {
97 }
98 
100 {
101  return theBuf.str();
102 }
103 
105 {}
106 
108 {
109  ossimIOMemoryStream* thisPtr = const_cast<ossimIOMemoryStream*>(this);
110  std::streampos pos = thisPtr->tellg();
111  thisPtr->seekg(0, std::ios::end);
112  std::streampos endPos = thisPtr->tellg();
113  thisPtr->seekg(pos, std::ios::beg);
114 
115  return (ossim_uint64)(endPos);
116 }
117 
119 
120  : ossimIStream(&theBuf),
121  theBuf(inputBuf.c_str(), std::ios::in)
122 {
123  ossimIStream::init(&theBuf);
124 }
125 
127 {
128 }
129 
131 {
132  return true;
133 }
134 
136 {
137  ossimIMemoryStream* thisPtr = const_cast<ossimIMemoryStream*>(this);
138  std::streampos pos = thisPtr->tellg();
139  thisPtr->seekg(0, std::ios::end);
140  std::streampos endPos = thisPtr->tellg();
141  thisPtr->seekg(pos, std::ios::beg);
142  return (ossim_uint64)(endPos);
143 }
144 
145 void ossimIMemoryStream::open(const char* /* protocolString */,
146  int /* openMode */ )
147 {
148 }
149 
151 {}
152 
154 {
155  return theBuf.str();
156 }
157 
159  : ossimOStream(&theBuf),
160  theBuf(std::ios::out)
161 {
162  ossimOStream::init(&theBuf);
163 }
164 
166 {
167 }
168 
170 {
171  return true;
172 }
173 
175 {
176  ossimOMemoryStream* thisPtr = const_cast<ossimOMemoryStream*>(this);
177  std::streampos pos = thisPtr->tellp();
178  thisPtr->seekp(0, std::ios::end);
179  std::streampos endPos = thisPtr->tellp();
180  thisPtr->seekp(pos, std::ios::beg);
181  return (ossim_uint64)(endPos);
182 }
183 
184 void ossimOMemoryStream::open(const char* /* protocolString */,
185  int /* openMode */ )
186 {
187 }
188 
190 {}
191 
193 {
194  return theBuf.str();
195 }
196 
198  : ossimStreamBase(),
199  std::fstream()
200 {
201 }
202 
204  std::ios_base::openmode mode)
205  : ossimStreamBase(),
206  std::fstream(name, mode)
207 {
208 }
209 
211 {
212 }
213 
215  : ossimStreamBase(),
216  std::basic_ifstream<char>()
217 {
218 }
219 ossimIFStream::ossimIFStream(const char* file, std::ios_base::openmode mode)
220  : ossimStreamBase(),
221  std::basic_ifstream<char>(file, mode)
222 {
223 }
224 
226 {
227 }
228 
230  : ossimStreamBase(),
231  std::basic_ofstream<char>()
232 {
233 }
234 
235 ossimOFStream::ossimOFStream(const char* name, std::ios_base::openmode mode)
236  : ossimStreamBase(),
237  std::basic_ofstream<char>(name, mode)
238 {
239 }
240 
242 {
243 }
244 #ifdef _MSC_VER
245 
246  ossimIFStream64::ossimIFStream64(const char* pFilename, std::ios_base::openmode mode, int prot) :
247  std::basic_ifstream<char>(theFile = std::_Fiopen(pFilename, mode, prot))
248  {
249  }
250 
252  {
253  if(is_open())
254  {
255  close();
256  }
257  }
258 
259  void ossimIFStream64::seekg64(off_type off, ios_base::seekdir way)
260  {
261  _fseeki64(theFile, off, way);
262  }
263 
264  void ossimIFStream64::seekg64(streampos pos, ios_base::seekdir way)
265  {
266  // Undo the potentially bad typecast done by _FPOSOFF when fpos is > max long
267  const off_type off(pos);
268  const fpos_t fpos = pos.seekpos();
269  seekg64(off - _FPOSOFF(fpos) + fpos, way);
270  }
271 
272  void ossimIFStream64::seekg64(std::istream& str, off_type off,
273  ios_base::seekdir way)
274  {
275  ossimIFStream64* pStream = dynamic_cast<ossimIFStream64*>(&str);
276  if (pStream != NULL)
277  {
278  pStream->seekg64(off, way);
279  }
280  else
281  {
282  str.seekg(off, way);
283  }
284  }
285 
287  std::streampos pos,
288  ios_base::seekdir way)
289  {
290  ossimIFStream64* pStream = dynamic_cast<ossimIFStream64*>(&str);
291  if (pStream != NULL)
292  {
293  pStream->seekg64(pos, way);
294  }
295  else
296  {
297  str.seekg(pos, way);
298  }
299  }
300 
301  ossimOFStream64::ossimOFStream64(const char* pFilename,
302  std::ios_base::openmode mode,
303  int prot) :
304  std::basic_ofstream<char>(pFilename, mode, prot)
305  {
306  }
307 
309  {
310  if(is_open())
311  {
312  close();
313  }
314  }
315 
317  {
318  // Undo the potentially bad typecast done by _FPOSOFF when fpos is > max long
319  const pos_type pos = tellp();
320  const off_type off(pos);
321  const fpos_t fpos = pos.seekpos();
322  return off - _FPOSOFF(fpos) + fpos;
323  }
324 
325 #else
326 
327 ossimIFStream64::ossimIFStream64(const char* pFilename,
328  std::ios_base::openmode mode,
329  long /* prot */) :
330  std::basic_ifstream<char>(pFilename, mode)
331 {
332 }
333 
335 {
336  if(is_open())
337  {
338  close();
339  }
340 }
341 
342 void ossimIFStream64::seekg64(off_type off, ios_base::seekdir way)
343 {
344  std::basic_ifstream<char>::seekg(off, way);
345 }
346 
348  off_type off, ios_base::seekdir way)
349 {
350  str.seekg(off, way);
351 }
352 
353 ossimOFStream64::ossimOFStream64(const char* pFilename,
354  std::ios_base::openmode mode,
355  long /* prot */) :
356  std::basic_ofstream<char>(pFilename, mode)
357 {
358 }
359 
361 {
362  if(is_open())
363  {
364  close();
365  }
366 }
367 
369 {
370  return tellp();
371 }
372 
373 #endif // _MSC_VER
374 
376 {
377  char buf[1024];
378  bool done = false;
379 
380  while(!done&&!in.fail())
381  {
382  in.read(buf, 1024);
383  if(in.gcount() < 1024)
384  {
385  done = true;
386  }
387  if(in.gcount() > 0)
388  {
389  out.write(buf, in.gcount());
390  }
391  }
392 }
393 
395 {
396  char buf[1024];
397  bool done = false;
398 
399  while(!done&&!in.fail())
400  {
401  in.read(buf, 1024);
402  if(in.gcount() < 1024)
403  {
404  done = true;
405  }
406  if(in.gcount() > 0)
407  {
408  out.write(buf, in.gcount());
409  }
410  }
411 
412  return out;
413 }
414 
416 {
417  char buf[1024];
418  bool done = false;
419 
420  while(!done&&!in.fail())
421  {
422  in.read(buf, 1024);
423  if(in.gcount() < 1024)
424  {
425  done = true;
426  }
427  if(in.gcount() > 0)
428  {
429  out.write(buf, in.gcount());
430  }
431  }
432 }
433 
435 {
436  char buf[1024];
437  bool done = false;
438 
439  while(!done&&!in.fail())
440  {
441  in.read(buf, 1024);
442  if(in.gcount() < 1024)
443  {
444  done = true;
445  }
446  if(in.gcount() > 0)
447  {
448  out.write(buf, in.gcount());
449  }
450  }
451 
452  return out;
453 }
454 
456 {
457  char buf[1024];
458  bool done = false;
459 
460  while(!done&&!in.fail())
461  {
462  in.read(buf, 1024);
463  if(in.gcount() < 1024)
464  {
465  done = true;
466  }
467  if(in.gcount() > 0)
468  {
469  out.write(buf, in.gcount());
470  }
471  }
472 }
473 
475 {
476  char buf[1024];
477  bool done = false;
478 
479  while(!done&&!in.fail())
480  {
481  in.read(buf, 1024);
482  if(in.gcount() < 1024)
483  {
484  done = true;
485  }
486  if(in.gcount() > 0)
487  {
488  out.write(buf, in.gcount());
489  }
490  }
491 }
492 
494 {
495  char buf[1024];
496  bool done = false;
497 
498  while(!done&&!in.fail())
499  {
500  in.read(buf, 1024);
501  if(in.gcount() < 1024)
502  {
503  done = true;
504  }
505  if(in.gcount() > 0)
506  {
507  out.write(buf, in.gcount());
508  }
509  }
510 
511  return out;
512 }
513 
515 {
516  char buf[1024];
517  bool done = false;
518 
519  while(!done&&!in.fail())
520  {
521  in.read(buf, 1024);
522  if(in.gcount() < 1024)
523  {
524  done = true;
525  }
526  if(in.gcount() > 0)
527  {
528  out.write(buf, in.gcount());
529  }
530  }
531 
532  return out;
533 }
virtual void open(const char *, int)
std::basic_fstream< char > fstream
Class for char mixed input and output file streams.
Definition: ossimIosFwd.h:50
ossimIFStream64(const char *pFilename, std::ios_base::openmode mode=ios_base::in, long prot=0666)
virtual ~ossimIMemoryStream()
ossimIStream(std::streambuf *sb)
virtual ~ossimOFStream64()
virtual ~ossimIFStream()
bool is_open() const
ossimOStream(std::streambuf *sb)
virtual ~ossimIFStream64()
virtual void close()
virtual ~ossimIOStream()
virtual void close()
virtual ~ossimIOFStream()
ossimIMemoryStream(const ossimString &inputBuf)
bool is_open() const
void operator<<(ossimOStream &out, ossimIStream &in)
virtual ~ossimIOMemoryStream()
std::stringbuf theBuf
Definition: ossimIoStream.h:96
ossim_uint64 size() const
std::stringbuf theBuf
virtual void open(const char *, int)
unsigned long long ossim_uint64
bool is_open() const
virtual ~ossimOStream()
std::stringbuf theBuf
ossim_uint64 tellp64()
virtual ~ossimOFStream()
void seekg64(off_type off, ios_base::seekdir way)
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
ossim_uint64 size() const
virtual ~ossimIStream()
ossimOFStream64(const char *pFilename, std::ios_base::openmode mode=ios_base::out, long prot=0666)
void operator>>(ossimIStream &in, ossimOStream &out)
ossim_uint64 size() const
virtual void open(const char *, int)
virtual ~ossimOMemoryStream()
ossimIOStream(std::streambuf *sb)
virtual void close()