Panda3D
pandaIOStream.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file pandaIOStream.cxx
10  * @author rdb
11  * @date 2011-03-29
12  */
13 
14 #include "pandaIOStream.h"
15 
16 using std::ios;
17 
18 /**
19  *
20  */
21 PandaIOStream::
22 PandaIOStream(std::istream &stream) : _istream(stream) {
23 }
24 
25 /**
26  * Returns the size of this file.
27  */
28 size_t PandaIOStream::
29 FileSize() const {
30  std::streampos cur = _istream.tellg();
31  _istream.seekg(0, ios::end);
32  std::streampos end = _istream.tellg();
33  _istream.seekg(cur, ios::beg);
34  return end;
35 }
36 
37 /**
38  * See fflush.
39  */
40 void PandaIOStream::
41 Flush() {
42  nassertv(false);
43 }
44 
45 /**
46  * See fread.
47  */
48 size_t PandaIOStream::
49 Read(void *buffer, size_t size, size_t count) {
50  _istream.read((char*) buffer, size * count);
51  return _istream.gcount();
52 }
53 
54 /**
55  * See fseek.
56  */
57 aiReturn PandaIOStream::
58 Seek(size_t offset, aiOrigin origin) {
59  switch (origin) {
60  case aiOrigin_SET:
61  _istream.seekg(offset, ios::beg);
62  break;
63 
64  case aiOrigin_CUR:
65  _istream.seekg(offset, ios::cur);
66  break;
67 
68  case aiOrigin_END:
69  _istream.seekg(offset, ios::end);
70  break;
71 
72  default:
73  // Keep compiler happy
74  nassertr(false, AI_FAILURE);
75  break;
76  }
77 
78  if (_istream.good()) {
79  return AI_SUCCESS;
80  } else {
81  return AI_FAILURE;
82  }
83 }
84 
85 /**
86  * See ftell.
87  */
88 size_t PandaIOStream::
89 Tell() const {
90  return _istream.tellg();
91 }
92 
93 /**
94  * See fwrite.
95  */
96 size_t PandaIOStream::
97 Write(const void *buffer, size_t size, size_t count) {
98  nassertr(false, 0);
99  return 0;
100 }
aiReturn Seek(size_t pOffset, aiOrigin pOrigin)
See fseek.
size_t Tell() const
See ftell.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
size_t Read(void *pvBuffer, size_t pSize, size_t pCount)
See fread.
size_t FileSize() const
Returns the size of this file.
void Flush()
See fflush.
size_t Write(const void *buffer, size_t size, size_t count)
See fwrite.