?? buffer__2_8h-source.html
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>buffer_2.h Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.2.18 --><center><a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> </center><hr><h1>buffer_2.h</h1><div class="fragment"><pre>00001 <span class="comment">/*</span>00002 <span class="comment"> ZIG - An extendable, portable game engine focused on networking & scripting</span>00003 <span class="comment"> Project Home: http://zige.sourceforge.net</span>00004 <span class="comment"> Copyright (C) 2002 F醔io Reis Cecin <fcecin AT inf DOT ufrgs DOT br></span>00005 <span class="comment"></span>00006 <span class="comment"> This library is free software; you can redistribute it and/or</span>00007 <span class="comment"> modify it under the terms of the GNU Lesser General Public</span>00008 <span class="comment"> License as published by the Free Software Foundation; either</span>00009 <span class="comment"> version 2.1 of the License, or (at your option) any later version.</span>00010 <span class="comment"></span>00011 <span class="comment"> This library is distributed in the hope that it will be useful,</span>00012 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span>00013 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>00014 <span class="comment"> Lesser General Public License for more details.</span>00015 <span class="comment"></span>00016 <span class="comment"> You should have received a copy of the GNU Lesser General Public</span>00017 <span class="comment"> License along with this library; if not, write to the Free Software</span>00018 <span class="comment"> Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA </span>00019 <span class="comment">*/</span>00020 <span class="comment">/*</span>00021 <span class="comment"></span>00022 <span class="comment"> shared buffer, version 2 - no base class</span>00023 <span class="comment"></span>00024 <span class="comment"> assignment and copy ctor makes DEEP COPY</span>00025 <span class="comment"></span>00026 <span class="comment"> debug the refcounted version + copy on write later, when this version is already working OK.</span>00027 <span class="comment"></span>00028 <span class="comment">*/</span>00029 00030 <span class="keyword">class </span><a class="code" href="classbuffer__c.html">buffer_c</a>;00031 <a name="l00033"></a><a class="code" href="classserializable__c.html">00033</a> <span class="keyword">class </span><a class="code" href="classserializable__c.html">serializable_c</a> {00034 <span class="keyword">public</span>:00035 00042 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classserializable__c.html#a0">read</a>(<a class="code" href="classbuffer__c.html">buffer_c</a> &in);00043 00050 <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classserializable__c.html#a1">write</a>(<a class="code" href="classbuffer__c.html">buffer_c</a> &out) <span class="keyword">const</span>;00051 00052 <span class="comment">// this method is defined by the magic macro ZIG_SERIALIZABLE_CLASS (see typereg.h). this is</span>00053 <span class="comment">// one of the reasons why you need to include ZIG_SERIALIZABLE_CLASS(X) in class X to be </span>00054 <span class="comment">// serializable.</span>00055 <span class="keyword">virtual</span> <span class="keywordtype">int</span> ZIG_GetTypeId() <span class="keyword">const</span> = 0;00056 00057 <span class="comment">// this method is defined by the magic macro ZIG_SERIALIZABLE_CLASS (see typereg.h). this allows</span>00058 <span class="comment">// us to implement the "default serialization" mechanism (which is just a bitwise memcpy).</span>00059 <span class="keyword">virtual</span> <span class="keywordtype">int</span> ZIG_GetMySizeof()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <span class="keyword">sizeof</span>(serializable_c); };00060 };00061 00062 <span class="comment">//define this to make access to a single instance of buffer_c not synchronized</span>00063 <span class="preprocessor">#define BUFFER_NO_SYNC</span>00064 <span class="preprocessor"></span>00065 <span class="comment">//define this to disable statistics collection on buffers</span>00066 <span class="preprocessor">#define BUFFER_NO_STATS</span>00067 <span class="preprocessor"></span>00068 <span class="comment">// includes</span>00069 <span class="preprocessor">#include "zigdefs.h"</span>00070 <span class="preprocessor">#include "thread.h"</span>00071 <span class="preprocessor">#include <string></span>00072 <span class="keyword">using</span> <span class="keyword">namespace </span>std;00073 00074 <span class="comment">//this is the buffer's allocation unit. if big: less alocation, more wasted memory. if small, too much</span>00075 <span class="comment">//allocation, possibly less wasted memory</span>00076 <span class="preprocessor">#define BUFFER_CHUNK_SIZE 128</span>00077 <span class="preprocessor"></span>00078 00079 <span class="preprocessor">#ifndef BUFFER_NO_STATS</span>00080 <span class="preprocessor"></span>00081 <span class="keyword">extern</span> mutex_c cbuffer_mutex;00082 <span class="keyword">extern</span> <span class="keyword">volatile</span> <span class="keywordtype">int</span> cbuffer_count;00083 <span class="keyword">extern</span> <span class="keyword">volatile</span> <span class="keywordtype">int</span> cbuffer_totmem;00084 <span class="keyword">extern</span> <span class="keyword">volatile</span> <span class="keywordtype">int</span> cbuffer_maxmem;00085 00086 <span class="keywordtype">void</span> check_cbuffer_maxmem(<span class="keywordtype">int</span> yeah);00087 00088 <span class="preprocessor">#endif</span>00089 <span class="preprocessor"></span>00090 <span class="comment">// shared buffer reg - a growable buffer</span>00091 <span class="keyword">class </span>buffer_t {00092 <span class="keyword">public</span>:00093 <span class="keywordtype">char</span> *data; <span class="comment">//pointer to buffer</span>00094 <span class="keywordtype">int</span> alen; <span class="comment">//allocated length</span>00095 <span class="keywordtype">int</span> ulen; <span class="comment">//used length</span>00096 buffer_t() {00097 data = 0;00098 alen = 0;00099 ulen = 0;00100 }00101 };00102 00104 <span class="comment">//concrete subclass of shared_c</span><a name="l00105"></a><a class="code" href="classbuffer__c.html">00105</a> <span class="keyword">class </span><a class="code" href="classbuffer__c.html">buffer_c</a> {00106 <span class="keyword">public</span>:00107 00109 <a class="code" href="classbuffer__c.html#a0">buffer_c</a>();00110 00112 <a class="code" href="classbuffer__c.html#a0">buffer_c</a>(<span class="keywordtype">int</span> <a class="code" href="classbuffer__c.html#a14">size</a>);00113 00115 <a class="code" href="classbuffer__c.html#a0">buffer_c</a>(<span class="keyword">const</span> <a class="code" href="classbuffer__c.html">buffer_c</a> &b);00116 00118 <a class="code" href="classbuffer__c.html">buffer_c</a>& <a class="code" href="classbuffer__c.html#a3">operator=</a>(<span class="keyword">const</span> <a class="code" href="classbuffer__c.html">buffer_c</a> &b);00119 00121 <span class="keyword">virtual</span> <a class="code" href="classbuffer__c.html#a4">~buffer_c</a>();00122 00126 <span class="keywordtype">void</span> <a class="code" href="classbuffer__c.html#a5">wrap</a>(<span class="keywordtype">char</span> *buffer, <span class="keywordtype">int</span> buffer_size);00127 00129 <span class="keywordtype">void</span> <a class="code" href="classbuffer__c.html#a6">purge</a>();00130 00133 <span class="keywordtype">void</span> <a class="code" href="classbuffer__c.html#a7">ensure_capacity</a>(<span class="keywordtype">int</span> capacity);00134 00137 <span class="keywordtype">int</span> <a class="code" href="classbuffer__c.html#a8">get_capacity</a>();00138 00140 <span class="keywordtype">void</span> <a class="code" href="classbuffer__c.html#a9">clear</a>();00141 00143 <span class="keywordtype">void</span> <a class="code" href="classbuffer__c.html#a10">seek</a>(<span class="keywordtype">int</span> ptarg);00144 00146 <span class="keywordtype">void</span> <a class="code" href="classbuffer__c.html#a11">seek_end</a>();00147 00149 <span class="keywordtype">void</span> <a class="code" href="classbuffer__c.html#a12">skip</a>(<span class="keywordtype">int</span> amount);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -