mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 01:07:51 -04:00
robusity Ramfile interface
This commit is contained in:
parent
f32eb1a6f8
commit
1c11c51455
@ -25,3 +25,37 @@ INLINE Ramfile::
|
|||||||
Ramfile() {
|
Ramfile() {
|
||||||
_pos = 0;
|
_pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: Ramfile::seek
|
||||||
|
// Access: Published
|
||||||
|
// Description: Moves the data pointer to the indicated byte
|
||||||
|
// position. It is not an error to move the pointer
|
||||||
|
// past the end of data.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE void Ramfile::
|
||||||
|
seek(size_t pos) {
|
||||||
|
_pos = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: Ramfile::tell
|
||||||
|
// Access: Published
|
||||||
|
// Description: Returns the current data pointer position as a byte
|
||||||
|
// offset from the beginning of the stream.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE size_t Ramfile::
|
||||||
|
tell() const {
|
||||||
|
return _pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: Ramfile::get_data
|
||||||
|
// Access: Published
|
||||||
|
// Description: Returns the entire buffer contents as a string,
|
||||||
|
// regardless of the current data pointer.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
INLINE const string &Ramfile::
|
||||||
|
get_data() const {
|
||||||
|
return _data;
|
||||||
|
}
|
||||||
|
@ -18,6 +18,24 @@
|
|||||||
|
|
||||||
#include "ramfile.h"
|
#include "ramfile.h"
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: Ramfile::read
|
||||||
|
// Access: Published
|
||||||
|
// Description: Extracts and returns the indicated number of
|
||||||
|
// characters from the current data pointer, and
|
||||||
|
// advances the data pointer. If the data pointer
|
||||||
|
// exceeds the end of the buffer, returns empty string.
|
||||||
|
//
|
||||||
|
// The interface here is intentionally designed to be
|
||||||
|
// similar to that for Python's file.read() function.
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
string Ramfile::
|
||||||
|
read(size_t length) {
|
||||||
|
size_t orig_pos = _pos;
|
||||||
|
_pos = min(_pos + length, _data.length());
|
||||||
|
return _data.substr(orig_pos, length);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: Ramfile::readline
|
// Function: Ramfile::readline
|
||||||
// Access: Published
|
// Access: Published
|
||||||
@ -27,7 +45,7 @@
|
|||||||
// of file is reached.
|
// of file is reached.
|
||||||
//
|
//
|
||||||
// The interface here is intentionally designed to be
|
// The interface here is intentionally designed to be
|
||||||
// similar to that for Python's File.readline()
|
// similar to that for Python's file.readline()
|
||||||
// function.
|
// function.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
string Ramfile::
|
string Ramfile::
|
||||||
|
@ -32,8 +32,13 @@ class EXPCL_PANDAEXPRESS Ramfile {
|
|||||||
PUBLISHED:
|
PUBLISHED:
|
||||||
INLINE Ramfile();
|
INLINE Ramfile();
|
||||||
|
|
||||||
|
INLINE void seek(size_t pos);
|
||||||
|
INLINE size_t tell() const;
|
||||||
|
string read(size_t length);
|
||||||
string readline();
|
string readline();
|
||||||
|
|
||||||
|
INLINE const string &get_data() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
size_t _pos;
|
size_t _pos;
|
||||||
string _data;
|
string _data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user