00001 // Filename: pandaIOStream.cxx 00002 // Created by: rdb (29Mar11) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "pandaIOStream.h" 00016 00017 00018 //////////////////////////////////////////////////////////////////// 00019 // Function: PandaIOStream::Constructor 00020 // Access: Public 00021 // Description: 00022 //////////////////////////////////////////////////////////////////// 00023 PandaIOStream:: 00024 PandaIOStream(istream &stream) : _istream(stream) { 00025 } 00026 00027 //////////////////////////////////////////////////////////////////// 00028 // Function: PandaIOStream::FileSize 00029 // Access: Public 00030 // Description: Returns the size of this file. 00031 //////////////////////////////////////////////////////////////////// 00032 size_t PandaIOStream:: 00033 FileSize() const { 00034 streampos cur = _istream.tellg(); 00035 _istream.seekg(0, ios::end); 00036 streampos end = _istream.tellg(); 00037 _istream.seekg(cur, ios::beg); 00038 return end; 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function: PandaIOStream::Flush 00043 // Access: Public 00044 // Description: See fflush. 00045 //////////////////////////////////////////////////////////////////// 00046 void PandaIOStream:: 00047 Flush() { 00048 nassertv(false); 00049 } 00050 00051 //////////////////////////////////////////////////////////////////// 00052 // Function: PandaIOStream::Read 00053 // Access: Public 00054 // Description: See fread. 00055 //////////////////////////////////////////////////////////////////// 00056 size_t PandaIOStream:: 00057 Read(void *buffer, size_t size, size_t count) { 00058 _istream.read((char*) buffer, size * count); 00059 return _istream.gcount(); 00060 } 00061 00062 //////////////////////////////////////////////////////////////////// 00063 // Function: PandaIOStream::Seek 00064 // Access: Public 00065 // Description: See fseek. 00066 //////////////////////////////////////////////////////////////////// 00067 aiReturn PandaIOStream:: 00068 Seek(size_t offset, aiOrigin origin) { 00069 switch (origin) { 00070 case aiOrigin_SET: 00071 _istream.seekg(offset, ios::beg); 00072 break; 00073 00074 case aiOrigin_CUR: 00075 _istream.seekg(offset, ios::cur); 00076 break; 00077 00078 case aiOrigin_END: 00079 _istream.seekg(offset, ios::end); 00080 break; 00081 } 00082 00083 if (_istream.good()) { 00084 return AI_SUCCESS; 00085 } else { 00086 return AI_FAILURE; 00087 } 00088 } 00089 00090 //////////////////////////////////////////////////////////////////// 00091 // Function: PandaIOStream::Tell 00092 // Access: Public 00093 // Description: See ftell. 00094 //////////////////////////////////////////////////////////////////// 00095 size_t PandaIOStream:: 00096 Tell() const { 00097 return _istream.tellg(); 00098 } 00099 00100 //////////////////////////////////////////////////////////////////// 00101 // Function: PandaIOStream::Write 00102 // Access: Public 00103 // Description: See fwrite. 00104 //////////////////////////////////////////////////////////////////// 00105 size_t PandaIOStream:: 00106 Write(const void *buffer, size_t size, size_t count) { 00107 nassertr(false, 0); 00108 }