Click here to Skip to main content
15,895,667 members
Articles / Programming Languages / C++

An STL-compliant mathematical vector class

Rate me:
Please Sign up or sign in to vote.
3.78/5 (8 votes)
12 May 20056 min read 51.6K   1.1K   25  
A portable implementation of a templated, STL-compliant math vector class.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Math: EObserver.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.2 -->
<div class="qindex"><a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div>
<h1>EObserver.h</h1><a href="_e_observer_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 
00002 <span class="preprocessor">#ifndef E_OBSERVER_H</span>
00003 <span class="preprocessor"></span><span class="preprocessor">#define E_OBSERVER_H</span>
00004 <span class="preprocessor"></span>
00005 <span class="preprocessor">#include &lt;algorithm&gt;</span>
00006 <span class="preprocessor">#include &lt;list&gt;</span>
00007 
00014 <span class="keyword">template</span>&lt;<span class="keyword">typename</span> T&gt;
<a name="l00015"></a><a class="code" href="class_e_subject.html">00015</a> <span class="keyword">class </span><a class="code" href="class_e_subject.html">ESubject</a>
00016 {
00017    <span class="keyword">typedef</span> std::list&lt;T*&gt; EObserverContainer;
00018 <span class="keyword">public</span>:
00019 
<a name="l00026"></a><a class="code" href="class_e_subject.html#a0">00026</a>    <span class="keyword">virtual</span> <a class="code" href="class_e_subject.html#a0">~ESubject</a>() { }
00027 
<a name="l00035"></a><a class="code" href="class_e_subject.html#a1">00035</a>    <span class="keywordtype">void</span> <a class="code" href="class_e_subject.html#a1">addObserver</a>(T* observer)
00036    {
00037       m_observers.push_back(observer);
00038    }
00039 
<a name="l00048"></a><a class="code" href="class_e_subject.html#a2">00048</a>    <span class="keywordtype">void</span> <a class="code" href="class_e_subject.html#a2">removeObserver</a>(T* observer)
00049    {
00050       <span class="keyword">typename</span> EObserverContainer::iterator i = std::find(m_observers.begin(),
00051                                                           m_observers.end(),
00052                                                           observer);
00053       <span class="keywordflow">if</span> (i == m_observers.end()) <span class="keywordflow">return</span>;
00054 
00055       m_observers.erase(i);
00056    }
00057 
00068    <span class="keyword">template</span>&lt;<span class="keyword">typename</span> S&gt;
<a name="l00069"></a><a class="code" href="class_e_subject.html#a3">00069</a>    <span class="keywordtype">void</span> <a class="code" href="class_e_subject.html#a3">notify</a>(S* hint)
00070    {
00071       updateObservers(hint);
00072    }
00073 
00074 <span class="keyword">private</span>:
00075    EObserverContainer m_observers;
00076 
00077    <span class="keyword">template</span>&lt;<span class="keyword">typename</span> S&gt;
00078    <span class="keywordtype">void</span> updateObservers(S* hint)
00079    {
00080       <span class="keywordflow">for</span> (<span class="keyword">typename</span> EObserverContainer::iterator i = m_observers.begin(); i != m_observers.end(); ++i)
00081          (*i)-&gt;updateObserver(<span class="keyword">this</span>, hint);
00082    }
00083 };
00084 
00085 <span class="preprocessor">#endif // E_OBSERVER_H</span>
00086 <span class="preprocessor"></span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu May 12 20:32:58 2005 for Math by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions