Click here to Skip to main content
15,893,663 members
Articles / Programming Languages / C#

An extensible math expression parser with plug-ins

Rate me:
Please Sign up or sign in to vote.
4.92/5 (147 votes)
13 Mar 2008CPOL51 min read 1.4M   29K   364  
Design and code for an extensible, maintainable, robust, and easy to use math parser.
<!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>MTParserLib: MTGlobalString.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.4 -->
<div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</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="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div>
<h1>MTGlobalString.h</h1><a href="MTGlobalString_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/** @file MTGlobalString.h      </span>
<a name="l00002"></a>00002 <span class="comment">        @author (c) 2008 Mathieu Jacques</span>
<a name="l00003"></a>00003 <span class="comment">*/</span>
<a name="l00004"></a>00004 
<a name="l00005"></a>00005 
<a name="l00006"></a>00006 <span class="preprocessor">#ifndef _MTGLOBALSTRING_INCLUDED</span>
<a name="l00007"></a>00007 <span class="preprocessor"></span><span class="preprocessor">#define _MTGLOBALSTRING_INCLUDED</span>
<a name="l00008"></a>00008 <span class="preprocessor"></span>
<a name="l00009"></a>00009 <span class="preprocessor">#include "<a class="code" href="MTUnicodeANSIDefs_8h.html">MTUnicodeANSIDefs.h</a>"</span>
<a name="l00010"></a>00010 <span class="preprocessor">#include &lt;windows.h&gt;</span>
<a name="l00011"></a>00011 
<a name="l00012"></a>00012 <span class="comment"></span>
<a name="l00013"></a>00013 <span class="comment">/** @brief String allocated in global memory */</span>
<a name="l00014"></a><a class="code" href="classMTGlobalString.html">00014</a> <span class="keyword">class </span><a class="code" href="classMTGlobalString.html">MTGlobalString</a>
<a name="l00015"></a>00015 {
<a name="l00016"></a>00016 <span class="keyword">public</span>:
<a name="l00017"></a>00017 <span class="comment"></span>
<a name="l00018"></a>00018 <span class="comment">        /** @brief Create an empty string */</span>
<a name="l00019"></a><a class="code" href="classMTGlobalString.html#a0">00019</a>         <a class="code" href="classMTGlobalString.html#a0">MTGlobalString</a>(){ m_buffer = NULL; m_size = 0;}
<a name="l00020"></a>00020         <span class="comment"></span>
<a name="l00021"></a>00021 <span class="comment">        /** @brief Copy an existing string */</span>
<a name="l00022"></a><a class="code" href="classMTGlobalString.html#a1">00022</a>         <a class="code" href="classMTGlobalString.html#a0">MTGlobalString</a>(<span class="keyword">const</span> <a class="code" href="classMTGlobalString.html">MTGlobalString</a> &amp;obj)
<a name="l00023"></a>00023         {
<a name="l00024"></a>00024                 m_buffer = NULL;                
<a name="l00025"></a>00025                 <a class="code" href="classMTGlobalString.html#a3">operator=</a>(obj);
<a name="l00026"></a>00026         }
<a name="l00027"></a>00027 <span class="comment"></span>
<a name="l00028"></a>00028 <span class="comment">        /** @brief Copy an existing string */</span>
<a name="l00029"></a><a class="code" href="classMTGlobalString.html#a2">00029</a>         <a class="code" href="classMTGlobalString.html#a0">MTGlobalString</a>(<span class="keyword">const</span> <a class="code" href="MTUnicodeANSIDefs_8h.html#a1">MTCHAR</a> *str)
<a name="l00030"></a>00030         {
<a name="l00031"></a>00031                 m_buffer = NULL;                
<a name="l00032"></a>00032                 allocStr(str);
<a name="l00033"></a>00033         }
<a name="l00034"></a>00034 <span class="comment"></span>
<a name="l00035"></a>00035 <span class="comment">        /** @brief Copy an existing string */</span>
<a name="l00036"></a><a class="code" href="classMTGlobalString.html#a3">00036</a>         <a class="code" href="classMTGlobalString.html">MTGlobalString</a>&amp; <a class="code" href="classMTGlobalString.html#a3">operator=</a>(<span class="keyword">const</span> <a class="code" href="classMTGlobalString.html">MTGlobalString</a> &amp;obj)
<a name="l00037"></a>00037         {
<a name="l00038"></a>00038                 allocStr(obj.<a class="code" href="classMTGlobalString.html#a7">c_str</a>());
<a name="l00039"></a>00039                 <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00040"></a>00040         }
<a name="l00041"></a>00041 <span class="comment"></span>
<a name="l00042"></a>00042 <span class="comment">        /** @brief Copy an existing string */</span>
<a name="l00043"></a><a class="code" href="classMTGlobalString.html#a4">00043</a>         <a class="code" href="classMTGlobalString.html">MTGlobalString</a>&amp; <a class="code" href="classMTGlobalString.html#a3">operator=</a>(<span class="keyword">const</span> <a class="code" href="MTUnicodeANSIDefs_8h.html#a1">MTCHAR</a> *str)
<a name="l00044"></a>00044         {
<a name="l00045"></a>00045                 allocStr(str);
<a name="l00046"></a>00046                 <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00047"></a>00047         }
<a name="l00048"></a>00048 
<a name="l00049"></a><a class="code" href="classMTGlobalString.html#a5">00049</a>         <span class="keywordtype">bool</span> <a class="code" href="classMTGlobalString.html#a5">operator==</a>(<span class="keyword">const</span> <a class="code" href="MTUnicodeANSIDefs_8h.html#a1">MTCHAR</a> *str)<span class="keyword">const</span>
<a name="l00050"></a>00050 <span class="keyword">        </span>{
<a name="l00051"></a>00051                 <span class="keywordflow">return</span> lstrcmp(<a class="code" href="classMTGlobalString.html#a7">c_str</a>(), str) == 0;
<a name="l00052"></a>00052         }
<a name="l00053"></a>00053 
<a name="l00054"></a><a class="code" href="classMTGlobalString.html#a6">00054</a>         <span class="keywordtype">bool</span> <a class="code" href="classMTGlobalString.html#a6">operator!=</a>(<span class="keyword">const</span> <a class="code" href="MTUnicodeANSIDefs_8h.html#a1">MTCHAR</a> *str)<span class="keyword">const</span>
<a name="l00055"></a>00055 <span class="keyword">        </span>{
<a name="l00056"></a>00056                 <span class="keywordflow">return</span> lstrcmp(<a class="code" href="classMTGlobalString.html#a7">c_str</a>(), str) != 0;
<a name="l00057"></a>00057         }
<a name="l00058"></a>00058 <span class="comment"></span>
<a name="l00059"></a>00059 <span class="comment">        /** @brief Get the string */</span>
<a name="l00060"></a><a class="code" href="classMTGlobalString.html#a7">00060</a>         <span class="keyword">const</span> <a class="code" href="MTUnicodeANSIDefs_8h.html#a1">MTCHAR</a>* <a class="code" href="classMTGlobalString.html#a7">c_str</a>()<span class="keyword">const</span>
<a name="l00061"></a>00061 <span class="keyword">        </span>{
<a name="l00062"></a>00062                 <span class="keywordflow">if</span>( m_buffer == NULL )
<a name="l00063"></a>00063                 {
<a name="l00064"></a>00064                         <span class="keywordflow">return</span> _T(<span class="stringliteral">""</span>);
<a name="l00065"></a>00065                 }
<a name="l00066"></a>00066                 <span class="keywordflow">else</span>
<a name="l00067"></a>00067                 {
<a name="l00068"></a>00068                         <span class="keywordflow">return</span> (<a class="code" href="MTUnicodeANSIDefs_8h.html#a1">MTCHAR</a>*)m_buffer;
<a name="l00069"></a>00069                 }
<a name="l00070"></a>00070         }
<a name="l00071"></a>00071 <span class="comment"></span>
<a name="l00072"></a>00072 <span class="comment">        /** @brief Get the size of the string in characters */</span>
<a name="l00073"></a><a class="code" href="classMTGlobalString.html#a8">00073</a>         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classMTGlobalString.html#a8">size</a>()<span class="keyword">const</span>
<a name="l00074"></a>00074 <span class="keyword">        </span>{
<a name="l00075"></a>00075                 <span class="keywordflow">return</span> m_size;
<a name="l00076"></a>00076         }
<a name="l00077"></a>00077 
<a name="l00078"></a><a class="code" href="classMTGlobalString.html#a9">00078</a>         <a class="code" href="classMTGlobalString.html#a9">~MTGlobalString</a>(){ clean(); }
<a name="l00079"></a>00079 
<a name="l00080"></a>00080 
<a name="l00081"></a>00081 <span class="keyword">private</span>:
<a name="l00082"></a>00082 
<a name="l00083"></a>00083         <span class="keywordtype">void</span> clean()
<a name="l00084"></a>00084         {
<a name="l00085"></a>00085                 <span class="keywordflow">if</span>( m_buffer != NULL )
<a name="l00086"></a>00086                 {
<a name="l00087"></a>00087                         SysFreeString(m_buffer);
<a name="l00088"></a>00088                         m_buffer = NULL;
<a name="l00089"></a>00089                         m_size = 0;
<a name="l00090"></a>00090                 }
<a name="l00091"></a>00091         }
<a name="l00092"></a>00092 
<a name="l00093"></a>00093         <span class="keywordtype">void</span> allocStr(<span class="keyword">const</span> <a class="code" href="MTUnicodeANSIDefs_8h.html#a1">MTCHAR</a> *str)
<a name="l00094"></a>00094         {
<a name="l00095"></a>00095                 clean();
<a name="l00096"></a>00096                 m_size = lstrlen(str);
<a name="l00097"></a>00097                 
<a name="l00098"></a>00098                 <span class="comment">// allocate bytes for ANSI and Unicode as well</span>
<a name="l00099"></a>00099                 m_buffer = SysAllocStringByteLen((<span class="keyword">const</span> <span class="keywordtype">char</span>*)str, <span class="keyword">sizeof</span>(<a class="code" href="MTUnicodeANSIDefs_8h.html#a1">MTCHAR</a>)*m_size);              
<a name="l00100"></a>00100         }
<a name="l00101"></a>00101 
<a name="l00102"></a>00102 
<a name="l00103"></a>00103 <span class="keyword">private</span>:
<a name="l00104"></a>00104 
<a name="l00105"></a>00105         BSTR m_buffer;                  <span class="comment">// the string memory buffer</span>
<a name="l00106"></a>00106         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> m_size;    <span class="comment">// the number of characters</span>
<a name="l00107"></a>00107 };
<a name="l00108"></a>00108 
<a name="l00109"></a>00109 <span class="preprocessor">#endif</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Mar 9 17:39:35 2008 for MTParserLib by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.4 </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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Canada Canada
Software Engineer working at a fun and smart startup company

Comments and Discussions