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