git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@40 331e1502-861f-0410-8da2-ba01fb791d7f
113 lines
6.8 KiB
HTML
113 lines
6.8 KiB
HTML
<!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>EO: LanguageTable.cpp Source File</title>
|
|
<link href="doxygen.css" rel="stylesheet" type="text/css">
|
|
</head><body>
|
|
<!-- Generated by Doxygen 1.3.9.1 -->
|
|
<div class="qindex"> <form class="search" action="search.php" method="get">
|
|
<a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="namespaces.html">Namespace List</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">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="pages.html">Related Pages</a> | <span class="search"><u>S</u>earch for <input class="search" type="text" name="query" value="" size="20" accesskey="s"/></span></form></div>
|
|
<div class="nav">
|
|
<a class="el" href="dir_000007.html">contrib</a> / <a class="el" href="dir_000008.html">mathsym</a> / <a class="el" href="dir_000024.html">gen</a></div>
|
|
<h1>LanguageTable.cpp</h1><div class="fragment"><pre class="fragment">00001 <span class="comment">/* </span>
|
|
00002 <span class="comment"> * Copyright (C) 2005 Maarten Keijzer</span>
|
|
00003 <span class="comment"> *</span>
|
|
00004 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
|
|
00005 <span class="comment"> * it under the terms of version 2 of the GNU General Public License as </span>
|
|
00006 <span class="comment"> * published by the Free Software Foundation. </span>
|
|
00007 <span class="comment"> *</span>
|
|
00008 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
|
|
00009 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
|
|
00010 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
|
|
00011 <span class="comment"> * GNU General Public License for more details.</span>
|
|
00012 <span class="comment"> *</span>
|
|
00013 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
|
|
00014 <span class="comment"> * along with this program; if not, write to the Free Software</span>
|
|
00015 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>
|
|
00016 <span class="comment"> */</span>
|
|
00017
|
|
00018
|
|
00019 <span class="preprocessor">#include "LanguageTable.h"</span>
|
|
00020 <span class="preprocessor">#include "Sym.h"</span>
|
|
00021
|
|
00022 <span class="preprocessor">#include <utils/eoRNG.h></span>
|
|
00023
|
|
00024 <span class="keyword">using</span> <span class="keyword">namespace </span>std;
|
|
00025
|
|
00026 <span class="keyword">extern</span> Sym default_const();
|
|
00027
|
|
00028 <span class="keyword">class </span>LanguageImpl {
|
|
00029 <span class="keyword">public</span> :
|
|
00030 std::vector<Sym> vars;
|
|
00031 LanguageTable::erc_func erc;
|
|
00032
|
|
00033 std::vector<functor_t> functions;
|
|
00034 std::vector< std::vector<token_t> > functions_per_arity;
|
|
00035
|
|
00036 LanguageImpl() : erc(default_const) {}
|
|
00037 };
|
|
00038
|
|
00039 LanguageTable::LanguageTable() {
|
|
00040 pimpl = <span class="keyword">new</span> LanguageImpl;
|
|
00041 }
|
|
00042
|
|
00043 LanguageTable::~LanguageTable() {
|
|
00044 <span class="keyword">delete</span> pimpl;
|
|
00045 }
|
|
00046
|
|
00047 LanguageTable::LanguageTable(<span class="keyword">const</span> LanguageTable& that) {
|
|
00048 pimpl = <span class="keyword">new</span> LanguageImpl(*that.pimpl);
|
|
00049 }
|
|
00050
|
|
00051 LanguageTable& LanguageTable::operator=(<span class="keyword">const</span> LanguageTable& that) {
|
|
00052 *pimpl = *that.pimpl;
|
|
00053 <span class="keywordflow">return</span> *<span class="keyword">this</span>;
|
|
00054 }
|
|
00055
|
|
00056 <span class="keywordtype">void</span> LanguageTable::add_function(token_t token, <span class="keywordtype">unsigned</span> arity) {
|
|
00057 functor_t f = {token, arity};
|
|
00058 add_function( f );
|
|
00059 }
|
|
00060
|
|
00061 <span class="keywordtype">void</span> LanguageTable::add_function(functor_t f) {
|
|
00062
|
|
00063 <span class="keywordflow">if</span> (f.arity > 0) {
|
|
00064 pimpl->functions.push_back(f);
|
|
00065
|
|
00066 } <span class="keywordflow">else</span> {
|
|
00067 pimpl->vars.push_back(Sym(f.token));
|
|
00068 }
|
|
00069
|
|
00070 <span class="keywordflow">if</span> (pimpl->functions_per_arity.size() <= f.arity) pimpl->functions_per_arity.resize(f.arity+1);
|
|
00071 pimpl->functions_per_arity[f.arity].push_back(f.token);
|
|
00072
|
|
00073 }
|
|
00074
|
|
00075 <span class="keywordtype">void</span> LanguageTable::set_erc( erc_func func) { pimpl->erc = func; }
|
|
00076
|
|
00077 <span class="comment">/* Getting info out */</span>
|
|
00078
|
|
00079 <span class="keyword">extern</span> Sym SymConst(<span class="keywordtype">double</span> val);
|
|
00080
|
|
00081 Sym LanguageTable::get_random_var()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> rng.<a class="code" href="classeo_rng.html#a14">choice</a>(pimpl->vars); }
|
|
00082 Sym LanguageTable::get_random_const()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> pimpl->erc(); }
|
|
00083
|
|
00084 functor_t LanguageTable::get_random_function()<span class="keyword"> const </span>
|
|
00085 <span class="keyword"></span>{
|
|
00086 <span class="keywordflow">return</span> rng.<a class="code" href="classeo_rng.html#a14">choice</a>(pimpl->functions);
|
|
00087 }
|
|
00088
|
|
00089 token_t LanguageTable::get_random_function(token_t token, <span class="keywordtype">unsigned</span> arity)<span class="keyword"> const </span>
|
|
00090 <span class="keyword"></span>{
|
|
00091 <span class="keywordflow">if</span> (pimpl->functions_per_arity.size() <= arity || pimpl->functions_per_arity[arity].empty()) {
|
|
00092 <span class="keywordflow">return</span> token; <span class="comment">// return original token if no functions of this arity are found</span>
|
|
00093 }
|
|
00094 <span class="keywordflow">return</span> rng.<a class="code" href="classeo_rng.html#a14">choice</a>(pimpl->functions_per_arity[arity]);
|
|
00095 }
|
|
00096
|
|
00097
|
|
00098
|
|
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Oct 19 05:06:40 2006 for EO by
|
|
<a href="http://www.doxygen.org/index.html">
|
|
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.3.9.1 </small></address>
|
|
</body>
|
|
</html>
|