Panda3D

Loading...
Searching...
No Matches
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 */
21PandaIOStream::
22PandaIOStream(std::istream &stream) : _istream(stream) {
23}
24
25/**
26 * Returns the size of this file.
27 */
28 size_t PandaIOStream::
29 FileSize() const {
30 _istream.clear();
31 std::streampos cur = _istream.tellg();
32 _istream.seekg(0, ios::end);
33 std::streampos end = _istream.tellg();
34 _istream.seekg(cur);
35 return end;
36}
37
38/**
39 * See fflush.
40 */
41 void PandaIOStream::
42 Flush() {
43 nassertv(false);
44}
45
46/**
47 * See fread.
48 */
49 size_t PandaIOStream::
50 Read(void *buffer, size_t size, size_t count) {
51 _istream.read((char *)buffer, size * count);
52
53 if (_istream.eof()) {
54 // Gracefully handle EOF.
55 _istream.clear(ios::eofbit);
56 }
57
58 return _istream.gcount() / size;
59}
60
61/**
62 * See fseek.
63 */
64aiReturn PandaIOStream::
65 Seek(size_t offset, aiOrigin origin) {
66 switch (origin) {
67 case aiOrigin_SET:
68 _istream.seekg(offset, ios::beg);
69 break;
70
71 case aiOrigin_CUR:
72 _istream.seekg(offset, ios::cur);
73 break;
74
75 case aiOrigin_END:
76 _istream.seekg(offset, ios::end);
77 break;
78
79 default:
80 // Keep compiler happy
81 nassertr(false, AI_FAILURE);
82 break;
83 }
84
85 if (_istream.good()) {
86 return AI_SUCCESS;
87 } else {
88 return AI_FAILURE;
89 }
90}
91
92/**
93 * See ftell.
94 */
95 size_t PandaIOStream::
96 Tell() const {
97 return _istream.tellg();
98}
99
100/**
101 * See fwrite.
102 */
103 size_t PandaIOStream::
104 Write(const void *buffer, size_t size, size_t count) {
105 nassertr(false, 0);
106 return 0;
107}
PandaIOStream::Flush
void Flush()
See fflush.
Definition pandaIOStream.cxx:42
PandaIOStream::FileSize
size_t FileSize() const
Returns the size of this file.
Definition pandaIOStream.cxx:29
PandaIOStream::Tell
size_t Tell() const
See ftell.
Definition pandaIOStream.cxx:96
PandaIOStream::Read
size_t Read(void *pvBuffer, size_t pSize, size_t pCount)
See fread.
Definition pandaIOStream.cxx:50
PandaIOStream::Seek
aiReturn Seek(size_t pOffset, aiOrigin pOrigin)
See fseek.
Definition pandaIOStream.cxx:65
PandaIOStream::Write
size_t Write(const void *buffer, size_t size, size_t count)
See fwrite.
Definition pandaIOStream.cxx:104
pandaIOStream.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.