📄 wg__resource__handle_8cpp-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>wg_resource_handle.cpp 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="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Data Structures</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Data Fields</a> </center><hr><h1>wg_resource_handle.cpp</h1><div class="fragment"><pre>00001 <span class="comment">// wg_resource_handle.cpp</span>00002 <span class="comment">//</span>00003 <span class="comment">// Resource Handle implementation</span>00004 <span class="comment">//</span>00005 <span class="comment">//</span>00006 <span class="comment">// Copyright (c) 2002 Rob Wiskow</span>00007 <span class="comment">// rob-dev@boxedchaos.com</span>00008 <span class="comment">//</span>00009 <span class="comment">// This library is free software; you can redistribute it and/or</span>00010 <span class="comment">// modify it under the terms of the GNU Lesser General Public</span>00011 <span class="comment">// License as published by the Free Software Foundation; either</span>00012 <span class="comment">// version 2.1 of the License, or (at your option) any later version.</span>00013 <span class="comment">//</span>00014 <span class="comment">// This library is distributed in the hope that it will be useful,</span>00015 <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span>00016 <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>00017 <span class="comment">// Lesser General Public License for more details.</span>00018 <span class="comment">//</span>00019 <span class="comment">// You should have received a copy of the GNU Lesser General Public</span>00020 <span class="comment">// License along with this library; if not, write to the Free Software</span>00021 <span class="comment">// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>00022 <span class="comment">//</span>00023 00024 <span class="preprocessor">#include "wgui_include_config.h"</span>00025 <span class="preprocessor">#include "wg_resource_handle.h"</span>00026 <span class="preprocessor">#include "wg_error.h"</span>00027 00028 <span class="keyword">namespace </span>wGui00029 {00030 00031 std::map<TResourceId, unsigned int> CResourceHandle::m_RefCountMap;<a name="l00032"></a><a class="code" href="classwGui_1_1CBitmapResourceHandle.html#q0">00032</a> std::map<TResourceId, SDL_Surface*> CBitmapResourceHandle::m_BitmapMap;<a name="l00033"></a><a class="code" href="classwGui_1_1CStringResourceHandle.html#q0">00033</a> std::map<TResourceId, std::string> CStringResourceHandle::m_StringMap;<a name="l00034"></a><a class="code" href="classwGui_1_1CCursorResourceHandle.html#q0">00034</a> std::map<TResourceId, SDL_Cursor*> CCursorResourceHandle::m_SDLCursorMap;00035 TResourceId CResourceHandle::m_NextUnusedResourceId = 10000;00036 00037 <a name="l00038"></a><a class="code" href="classwGui_1_1CResourceHandle.html#a0">00038</a> CResourceHandle::CResourceHandle(TResourceId resId) :00039 m_ResourceId(resId)00040 {00041 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a> == AUTO_CREATE_RESOURCE_ID)00042 {00043 <span class="keywordflow">while</span> (m_RefCountMap.find(m_NextUnusedResourceId) != m_RefCountMap.end())00044 {00045 ++m_NextUnusedResourceId;00046 }00047 <a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a> = m_NextUnusedResourceId;00048 ++m_NextUnusedResourceId;00049 }00050 <span class="keywordflow">if</span> (m_RefCountMap.find(<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>) == m_RefCountMap.end() || m_RefCountMap[<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>] == 0)00051 {00052 m_RefCountMap[<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>] = 0;00053 }00054 ++m_RefCountMap[<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>];00055 }00056 00057 <a name="l00058"></a><a class="code" href="classwGui_1_1CResourceHandle.html#a1">00058</a> CResourceHandle::CResourceHandle(<span class="keyword">const</span> <a class="code" href="classwGui_1_1CResourceHandle.html">CResourceHandle</a>& resHandle)00059 {00060 <a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a> = resHandle.<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>;00061 ++m_RefCountMap[<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>];00062 }00063 00064 <a name="l00065"></a><a class="code" href="classwGui_1_1CResourceHandle.html#a2">00065</a> CResourceHandle::~CResourceHandle(<span class="keywordtype">void</span>)00066 {00067 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CResourceHandle.html#a4">GetRefCount</a>() > 0)00068 {00069 --m_RefCountMap[<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>];00070 }00071 <span class="keywordflow">else</span>00072 {00073 <span class="keywordflow">throw</span>(<a class="code" href="classwGui_1_1Wg__Ex__App.html">Wg_Ex_App</a>(<span class="stringliteral">"CResourceHandle::~CResourceHandle : Trying to decrement refcount of zero!"</span>));00074 }00075 }00076 00077 <a name="l00078"></a><a class="code" href="classwGui_1_1CBitmapResourceHandle.html#a2">00078</a> CBitmapResourceHandle::~CBitmapResourceHandle(<span class="keywordtype">void</span>)00079 {00080 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CResourceHandle.html#a4">GetRefCount</a>() == 1 && <a class="code" href="classwGui_1_1CBitmapResourceHandle.html#q0">m_BitmapMap</a>.find(<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>) != <a class="code" href="classwGui_1_1CBitmapResourceHandle.html#q0">m_BitmapMap</a>.end())00081 {00082 SDL_FreeSurface(<a class="code" href="classwGui_1_1CBitmapResourceHandle.html#q0">m_BitmapMap</a>[<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>]);00083 <a class="code" href="classwGui_1_1CBitmapResourceHandle.html#q0">m_BitmapMap</a>.erase(<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>);00084 }00085 }00086 00087 <a name="l00088"></a><a class="code" href="classwGui_1_1CBitmapResourceHandle.html#a3">00088</a> SDL_Surface* CBitmapResourceHandle::Bitmap(<span class="keywordtype">void</span>)<span class="keyword"> const</span>00089 <span class="keyword"></span>{00090 <span class="keywordflow">return</span> (<a class="code" href="classwGui_1_1CBitmapResourceHandle.html#q0">m_BitmapMap</a>.find(<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>) != <a class="code" href="classwGui_1_1CBitmapResourceHandle.html#q0">m_BitmapMap</a>.end()) ? <a class="code" href="classwGui_1_1CBitmapResourceHandle.html#q0">m_BitmapMap</a>[<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>] : 0;00091 }00092 00093 <a name="l00094"></a><a class="code" href="classwGui_1_1CBitmapFileResourceHandle.html#a0">00094</a> CBitmapFileResourceHandle::CBitmapFileResourceHandle(std::string sFilename) :00095 <a class="code" href="classwGui_1_1CBitmapResourceHandle.html">CBitmapResourceHandle</a>(AUTO_CREATE_RESOURCE_ID),00096 m_sFilename(sFilename)00097 {00098 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CBitmapResourceHandle.html#q0">m_BitmapMap</a>.find(<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>) == <a class="code" href="classwGui_1_1CBitmapResourceHandle.html#q0">m_BitmapMap</a>.end())00099 {00100 <a class="code" href="classwGui_1_1CBitmapResourceHandle.html#q0">m_BitmapMap</a>[<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>] = SDL_LoadBMP(<a class="code" href="classwGui_1_1CBitmapFileResourceHandle.html#n0">m_sFilename</a>.c_str());00101 }00102 }00103 00104 <a name="l00105"></a><a class="code" href="classwGui_1_1CStringResourceHandle.html#a2">00105</a> CStringResourceHandle::~CStringResourceHandle(<span class="keywordtype">void</span>)00106 {00107 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CResourceHandle.html#a4">GetRefCount</a>() == 1 && <a class="code" href="classwGui_1_1CStringResourceHandle.html#q0">m_StringMap</a>.find(<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>) != <a class="code" href="classwGui_1_1CStringResourceHandle.html#q0">m_StringMap</a>.end())00108 {00109 <a class="code" href="classwGui_1_1CStringResourceHandle.html#q0">m_StringMap</a>.erase(<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>);00110 }00111 }00112 00113 <a name="l00114"></a><a class="code" href="classwGui_1_1CStringResourceHandle.html#a3">00114</a> <span class="keyword">const</span> std::string CStringResourceHandle::String(<span class="keywordtype">void</span>)<span class="keyword"> const</span>00115 <span class="keyword"></span>{00116 <span class="keywordflow">return</span> (<a class="code" href="classwGui_1_1CStringResourceHandle.html#q0">m_StringMap</a>.find(<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>) != <a class="code" href="classwGui_1_1CStringResourceHandle.html#q0">m_StringMap</a>.end()) ? <a class="code" href="classwGui_1_1CStringResourceHandle.html#q0">m_StringMap</a>[<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>] : <span class="stringliteral">""</span>;00117 }00118 00119 <a name="l00120"></a><a class="code" href="classwGui_1_1CCursorResourceHandle.html#a2">00120</a> CCursorResourceHandle::~CCursorResourceHandle(<span class="keywordtype">void</span>)00121 {00122 <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CResourceHandle.html#a4">GetRefCount</a>() == 1 && <a class="code" href="classwGui_1_1CCursorResourceHandle.html#q0">m_SDLCursorMap</a>.find(<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>) != <a class="code" href="classwGui_1_1CCursorResourceHandle.html#q0">m_SDLCursorMap</a>.end())00123 {00124 SDL_FreeCursor(<a class="code" href="classwGui_1_1CCursorResourceHandle.html#q0">m_SDLCursorMap</a>[<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>]);00125 <a class="code" href="classwGui_1_1CCursorResourceHandle.html#q0">m_SDLCursorMap</a>.erase(<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>);00126 }00127 }00128 00129 <a name="l00130"></a><a class="code" href="classwGui_1_1CCursorResourceHandle.html#a3">00130</a> SDL_Cursor* CCursorResourceHandle::Cursor(<span class="keywordtype">void</span>)<span class="keyword"> const</span>00131 <span class="keyword"></span>{00132 <span class="keywordflow">return</span> (<a class="code" href="classwGui_1_1CCursorResourceHandle.html#q0">m_SDLCursorMap</a>.find(<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>) != <a class="code" href="classwGui_1_1CCursorResourceHandle.html#q0">m_SDLCursorMap</a>.end()) ? <a class="code" href="classwGui_1_1CCursorResourceHandle.html#q0">m_SDLCursorMap</a>[<a class="code" href="classwGui_1_1CResourceHandle.html#n0">m_ResourceId</a>] : 0;00133 }00134 00135 }</pre></div><hr><address style="align: right;"><small>Generated on Sat Oct 25 12:43:24 2003 for wGui by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 width=110 height=53></a>1.2.18 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -