00001 // Filename: buffer.cxx 00002 // Created by: mike (09Jan97) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 #include "buffer.h" 00019 00020 //////////////////////////////////////////////////////////////////// 00021 // Defines 00022 //////////////////////////////////////////////////////////////////// 00023 00024 //////////////////////////////////////////////////////////////////// 00025 // Function: Buffer::Constructor 00026 // Access: Public 00027 // Description: 00028 //////////////////////////////////////////////////////////////////// 00029 Buffer:: 00030 Buffer(int size) { 00031 _length = size; 00032 _buffer = new char[_length]; 00033 } 00034 00035 //////////////////////////////////////////////////////////////////// 00036 // Function: Buffer::Destructor 00037 // Access: Public 00038 // Description: 00039 //////////////////////////////////////////////////////////////////// 00040 Buffer:: 00041 ~Buffer() { 00042 delete _buffer; 00043 } 00044 00045 00046 //////////////////////////////////////////////////////////////////// 00047 // Function: Ramfile::readline 00048 // Access: Published 00049 // Description: Assumes the stream represents a text file, and 00050 // extracts one line up to and including the trailing 00051 // newline character. Returns empty string when the end 00052 // of file is reached. 00053 // 00054 // The interface here is intentionally designed to be 00055 // similar to that for Python's File.readline() 00056 // function. 00057 //////////////////////////////////////////////////////////////////// 00058 string Ramfile:: 00059 readline() { 00060 size_t start = _pos; 00061 while (_pos < _data.length() && _data[_pos] != '\n') { 00062 ++_pos; 00063 } 00064 00065 if (_pos < _data.length() && _data[_pos] == '\n') { 00066 // Include the newline character also. 00067 ++_pos; 00068 } 00069 00070 return _data.substr(start, _pos - start); 00071 } 00072