StreamBuffer.h

Go to the documentation of this file.
00001 /*
00002  *    Copyright 2004-2006 Intel Corporation
00003  * 
00004  *    Licensed under the Apache License, Version 2.0 (the "License");
00005  *    you may not use this file except in compliance with the License.
00006  *    You may obtain a copy of the License at
00007  * 
00008  *        http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  *    Unless required by applicable law or agreed to in writing, software
00011  *    distributed under the License is distributed on an "AS IS" BASIS,
00012  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *    See the License for the specific language governing permissions and
00014  *    limitations under the License.
00015  */
00016 
00017 #ifndef _OASYS_STREAM_BUFFER_H_
00018 #define _OASYS_STREAM_BUFFER_H_
00019 
00020 #include <stdlib.h>
00021 
00022 namespace oasys {
00023 
00034 class StreamBuffer {
00035 public:
00039     StreamBuffer(size_t size = DEFAULT_BUFSIZE);
00040     ~StreamBuffer();
00041 
00046     void set_size(size_t size);
00047 
00050     char* data() { return &buf_[0]; }
00051     
00053     char* start();
00054     
00056     char* end();
00057     
00059     void reserve(size_t amount);
00060 
00062     void fill(size_t amount);
00063     
00065     void consume(size_t amount);
00066 
00068     void clear();
00069 
00071     size_t size()   { return size_; }
00072     
00074     size_t fullbytes();
00075 
00077     size_t tailbytes();
00078 
00079 private:
00081     void realloc(size_t size);
00082 
00086     void moveup();
00087 
00088     size_t start_;
00089     size_t end_;
00090     size_t size_;
00091 
00092     char* buf_;
00093 
00094     static const size_t DEFAULT_BUFSIZE = 512;
00095 };
00096 
00097 } // namespace oasys
00098  
00099 #endif //_OASYS_STREAM_BUFFER_H_

Generated on Thu Jun 7 16:56:52 2007 for DTN Reference Implementation by  doxygen 1.5.1