<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <meta http-equiv="X-UA-Compatible" content="IE=9"/> <title>edelib: edelib/EdbusContainer.h Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="top"><!-- do not remove this div! --> <div id="titlearea"> <table cellspacing="0" cellpadding="0"> <tbody> <tr style="height: 56px;"> <td style="padding-left: 0.5em;"> <div id="projectname">edelib  <span id="projectnumber">2.0.0</span> </div> </td> </tr> </tbody> </table> </div> <!-- Generated by Doxygen 1.7.6.1 --> <div id="navrow1" class="tabs"> <ul class="tablist"> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div id="navrow2" class="tabs2"> <ul class="tablist"> <li><a href="files.html"><span>File List</span></a></li> </ul> </div> </div> <div class="header"> <div class="headertitle"> <div class="title">edelib/EdbusContainer.h</div> </div> </div><!--header--> <div class="contents"> <div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span> <a name="l00002"></a>00002 <span class="comment"> * $Id: EdbusContainer.h 2839 2009-09-28 11:36:20Z karijes $</span> <a name="l00003"></a>00003 <span class="comment"> *</span> <a name="l00004"></a>00004 <span class="comment"> * D-BUS stuff</span> <a name="l00005"></a>00005 <span class="comment"> * Copyright (c) 2008 edelib authors</span> <a name="l00006"></a>00006 <span class="comment"> *</span> <a name="l00007"></a>00007 <span class="comment"> * This library is free software; you can redistribute it and/or</span> <a name="l00008"></a>00008 <span class="comment"> * modify it under the terms of the GNU Lesser General Public</span> <a name="l00009"></a>00009 <span class="comment"> * License as published by the Free Software Foundation; either</span> <a name="l00010"></a>00010 <span class="comment"> * version 2 of the License, or (at your option) any later version.</span> <a name="l00011"></a>00011 <span class="comment"> *</span> <a name="l00012"></a>00012 <span class="comment"> * This library is distributed in the hope that it will be useful,</span> <a name="l00013"></a>00013 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span> <a name="l00014"></a>00014 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span> <a name="l00015"></a>00015 <span class="comment"> * Lesser General Public License for more details.</span> <a name="l00016"></a>00016 <span class="comment"> *</span> <a name="l00017"></a>00017 <span class="comment"> * You should have received a copy of the GNU Lesser General Public License</span> <a name="l00018"></a>00018 <span class="comment"> * along with this library. If not, see <http://www.gnu.org/licenses/>.</span> <a name="l00019"></a>00019 <span class="comment"> */</span> <a name="l00020"></a>00020 <a name="l00021"></a>00021 <span class="preprocessor">#ifndef __EDELIB_EDBUSCONTAINER_H__</span> <a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#define __EDELIB_EDBUSCONTAINER_H__</span> <a name="l00023"></a>00023 <span class="preprocessor"></span> <a name="l00024"></a>00024 <span class="preprocessor">#include "List.h"</span> <a name="l00025"></a>00025 <a name="l00026"></a>00026 EDELIB_NS_BEGIN <a name="l00027"></a>00027 <a name="l00028"></a>00028 <span class="preprocessor">#ifndef SKIP_DOCS</span> <a name="l00029"></a>00029 <span class="preprocessor"></span><span class="keyword">template</span> <<span class="keyword">typename</span> T> <a name="l00030"></a>00030 <span class="keyword">struct </span>EdbusContainerImpl { <a name="l00031"></a>00031 list<T> lst; <a name="l00032"></a>00032 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> ref; <a name="l00033"></a>00033 }; <a name="l00034"></a>00034 <span class="preprocessor">#endif</span> <a name="l00035"></a>00035 <span class="preprocessor"></span> <a name="l00051"></a>00051 <span class="keyword">template</span> <<span class="keyword">typename</span> T> <a name="l00052"></a><a class="code" href="classedelib_1_1EdbusContainer.html">00052</a> <span class="keyword">class </span><a class="code" href="classedelib_1_1EdbusContainer.html" title="Abstract container for D-Bus containers.">EdbusContainer</a> { <a name="l00053"></a>00053 <span class="keyword">public</span>: <a name="l00057"></a><a class="code" href="classedelib_1_1EdbusContainer.html#ab64ef1a4698ff05a0ebb5228e5beb98a">00057</a> <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="code" href="classedelib_1_1list.html" title="Linked list class.">list<T>::iterator</a> <a class="code" href="classedelib_1_1EdbusContainer.html#ab64ef1a4698ff05a0ebb5228e5beb98a">iterator</a>; <a name="l00058"></a>00058 <a name="l00062"></a><a class="code" href="classedelib_1_1EdbusContainer.html#a7e8e827f4e0bed15c153f1e21c0c03ee">00062</a> <span class="keyword">typedef</span> <span class="keyword">typename</span> <a class="code" href="classedelib_1_1list.html" title="Linked list class.">list<T>::const_iterator</a> <a class="code" href="classedelib_1_1EdbusContainer.html#a7e8e827f4e0bed15c153f1e21c0c03ee">const_iterator</a>; <a name="l00063"></a>00063 <a name="l00064"></a>00064 <span class="preprocessor">#ifndef SKIP_DOCS</span> <a name="l00065"></a>00065 <span class="preprocessor"></span> <span class="keyword">typedef</span> EdbusContainerImpl<T> EdbusContainerPrivate; <a name="l00066"></a>00066 <span class="preprocessor">#endif</span> <a name="l00067"></a>00067 <span class="preprocessor"></span> <a name="l00068"></a>00068 <span class="keyword">protected</span>: <a name="l00072"></a><a class="code" href="classedelib_1_1EdbusContainer.html#a09eeff04b91fa500515a04eb31ba2a74">00072</a> EdbusContainerPrivate* <a class="code" href="classedelib_1_1EdbusContainer.html#a09eeff04b91fa500515a04eb31ba2a74">impl</a>; <a name="l00073"></a>00073 <a name="l00077"></a><a class="code" href="classedelib_1_1EdbusContainer.html#ac316ecc1ad3e8448f959f4d12e2c831d">00077</a> <span class="keywordtype">void</span> <a class="code" href="classedelib_1_1EdbusContainer.html#ac316ecc1ad3e8448f959f4d12e2c831d">dispose</a>(<span class="keywordtype">void</span>) { <a name="l00078"></a>00078 <span class="keywordflow">if</span>(!impl) <a name="l00079"></a>00079 <span class="keywordflow">return</span>; <a name="l00080"></a>00080 <a name="l00081"></a>00081 <span class="keyword">delete</span> impl; <a name="l00082"></a>00082 impl = 0; <a name="l00083"></a>00083 } <a name="l00084"></a>00084 <a name="l00090"></a><a class="code" href="classedelib_1_1EdbusContainer.html#adc83f10ad5dd3f037242af690efc1676">00090</a> <span class="keywordtype">void</span> <a class="code" href="classedelib_1_1EdbusContainer.html#adc83f10ad5dd3f037242af690efc1676">unhook</a>(<span class="keywordtype">void</span>) { <a name="l00091"></a>00091 <a class="code" href="group__macros.html#ga06190892c613d62224455b01c5459c15">E_ASSERT</a>(impl != NULL); <a name="l00092"></a>00092 <a name="l00093"></a>00093 <span class="keywordflow">if</span>(impl->ref == 1) <a name="l00094"></a>00094 <span class="keywordflow">return</span>; <a name="l00095"></a>00095 <a name="l00096"></a>00096 EdbusContainerPrivate* new_one = <span class="keyword">new</span> EdbusContainerPrivate; <a name="l00097"></a>00097 new_one->ref = 1; <a name="l00098"></a>00098 <a name="l00099"></a>00099 <span class="comment">/* </span> <a name="l00100"></a>00100 <span class="comment"> * Copy the content</span> <a name="l00101"></a>00101 <span class="comment"> *</span> <a name="l00102"></a>00102 <span class="comment"> * edelib::list does not have implemented copy operator</span> <a name="l00103"></a>00103 <span class="comment"> * and that is the way I like</span> <a name="l00104"></a>00104 <span class="comment"> */</span> <a name="l00105"></a>00105 <span class="keywordflow">if</span>(impl->lst.size() > 0) { <a name="l00106"></a>00106 <a class="code" href="classedelib_1_1EdbusContainer.html#ab64ef1a4698ff05a0ebb5228e5beb98a">iterator</a> it = impl->lst.begin(), it_end = impl->lst.end(); <a name="l00107"></a>00107 <a name="l00108"></a>00108 <span class="keywordflow">while</span>(it != it_end) { <a name="l00109"></a>00109 new_one->lst.push_back(*it); <a name="l00110"></a>00110 ++it; <a name="l00111"></a>00111 } <a name="l00112"></a>00112 } <a name="l00113"></a>00113 <a name="l00114"></a>00114 impl->ref--; <a name="l00115"></a>00115 impl = new_one; <a name="l00116"></a>00116 } <a name="l00117"></a>00117 <a name="l00121"></a><a class="code" href="classedelib_1_1EdbusContainer.html#a1896d2740b6973c23cd2b941f4943bb5">00121</a> <a class="code" href="classedelib_1_1EdbusContainer.html#a1896d2740b6973c23cd2b941f4943bb5">EdbusContainer</a>() : impl(0) { <a name="l00122"></a>00122 impl = <span class="keyword">new</span> EdbusContainerPrivate; <a name="l00123"></a>00123 impl->ref = 1; <a name="l00124"></a>00124 }; <a name="l00125"></a>00125 <a name="l00129"></a><a class="code" href="classedelib_1_1EdbusContainer.html#a5829e1d271bbae454d49a37893ee3987">00129</a> <a class="code" href="classedelib_1_1EdbusContainer.html#a5829e1d271bbae454d49a37893ee3987">EdbusContainer</a>(<span class="keyword">const</span> <a class="code" href="classedelib_1_1EdbusContainer.html" title="Abstract container for D-Bus containers.">EdbusContainer</a>& other) { <a name="l00130"></a>00130 <span class="keywordflow">if</span>(<span class="keyword">this</span> == &other) <a name="l00131"></a>00131 <span class="keywordflow">return</span>; <a name="l00132"></a>00132 <a name="l00133"></a>00133 impl = other.<a class="code" href="classedelib_1_1EdbusContainer.html#a09eeff04b91fa500515a04eb31ba2a74">impl</a>; <a name="l00134"></a>00134 other.<a class="code" href="classedelib_1_1EdbusContainer.html#a09eeff04b91fa500515a04eb31ba2a74">impl</a>->ref++; <a name="l00135"></a>00135 } <a name="l00136"></a>00136 <a name="l00141"></a><a class="code" href="classedelib_1_1EdbusContainer.html#ae2868697a0c61fbf99f6d93cfc81f574">00141</a> <a class="code" href="classedelib_1_1EdbusContainer.html#ae2868697a0c61fbf99f6d93cfc81f574">~EdbusContainer</a>() { <a name="l00142"></a>00142 impl->ref--; <a name="l00143"></a>00143 <a name="l00144"></a>00144 <span class="keywordflow">if</span>(impl->ref == 0) <a name="l00145"></a>00145 dispose(); <a name="l00146"></a>00146 } <a name="l00147"></a>00147 <a name="l00151"></a><a class="code" href="classedelib_1_1EdbusContainer.html#a62baf0cc7e066f3b83ce10b90b618196">00151</a> <a class="code" href="classedelib_1_1EdbusContainer.html" title="Abstract container for D-Bus containers.">EdbusContainer</a>& <a class="code" href="classedelib_1_1EdbusContainer.html#a62baf0cc7e066f3b83ce10b90b618196">operator=</a>(<span class="keyword">const</span> <a class="code" href="classedelib_1_1EdbusContainer.html" title="Abstract container for D-Bus containers.">EdbusContainer</a>& other) { <a name="l00152"></a>00152 other.<a class="code" href="classedelib_1_1EdbusContainer.html#a09eeff04b91fa500515a04eb31ba2a74">impl</a>->ref++; <a name="l00153"></a>00153 impl->ref--; <a name="l00154"></a>00154 <a name="l00155"></a>00155 <span class="keywordflow">if</span>(impl->ref == 0) <a name="l00156"></a>00156 dispose(); <a name="l00157"></a>00157 <a name="l00158"></a>00158 impl = other.<a class="code" href="classedelib_1_1EdbusContainer.html#a09eeff04b91fa500515a04eb31ba2a74">impl</a>; <a name="l00159"></a>00159 <span class="keywordflow">return</span> *<span class="keyword">this</span>; <a name="l00160"></a>00160 } <a name="l00161"></a>00161 }; <a name="l00162"></a>00162 <a name="l00163"></a>00163 EDELIB_NS_END <a name="l00164"></a>00164 <span class="preprocessor">#endif</span> </pre></div></div><!-- contents --> <hr class="footer"/><address class="footer"><small> Generated on Tue Jun 5 2012 17:49:02 for edelib by  <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/> </a> 1.7.6.1 </small></address> </body> </html>