<!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"/> <title>C++ API frePPLe: library.cpp Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> <link href="../styles.css" rel="stylesheet" type="text/css"> </head> <body> <div id="container"> <div id="menubar"> <div id="logo" align="center"> <br/><img src='../frepple.bmp' alt="frepple" /><br/> <a href='http://www.frepple.com/'> <strong>a Free<br/>Production Planning<br/>Library</strong> </a> </div> <div id="menu"> <br/> <h3><a href='../Main/HomePage.html'>Main</a></h3> <h3><a href='../UI/Main.html'>User Manual</a></h3> <h3><a href='../Tutorial/Main.html'>Tutorial</a></h3> <h3><a href='../Frepple/Main.html'>Reference Manual</a></h3> <h3><a href='../Main/FAQ.html'>FAQ</a></h3> <h3><a href='index.html'>C++ API</a></h3> <br/> </div> </div> <div id="content"> <br/> <!-- Generated by Doxygen 1.6.1 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <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="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> <li><a href="dirs.html"><span>Directories</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="dir_88117dff2735251a69c8eb9084477714.html">src</a> » <a class="el" href="dir_dc63a72a31e1c272514e3670d5c54e12.html">utils</a> </div> </div> <div class="contents"> <h1>utils/library.cpp</h1><a href="a00211.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/***************************************************************************</span> <a name="l00002"></a>00002 <span class="comment"> file : $URL: https://frepple.svn.sourceforge.net/svnroot/frepple/trunk/src/utils/library.cpp $</span> <a name="l00003"></a>00003 <span class="comment"> version : $LastChangedRevision: 1315 $ $LastChangedBy: jdetaeye $</span> <a name="l00004"></a>00004 <span class="comment"> date : $LastChangedDate: 2010-07-17 18:08:53 +0200 (Sat, 17 Jul 2010) $</span> <a name="l00005"></a>00005 <span class="comment"> ***************************************************************************/</span> <a name="l00006"></a>00006 <a name="l00007"></a>00007 <span class="comment">/***************************************************************************</span> <a name="l00008"></a>00008 <span class="comment"> * *</span> <a name="l00009"></a>00009 <span class="comment"> * Copyright (C) 2007-2010 by Johan De Taeye *</span> <a name="l00010"></a>00010 <span class="comment"> * *</span> <a name="l00011"></a>00011 <span class="comment"> * This library is free software; you can redistribute it and/or modify it *</span> <a name="l00012"></a>00012 <span class="comment"> * under the terms of the GNU Lesser General Public License as published *</span> <a name="l00013"></a>00013 <span class="comment"> * by the Free Software Foundation; either version 2.1 of the License, or *</span> <a name="l00014"></a>00014 <span class="comment"> * (at your option) any later version. *</span> <a name="l00015"></a>00015 <span class="comment"> * *</span> <a name="l00016"></a>00016 <span class="comment"> * This library is distributed in the hope that it will be useful, *</span> <a name="l00017"></a>00017 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of *</span> <a name="l00018"></a>00018 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *</span> <a name="l00019"></a>00019 <span class="comment"> * General Public License for more details. *</span> <a name="l00020"></a>00020 <span class="comment"> * *</span> <a name="l00021"></a>00021 <span class="comment"> * You should have received a copy of the GNU Lesser General Public *</span> <a name="l00022"></a>00022 <span class="comment"> * License along with this library; if not, write to the Free Software *</span> <a name="l00023"></a>00023 <span class="comment"> * Foundation Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 *</span> <a name="l00024"></a>00024 <span class="comment"> * USA *</span> <a name="l00025"></a>00025 <span class="comment"> * *</span> <a name="l00026"></a>00026 <span class="comment"> ***************************************************************************/</span> <a name="l00027"></a>00027 <a name="l00028"></a><a class="code" href="a00211.html#a342983a479ae7a921be5face83fdb029">00028</a> <span class="preprocessor">#define FREPPLE_CORE</span> <a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="a00252.html" title="Header file for auxilary classes.">frepple/utils.h</a>"</span> <a name="l00030"></a>00030 <span class="preprocessor">#include <sys/stat.h></span> <a name="l00031"></a>00031 <a name="l00032"></a>00032 <a name="l00033"></a>00033 <span class="keyword">namespace </span>frepple <a name="l00034"></a>00034 { <a name="l00035"></a>00035 <span class="keyword">namespace </span>utils <a name="l00036"></a>00036 { <a name="l00037"></a>00037 <a name="l00038"></a>00038 <span class="comment">// Repository of all categories and commands</span> <a name="l00039"></a>00039 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keyword">const</span> MetaCategory* MetaCategory::firstCategory = NULL; <a name="l00040"></a>00040 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <a class="code" href="a00114.html#aa7163794297440d3b6ef53b53f03084e">MetaCategory::CategoryMap</a> MetaCategory::categoriesByTag; <a name="l00041"></a>00041 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <a class="code" href="a00114.html#aa7163794297440d3b6ef53b53f03084e">MetaCategory::CategoryMap</a> MetaCategory::categoriesByGroupTag; <a name="l00042"></a>00042 <a name="l00043"></a>00043 <span class="comment">// Repository of loaded modules</span> <a name="l00044"></a>00044 set<string> CommandLoadLibrary::registry; <a name="l00045"></a>00045 <a name="l00046"></a>00046 <span class="comment">// Processing instruction metadata</span> <a name="l00047"></a>00047 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keyword">const</span> MetaCategory* <a class="code" href="a00025.html#a39d06c836b879942086e03fd32f94bb6">Command::metadataInstruction</a>; <a name="l00048"></a>00048 <a name="l00049"></a>00049 <span class="comment">// Number of processors.</span> <a name="l00050"></a>00050 <span class="comment">// The value initialized here is overwritten in the library initialization.</span> <a name="l00051"></a>00051 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">int</span> Environment::processors = 1; <a name="l00052"></a>00052 <a name="l00053"></a>00053 <span class="comment">// Output logging stream, whose input buffer is shared with either</span> <a name="l00054"></a>00054 <span class="comment">// Environment::logfile or cout.</span> <a name="l00055"></a>00055 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> ostream <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a>(cout.rdbuf()); <a name="l00056"></a>00056 <a name="l00057"></a>00057 <span class="comment">// Output file stream</span> <a name="l00058"></a>00058 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> ofstream Environment::logfile; <a name="l00059"></a>00059 <a name="l00060"></a>00060 <span class="comment">// Name of the log file</span> <a name="l00061"></a>00061 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">string</span> Environment::logfilename; <a name="l00062"></a>00062 <a name="l00063"></a>00063 <span class="comment">// Hash value computed only once</span> <a name="l00064"></a>00064 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keyword">const</span> <a class="code" href="a00257.html#af8a429831281b355afd656cb83d31443">hashtype</a> MetaCategory::defaultHash(<a class="code" href="a00096.html#a9df960daad4f157b92cc4974694093da">Keyword::hash</a>(<span class="stringliteral">"default"</span>)); <a name="l00065"></a>00065 <a name="l00066"></a>00066 vector<PythonType*> <a class="code" href="a00151.html#a67eb776e52371040a3b5eb76683a4760">PythonExtensionBase::table</a>; <a name="l00067"></a>00067 <a name="l00068"></a>00068 <a name="l00069"></a><a class="code" href="a00057.html#a1a07e3b3c5fd07dd2efbe7d546e3bd0e">00069</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">string</span> <a class="code" href="a00057.html#a1a07e3b3c5fd07dd2efbe7d546e3bd0e">Environment::searchFile</a>(<span class="keyword">const</span> <span class="keywordtype">string</span> filename) <a name="l00070"></a>00070 { <a name="l00071"></a>00071 <span class="preprocessor">#ifdef _MSC_VER</span> <a name="l00072"></a>00072 <span class="preprocessor"></span> <span class="keyword">static</span> <span class="keywordtype">char</span> pathseperator = <span class="charliteral">'\\'</span>; <a name="l00073"></a>00073 <span class="preprocessor">#else</span> <a name="l00074"></a>00074 <span class="preprocessor"></span> <span class="keyword">static</span> <span class="keywordtype">char</span> pathseperator = <span class="charliteral">'/'</span>; <a name="l00075"></a>00075 <span class="preprocessor">#endif</span> <a name="l00076"></a>00076 <span class="preprocessor"></span> <a name="l00077"></a>00077 <span class="comment">// First: check the current directory</span> <a name="l00078"></a>00078 <span class="keyword">struct </span>stat stat_p; <a name="l00079"></a>00079 <span class="keywordtype">int</span> result = stat(filename.c_str(), &stat_p); <a name="l00080"></a>00080 <span class="keywordflow">if</span> (!result && stat_p.st_mode & S_IREAD) <a name="l00081"></a>00081 <span class="keywordflow">return</span> filename; <a name="l00082"></a>00082 <a name="l00083"></a>00083 <span class="comment">// Second: check the FREPPLE_HOME directory, if it is defined</span> <a name="l00084"></a>00084 <span class="keywordtype">string</span> fullname; <a name="l00085"></a>00085 <span class="keywordtype">char</span> * envvar = getenv(<span class="stringliteral">"FREPPLE_HOME"</span>); <a name="l00086"></a>00086 <span class="keywordflow">if</span> (envvar) <a name="l00087"></a>00087 { <a name="l00088"></a>00088 fullname = envvar; <a name="l00089"></a>00089 <span class="keywordflow">if</span> (*fullname.rbegin() != pathseperator) <a name="l00090"></a>00090 fullname += pathseperator; <a name="l00091"></a>00091 fullname += filename; <a name="l00092"></a>00092 result = stat(fullname.c_str(), &stat_p); <a name="l00093"></a>00093 <span class="keywordflow">if</span> (!result && stat_p.st_mode & S_IREAD) <a name="l00094"></a>00094 <span class="keywordflow">return</span> fullname; <a name="l00095"></a>00095 } <a name="l00096"></a>00096 <a name="l00097"></a>00097 <span class="preprocessor">#ifdef DATADIRECTORY</span> <a name="l00098"></a>00098 <span class="preprocessor"></span> <span class="comment">// Third: check the data directory</span> <a name="l00099"></a>00099 fullname = DATADIRECTORY; <a name="l00100"></a>00100 <span class="keywordflow">if</span> (*fullname.rbegin() != pathseperator) <a name="l00101"></a>00101 fullname += pathseperator; <a name="l00102"></a>00102 fullname.append(filename); <a name="l00103"></a>00103 result = stat(fullname.c_str(), &stat_p); <a name="l00104"></a>00104 <span class="keywordflow">if</span> (!result && stat_p.st_mode & S_IREAD) <a name="l00105"></a>00105 <span class="keywordflow">return</span> fullname; <a name="l00106"></a>00106 <span class="preprocessor">#endif</span> <a name="l00107"></a>00107 <span class="preprocessor"></span> <a name="l00108"></a>00108 <span class="preprocessor">#ifdef LIBDIRECTORY</span> <a name="l00109"></a>00109 <span class="preprocessor"></span> <span class="comment">// Fourth: check the lib directory</span> <a name="l00110"></a>00110 fullname = LIBDIRECTORY; <a name="l00111"></a>00111 <span class="keywordflow">if</span> (*fullname.rbegin() != pathseperator) <a name="l00112"></a>00112 fullname += pathseperator; <a name="l00113"></a>00113 fullname += <span class="stringliteral">"frepple/"</span>; <a name="l00114"></a>00114 fullname += filename; <a name="l00115"></a>00115 result = stat(fullname.c_str(), &stat_p); <a name="l00116"></a>00116 <span class="keywordflow">if</span> (!result && stat_p.st_mode & S_IREAD) <a name="l00117"></a>00117 <span class="keywordflow">return</span> fullname; <a name="l00118"></a>00118 <span class="preprocessor">#endif</span> <a name="l00119"></a>00119 <span class="preprocessor"></span> <a name="l00120"></a>00120 <span class="comment">// Not found</span> <a name="l00121"></a>00121 <span class="keywordflow">return</span> <span class="stringliteral">""</span>; <a name="l00122"></a>00122 } <a name="l00123"></a>00123 <a name="l00124"></a>00124 <a name="l00125"></a><a class="code" href="a00057.html#a10599f07763dca5b794b47d7f64f03f1">00125</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00057.html#a10599f07763dca5b794b47d7f64f03f1">Environment::setLogFile</a>(<span class="keyword">const</span> <span class="keywordtype">string</span>& x) <a name="l00126"></a>00126 { <a name="l00127"></a>00127 <span class="comment">// Bye bye message</span> <a name="l00128"></a>00128 <span class="keywordflow">if</span> (!logfilename.empty()) <a name="l00129"></a>00129 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">"Stop logging at "</span> << <a class="code" href="a00049.html#ad203bd74ddc1e3b7b961f77fa60388f6">Date::now</a>() << endl; <a name="l00130"></a>00130 <a name="l00131"></a>00131 <span class="comment">// Close an eventual existing log file.</span> <a name="l00132"></a>00132 <span class="keywordflow">if</span> (logfile.is_open()) logfile.close(); <a name="l00133"></a>00133 <a name="l00134"></a>00134 <span class="comment">// No new logfile specified: redirect to the standard output stream</span> <a name="l00135"></a>00135 <span class="keywordflow">if</span> (x.empty() || x == <span class="stringliteral">"+"</span>) <a name="l00136"></a>00136 { <a name="l00137"></a>00137 logfilename = x; <a name="l00138"></a>00138 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a>.rdbuf(cout.rdbuf()); <a name="l00139"></a>00139 <span class="keywordflow">return</span>; <a name="l00140"></a>00140 } <a name="l00141"></a>00141 <a name="l00142"></a>00142 <span class="comment">// Open the file: either as a new file, either appending to existing file</span> <a name="l00143"></a>00143 <span class="keywordflow">if</span> (x[0] != <span class="charliteral">'+'</span>) logfile.open(x.c_str(), ios::out); <a name="l00144"></a>00144 <span class="keywordflow">else</span> logfile.open(x.c_str()+1, ios::app); <a name="l00145"></a>00145 <span class="keywordflow">if</span> (!logfile.good()) <a name="l00146"></a>00146 { <a name="l00147"></a>00147 <span class="comment">// Redirect to the previous logfile (or cout if that's not possible)</span> <a name="l00148"></a>00148 <span class="keywordflow">if</span> (logfile.is_open()) logfile.close(); <a name="l00149"></a>00149 logfile.open(logfilename.c_str(), ios::app); <a name="l00150"></a>00150 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a>.rdbuf(logfile.is_open() ? logfile.rdbuf() : cout.rdbuf()); <a name="l00151"></a>00151 <span class="comment">// The log file could not be opened</span> <a name="l00152"></a>00152 <span class="keywordflow">throw</span> <a class="code" href="a00162.html" title="An exception of this type is thrown when the library runs into problems that are...">RuntimeException</a>(<span class="stringliteral">"Could not open log file '"</span> + x + <span class="stringliteral">"'"</span>); <a name="l00153"></a>00153 } <a name="l00154"></a>00154 <a name="l00155"></a>00155 <span class="comment">// Store the file name</span> <a name="l00156"></a>00156 logfilename = x; <a name="l00157"></a>00157 <a name="l00158"></a>00158 <span class="comment">// Redirect the log file.</span> <a name="l00159"></a>00159 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a>.rdbuf(logfile.rdbuf()); <a name="l00160"></a>00160 <a name="l00161"></a>00161 <span class="comment">// Print a nice header</span> <a name="l00162"></a>00162 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">"Start logging frePPLe "</span> << <a class="code" href="a00252.html#aa326a05d5e30f9e9a4bb0b4469d5d0c0">PACKAGE_VERSION</a> << <span class="stringliteral">" ("</span> <a name="l00163"></a>00163 << __DATE__ << <span class="stringliteral">") at "</span> << <a class="code" href="a00049.html#ad203bd74ddc1e3b7b961f77fa60388f6">Date::now</a>() << endl; <a name="l00164"></a>00164 } <a name="l00165"></a>00165 <a name="l00166"></a>00166 <a name="l00167"></a><a class="code" href="a00099.html#ae32b3740511d9217271416c0f34d581b">00167</a> <span class="keywordtype">void</span> <a class="code" href="a00099.html#ae32b3740511d9217271416c0f34d581b">LibraryUtils::initialize</a>() <a name="l00168"></a>00168 { <a name="l00169"></a>00169 <span class="comment">// Initialize only once</span> <a name="l00170"></a>00170 <span class="keyword">static</span> <span class="keywordtype">bool</span> init = <span class="keyword">false</span>; <a name="l00171"></a>00171 <span class="keywordflow">if</span> (init) <a name="l00172"></a>00172 { <a name="l00173"></a>00173 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">"Warning: Calling frepple::LibraryUtils::initialize() more "</span> <a name="l00174"></a>00174 << <span class="stringliteral">"than once."</span> << endl; <a name="l00175"></a>00175 <span class="keywordflow">return</span>; <a name="l00176"></a>00176 } <a name="l00177"></a>00177 init = <span class="keyword">true</span>; <a name="l00178"></a>00178 <a name="l00179"></a>00179 <span class="comment">// Set the locale to the default setting.</span> <a name="l00180"></a>00180 <span class="comment">// When not executed, the locale is the "C-locale", which restricts us to</span> <a name="l00181"></a>00181 <span class="comment">// ascii data in the input.</span> <a name="l00182"></a>00182 <span class="comment">// For Posix platforms the environment variable LC_ALL controls the locale.</span> <a name="l00183"></a>00183 <span class="comment">// Most Linux distributions these days have a default locale that supports</span> <a name="l00184"></a>00184 <span class="comment">// UTF-8 encoding, meaning that every unicode character can be</span> <a name="l00185"></a>00185 <span class="comment">// represented.</span> <a name="l00186"></a>00186 <span class="comment">// On Windows, the default is the system-default ANSI code page. The number</span> <a name="l00187"></a>00187 <span class="comment">// of characters that frePPLe supports on Windows is constrained by this...</span> <a name="l00188"></a>00188 <span class="preprocessor"> #if defined(HAVE_SETLOCALE) || defined(_MSC_VER)</span> <a name="l00189"></a>00189 <span class="preprocessor"></span> setlocale(LC_ALL, <span class="stringliteral">""</span> ); <a name="l00190"></a>00190 <span class="preprocessor"> #endif</span> <a name="l00191"></a>00191 <span class="preprocessor"></span> <a name="l00192"></a>00192 <span class="comment">// Initialize Xerces parser</span> <a name="l00193"></a>00193 xercesc::XMLPlatformUtils::Initialize(); <a name="l00194"></a>00194 <a name="l00195"></a>00195 <span class="comment">// Initialize the processing instruction metadata.</span> <a name="l00196"></a>00196 <a class="code" href="a00025.html#a39d06c836b879942086e03fd32f94bb6">Command::metadataInstruction</a> = <span class="keyword">new</span> <a class="code" href="a00114.html" title="A MetaCategory instance represents metadata for a category of object.">MetaCategory</a> <a name="l00197"></a>00197 (<span class="stringliteral">"instruction"</span>, <span class="stringliteral">""</span>); <a name="l00198"></a>00198 <a name="l00199"></a>00199 <span class="comment">// Register Python as a processing instruction.</span> <a name="l00200"></a>00200 <a class="code" href="a00033.html#a679228b0372db2965ec58e1c34760ab7">CommandPython::metadata2</a> = <span class="keyword">new</span> <a class="code" href="a00115.html" title="This class stores metadata about the classes in the library. The stored information...">MetaClass</a>( <a name="l00201"></a>00201 <span class="stringliteral">"instruction"</span>, <span class="stringliteral">"python"</span>, <a class="code" href="a00033.html#af71bbd41fa2d420e572cfe963ac17ba6">CommandPython::processorXMLInstruction</a>); <a name="l00202"></a>00202 <a name="l00203"></a>00203 <span class="comment">// Initialize the Python interpreter</span> <a name="l00204"></a>00204 <a class="code" href="a00099.html#ae32b3740511d9217271416c0f34d581b">PythonInterpreter::initialize</a>(); <a name="l00205"></a>00205 <a name="l00206"></a>00206 <span class="comment">// Query the system for the number of available processors.</span> <a name="l00207"></a>00207 <span class="comment">// The environment variable NUMBER_OF_PROCESSORS is defined automatically on</span> <a name="l00208"></a>00208 <span class="comment">// Windows platforms. On other platforms it'll have to be explicitly set</span> <a name="l00209"></a>00209 <span class="comment">// since there isn't an easy and portable way of querying this system</span> <a name="l00210"></a>00210 <span class="comment">// information.</span> <a name="l00211"></a>00211 <span class="keyword">const</span> <span class="keywordtype">char</span> *c = getenv(<span class="stringliteral">"NUMBER_OF_PROCESSORS"</span>); <a name="l00212"></a>00212 <span class="keywordflow">if</span> (c) <a name="l00213"></a>00213 { <a name="l00214"></a>00214 <span class="keywordtype">int</span> p = atoi(c); <a name="l00215"></a>00215 <a class="code" href="a00057.html#a2e77491e9f8ce70fbf055217655460af">Environment::setProcessors</a>(p); <a name="l00216"></a>00216 } <a name="l00217"></a>00217 } <a name="l00218"></a>00218 <a name="l00219"></a>00219 <a name="l00220"></a><a class="code" href="a00115.html#a6f3ffe2fd965f271fcf683e1b767ef35">00220</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00115.html#a6f3ffe2fd965f271fcf683e1b767ef35">MetaClass::registerClass</a> (<span class="keyword">const</span> <span class="keywordtype">string</span>& a, <span class="keyword">const</span> <span class="keywordtype">string</span>& b, <a name="l00221"></a>00221 <span class="keywordtype">bool</span> def, creatorDefault f) <a name="l00222"></a>00222 { <a name="l00223"></a>00223 <span class="comment">// Find or create the category</span> <a name="l00224"></a>00224 <a class="code" href="a00114.html" title="A MetaCategory instance represents metadata for a category of object.">MetaCategory</a>* cat <a name="l00225"></a>00225 = <span class="keyword">const_cast<</span><a class="code" href="a00114.html" title="A MetaCategory instance represents metadata for a category of object.">MetaCategory</a>*<span class="keyword">></span>(<a class="code" href="a00114.html#ae560068cd28964a67324d31b38863816">MetaCategory::findCategoryByTag</a>(a.c_str())); <a name="l00226"></a>00226 <a name="l00227"></a>00227 <span class="comment">// Check for a valid category</span> <a name="l00228"></a>00228 <span class="keywordflow">if</span> (!cat) <a name="l00229"></a>00229 <span class="keywordflow">throw</span> <a class="code" href="a00111.html" title="An exception of this type is thrown when the library gets in an inconsistent state...">LogicException</a>(<span class="stringliteral">"Category "</span> + a <a name="l00230"></a>00230 + <span class="stringliteral">" not found when registering class "</span> + b); <a name="l00231"></a>00231 <a name="l00232"></a>00232 <span class="comment">// Update fields</span> <a name="l00233"></a>00233 <a class="code" href="a00115.html#a1c94d25992dd871a1eee6825ab84d28a">type</a> = b.empty() ? <span class="stringliteral">"unspecified"</span> : b; <a name="l00234"></a>00234 <a class="code" href="a00115.html#aace20f59ef5a9de3188cb9810398932b">typetag</a> = &<a class="code" href="a00096.html#aeccf1356d895ed0bf0e02f42763c72ea">Keyword::find</a>(<a class="code" href="a00115.html#a1c94d25992dd871a1eee6825ab84d28a">type</a>.c_str()); <a name="l00235"></a>00235 <a class="code" href="a00115.html#a0183becf741251599d5d277a030a33c2">category</a> = cat; <a name="l00236"></a>00236 <a name="l00237"></a>00237 <span class="comment">// Update the metadata table</span> <a name="l00238"></a>00238 cat->classes[<a class="code" href="a00096.html#a9df960daad4f157b92cc4974694093da">Keyword::hash</a>(b)] = <span class="keyword">this</span>; <a name="l00239"></a>00239 <a name="l00240"></a>00240 <span class="comment">// Register this tag also as the default one, if requested</span> <a name="l00241"></a>00241 <span class="keywordflow">if</span> (def) cat->classes[<a class="code" href="a00096.html#a9df960daad4f157b92cc4974694093da">Keyword::hash</a>(<span class="stringliteral">"default"</span>)] = <span class="keyword">this</span>; <a name="l00242"></a>00242 <a name="l00243"></a>00243 <span class="comment">// Set method pointers to NULL</span> <a name="l00244"></a>00244 <a class="code" href="a00115.html#a89b6aced03f5425e5fbb85f4a15f9aad">factoryMethodDefault</a> = f; <a name="l00245"></a>00245 } <a name="l00246"></a>00246 <a name="l00247"></a>00247 <a name="l00248"></a><a class="code" href="a00114.html#a129cc0601853bb65f5850e54784a6df3">00248</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <a class="code" href="a00114.html#a129cc0601853bb65f5850e54784a6df3">MetaCategory::MetaCategory</a> (<span class="keyword">const</span> <span class="keywordtype">string</span>& a, <span class="keyword">const</span> <span class="keywordtype">string</span>& gr, <a name="l00249"></a>00249 readController f, writeController w) <a name="l00250"></a>00250 { <a name="l00251"></a>00251 <span class="comment">// Update registry</span> <a name="l00252"></a>00252 <span class="keywordflow">if</span> (!a.empty()) categoriesByTag[<a class="code" href="a00096.html#a9df960daad4f157b92cc4974694093da">Keyword::hash</a>(a)] = <span class="keyword">this</span>; <a name="l00253"></a>00253 <span class="keywordflow">if</span> (!gr.empty()) categoriesByGroupTag[<a class="code" href="a00096.html#a9df960daad4f157b92cc4974694093da">Keyword::hash</a>(gr)] = <span class="keyword">this</span>; <a name="l00254"></a>00254 <a name="l00255"></a>00255 <span class="comment">// Update fields</span> <a name="l00256"></a>00256 <a class="code" href="a00114.html#a12334a610fa3ae152311a623ea11ce1d">readFunction</a> = f; <a name="l00257"></a>00257 writeFunction = w; <a name="l00258"></a>00258 <a class="code" href="a00115.html#a1c94d25992dd871a1eee6825ab84d28a">type</a> = a.empty() ? <span class="stringliteral">"unspecified"</span> : a; <a name="l00259"></a>00259 <a class="code" href="a00115.html#aace20f59ef5a9de3188cb9810398932b">typetag</a> = &<a class="code" href="a00096.html#aeccf1356d895ed0bf0e02f42763c72ea">Keyword::find</a>(<a class="code" href="a00115.html#a1c94d25992dd871a1eee6825ab84d28a">type</a>.c_str()); <a name="l00260"></a>00260 <a class="code" href="a00114.html#ab4095aa6c4dd8dc0049f4013a5950b3e">group</a> = gr.empty() ? <span class="stringliteral">"unspecified"</span> : gr; <a name="l00261"></a>00261 <a class="code" href="a00114.html#abf52fd75f82c4de4091e3b1921b43ba5">grouptag</a> = &<a class="code" href="a00096.html#aeccf1356d895ed0bf0e02f42763c72ea">Keyword::find</a>(group.c_str()); <a name="l00262"></a>00262 <a name="l00263"></a>00263 <span class="comment">// Maintain a linked list of all registered categories</span> <a name="l00264"></a>00264 nextCategory = NULL; <a name="l00265"></a>00265 <span class="keywordflow">if</span> (!firstCategory) <a name="l00266"></a>00266 firstCategory = <span class="keyword">this</span>; <a name="l00267"></a>00267 <span class="keywordflow">else</span> <a name="l00268"></a>00268 { <a name="l00269"></a>00269 <span class="keyword">const</span> <a class="code" href="a00114.html" title="A MetaCategory instance represents metadata for a category of object.">MetaCategory</a> *i = firstCategory; <a name="l00270"></a>00270 <span class="keywordflow">while</span> (i->nextCategory) i = i->nextCategory; <a name="l00271"></a>00271 <span class="keyword">const_cast<</span><a class="code" href="a00114.html" title="A MetaCategory instance represents metadata for a category of object.">MetaCategory</a>*<span class="keyword">></span>(i)->nextCategory = <span class="keyword">this</span>; <a name="l00272"></a>00272 } <a name="l00273"></a>00273 } <a name="l00274"></a>00274 <a name="l00275"></a>00275 <a name="l00276"></a><a class="code" href="a00114.html#ae560068cd28964a67324d31b38863816">00276</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keyword">const</span> <a class="code" href="a00114.html" title="A MetaCategory instance represents metadata for a category of object.">MetaCategory</a>* <a class="code" href="a00114.html#ae560068cd28964a67324d31b38863816">MetaCategory::findCategoryByTag</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* c) <a name="l00277"></a>00277 { <a name="l00278"></a>00278 <span class="comment">// Loop through all categories</span> <a name="l00279"></a>00279 CategoryMap::const_iterator i = categoriesByTag.find(<a class="code" href="a00096.html#a9df960daad4f157b92cc4974694093da">Keyword::hash</a>(c)); <a name="l00280"></a>00280 <span class="keywordflow">return</span> (i!=categoriesByTag.end()) ? i->second : NULL; <a name="l00281"></a>00281 } <a name="l00282"></a>00282 <a name="l00283"></a>00283 <a name="l00284"></a><a class="code" href="a00114.html#a64fdf78b23c9da0c72937d1ee173f10e">00284</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keyword">const</span> <a class="code" href="a00114.html" title="A MetaCategory instance represents metadata for a category of object.">MetaCategory</a>* <a class="code" href="a00114.html#ae560068cd28964a67324d31b38863816">MetaCategory::findCategoryByTag</a>(<span class="keyword">const</span> <a class="code" href="a00257.html#af8a429831281b355afd656cb83d31443">hashtype</a> h) <a name="l00285"></a>00285 { <a name="l00286"></a>00286 <span class="comment">// Loop through all categories</span> <a name="l00287"></a>00287 CategoryMap::const_iterator i = categoriesByTag.find(h); <a name="l00288"></a>00288 <span class="keywordflow">return</span> (i!=categoriesByTag.end()) ? i->second : NULL; <a name="l00289"></a>00289 } <a name="l00290"></a>00290 <a name="l00291"></a>00291 <a name="l00292"></a><a class="code" href="a00114.html#a8221e194d1809fcc1868a5b1bf2d319b">00292</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keyword">const</span> <a class="code" href="a00114.html" title="A MetaCategory instance represents metadata for a category of object.">MetaCategory</a>* <a class="code" href="a00114.html#a8221e194d1809fcc1868a5b1bf2d319b">MetaCategory::findCategoryByGroupTag</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* c) <a name="l00293"></a>00293 { <a name="l00294"></a>00294 <span class="comment">// Loop through all categories</span> <a name="l00295"></a>00295 CategoryMap::const_iterator i = categoriesByGroupTag.find(<a class="code" href="a00096.html#a9df960daad4f157b92cc4974694093da">Keyword::hash</a>(c)); <a name="l00296"></a>00296 <span class="keywordflow">return</span> (i!=categoriesByGroupTag.end()) ? i->second : NULL; <a name="l00297"></a>00297 } <a name="l00298"></a>00298 <a name="l00299"></a>00299 <a name="l00300"></a><a class="code" href="a00114.html#a35e0d66624ab7351a0b08a6823883653">00300</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keyword">const</span> <a class="code" href="a00114.html" title="A MetaCategory instance represents metadata for a category of object.">MetaCategory</a>* <a class="code" href="a00114.html#a8221e194d1809fcc1868a5b1bf2d319b">MetaCategory::findCategoryByGroupTag</a>(<span class="keyword">const</span> <a class="code" href="a00257.html#af8a429831281b355afd656cb83d31443">hashtype</a> h) <a name="l00301"></a>00301 { <a name="l00302"></a>00302 <span class="comment">// Loop through all categories</span> <a name="l00303"></a>00303 CategoryMap::const_iterator i = categoriesByGroupTag.find(h); <a name="l00304"></a>00304 <span class="keywordflow">return</span> (i!=categoriesByGroupTag.end()) ? i->second : NULL; <a name="l00305"></a>00305 } <a name="l00306"></a>00306 <a name="l00307"></a>00307 <a name="l00308"></a><a class="code" href="a00114.html#a3472af066bddae41ca38a0b48ac0fd24">00308</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keyword">const</span> <a class="code" href="a00115.html" title="This class stores metadata about the classes in the library. The stored information...">MetaClass</a>* <a class="code" href="a00114.html#a3472af066bddae41ca38a0b48ac0fd24">MetaCategory::findClass</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* c)<span class="keyword"> const</span> <a name="l00309"></a>00309 <span class="keyword"></span>{ <a name="l00310"></a>00310 <span class="comment">// Look up in the registered classes</span> <a name="l00311"></a>00311 MetaCategory::ClassMap::const_iterator j = classes.find(<a class="code" href="a00096.html#a9df960daad4f157b92cc4974694093da">Keyword::hash</a>(c)); <a name="l00312"></a>00312 <span class="keywordflow">return</span> (j == classes.end()) ? NULL : j->second; <a name="l00313"></a>00313 } <a name="l00314"></a>00314 <a name="l00315"></a>00315 <a name="l00316"></a><a class="code" href="a00114.html#ae136db23de357da3cc00db3a64451cd9">00316</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keyword">const</span> <a class="code" href="a00115.html" title="This class stores metadata about the classes in the library. The stored information...">MetaClass</a>* <a class="code" href="a00114.html#a3472af066bddae41ca38a0b48ac0fd24">MetaCategory::findClass</a>(<span class="keyword">const</span> <a class="code" href="a00257.html#af8a429831281b355afd656cb83d31443">hashtype</a> h)<span class="keyword"> const</span> <a name="l00317"></a>00317 <span class="keyword"></span>{ <a name="l00318"></a>00318 <span class="comment">// Look up in the registered classes</span> <a name="l00319"></a>00319 MetaCategory::ClassMap::const_iterator j = classes.find(h); <a name="l00320"></a>00320 <span class="keywordflow">return</span> (j == classes.end()) ? NULL : j->second; <a name="l00321"></a>00321 } <a name="l00322"></a>00322 <a name="l00323"></a>00323 <a name="l00324"></a><a class="code" href="a00114.html#aa04358522c716d21f11ab487c179b10c">00324</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00114.html#aa04358522c716d21f11ab487c179b10c">MetaCategory::persist</a>(<a class="code" href="a00189.html" title="Base class for writing XML formatted data to an output stream.">XMLOutput</a> *o) <a name="l00325"></a>00325 { <a name="l00326"></a>00326 <span class="keywordflow">for</span> (<span class="keyword">const</span> <a class="code" href="a00114.html" title="A MetaCategory instance represents metadata for a category of object.">MetaCategory</a> *i = firstCategory; i; i = i->nextCategory) <a name="l00327"></a>00327 <span class="keywordflow">if</span> (i->writeFunction) i->writeFunction(i, o); <a name="l00328"></a>00328 } <a name="l00329"></a>00329 <a name="l00330"></a>00330 <a name="l00331"></a><a class="code" href="a00115.html#a9ad93304bf62c6141f2881bdd2bf914d">00331</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keyword">const</span> <a class="code" href="a00115.html" title="This class stores metadata about the classes in the library. The stored information...">MetaClass</a>* <a class="code" href="a00115.html#a9ad93304bf62c6141f2881bdd2bf914d">MetaClass::findClass</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* c) <a name="l00332"></a>00332 { <a name="l00333"></a>00333 <span class="comment">// Loop through all categories</span> <a name="l00334"></a>00334 <span class="keywordflow">for</span> (MetaCategory::CategoryMap::const_iterator i = MetaCategory::categoriesByTag.begin(); <a name="l00335"></a>00335 i != MetaCategory::categoriesByTag.end(); ++i) <a name="l00336"></a>00336 { <a name="l00337"></a>00337 <span class="comment">// Look up in the registered classes</span> <a name="l00338"></a>00338 MetaCategory::ClassMap::const_iterator j <a name="l00339"></a>00339 = i->second->classes.find(<a class="code" href="a00096.html#a9df960daad4f157b92cc4974694093da">Keyword::hash</a>(c)); <a name="l00340"></a>00340 <span class="keywordflow">if</span> (j != i->second->classes.end()) <span class="keywordflow">return</span> j->second; <a name="l00341"></a>00341 } <a name="l00342"></a>00342 <span class="comment">// Not found...</span> <a name="l00343"></a>00343 <span class="keywordflow">return</span> NULL; <a name="l00344"></a>00344 } <a name="l00345"></a>00345 <a name="l00346"></a>00346 <a name="l00347"></a><a class="code" href="a00115.html#a60d345941c4cc3743a23336015897913">00347</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00115.html#a60d345941c4cc3743a23336015897913">MetaClass::printClasses</a>() <a name="l00348"></a>00348 { <a name="l00349"></a>00349 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">"Registered classes:"</span> << endl; <a name="l00350"></a>00350 <span class="comment">// Loop through all categories</span> <a name="l00351"></a>00351 <span class="keywordflow">for</span> (MetaCategory::CategoryMap::const_iterator i = MetaCategory::categoriesByTag.begin(); <a name="l00352"></a>00352 i != MetaCategory::categoriesByTag.end(); ++i) <a name="l00353"></a>00353 { <a name="l00354"></a>00354 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">" "</span> << i->second->type << endl; <a name="l00355"></a>00355 <span class="comment">// Loop through the classes for the category</span> <a name="l00356"></a>00356 <span class="keywordflow">for</span> (MetaCategory::ClassMap::const_iterator <a name="l00357"></a>00357 j = i->second->classes.begin(); <a name="l00358"></a>00358 j != i->second->classes.end(); <a name="l00359"></a>00359 ++j) <a name="l00360"></a>00360 <span class="keywordflow">if</span> (j->first == <a class="code" href="a00096.html#a9df960daad4f157b92cc4974694093da">Keyword::hash</a>(<span class="stringliteral">"default"</span>)) <a name="l00361"></a>00361 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">" default ( = "</span> << j->second->type << <span class="stringliteral">" )"</span> << j->second << endl; <a name="l00362"></a>00362 <span class="keywordflow">else</span> <a name="l00363"></a>00363 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">" "</span> << j->second->type << j->second << endl; <a name="l00364"></a>00364 } <a name="l00365"></a>00365 } <a name="l00366"></a>00366 <a name="l00367"></a>00367 <a name="l00368"></a><a class="code" href="a00115.html#aafea050a7ec4ee812cfc0de5fe30ce19">00368</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <a class="code" href="a00257.html#a07f97ddf3e649a4d2aa13cb900b5dcf4">Action</a> <a class="code" href="a00115.html#aafea050a7ec4ee812cfc0de5fe30ce19">MetaClass::decodeAction</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *x) <a name="l00369"></a>00369 { <a name="l00370"></a>00370 <span class="comment">// Validate the action</span> <a name="l00371"></a>00371 <span class="keywordflow">if</span> (!x) <span class="keywordflow">throw</span> <a class="code" href="a00111.html" title="An exception of this type is thrown when the library gets in an inconsistent state...">LogicException</a>(<span class="stringliteral">"Invalid action NULL"</span>); <a name="l00372"></a>00372 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(x,<span class="stringliteral">"AC"</span>)) <span class="keywordflow">return</span> <a class="code" href="a00257.html#a07f97ddf3e649a4d2aa13cb900b5dcf4a75b4aab762127e8083e16661b4021a00">ADD_CHANGE</a>; <a name="l00373"></a>00373 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(x,<span class="stringliteral">"A"</span>)) <span class="keywordflow">return</span> <a class="code" href="a00257.html#a07f97ddf3e649a4d2aa13cb900b5dcf4a8f6183fcf54ca6985ff2b5ef80673a25">ADD</a>; <a name="l00374"></a>00374 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(x,<span class="stringliteral">"C"</span>)) <span class="keywordflow">return</span> <a class="code" href="a00257.html#a07f97ddf3e649a4d2aa13cb900b5dcf4a1b9888c025bb8f78e322471fd5e14423">CHANGE</a>; <a name="l00375"></a>00375 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!strcmp(x,<span class="stringliteral">"R"</span>)) <span class="keywordflow">return</span> <a class="code" href="a00257.html#a07f97ddf3e649a4d2aa13cb900b5dcf4a6b9fb19e9a6595385dec31b63e0054e1">REMOVE</a>; <a name="l00376"></a>00376 <span class="keywordflow">else</span> <span class="keywordflow">throw</span> <a class="code" href="a00111.html" title="An exception of this type is thrown when the library gets in an inconsistent state...">LogicException</a>(<span class="stringliteral">"Invalid action '"</span> + <span class="keywordtype">string</span>(x) + <span class="stringliteral">"'"</span>); <a name="l00377"></a>00377 } <a name="l00378"></a>00378 <a name="l00379"></a>00379 <a name="l00380"></a><a class="code" href="a00115.html#a5fb6af1238c308ca2c320ff4487744a2">00380</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <a class="code" href="a00257.html#a07f97ddf3e649a4d2aa13cb900b5dcf4">Action</a> <a class="code" href="a00115.html#aafea050a7ec4ee812cfc0de5fe30ce19">MetaClass::decodeAction</a>(<span class="keyword">const</span> <a class="code" href="a00003.html" title="This class represents a dictionary of keyword + value pairs.">AttributeList</a>& atts) <a name="l00381"></a>00381 { <a name="l00382"></a>00382 <span class="comment">// Decode the string and return the default in the absence of the attribute</span> <a name="l00383"></a>00383 <span class="keyword">const</span> <a class="code" href="a00047.html" title="This abstract class represents a attribute and value pair for updating objects in...">DataElement</a>* c = atts.<a class="code" href="a00003.html#afc79347bc21694cedfe218f8d023235f">get</a>(<a class="code" href="a00176.html#a391c4d3fc071199c00a248d992d623dd">Tags::tag_action</a>); <a name="l00384"></a>00384 <span class="keywordflow">return</span> *c ? <a class="code" href="a00115.html#aafea050a7ec4ee812cfc0de5fe30ce19">decodeAction</a>(c-><a class="code" href="a00047.html#a053aa4cde35b21a399f26bca0132ab3f">getString</a>().c_str()) : <a class="code" href="a00257.html#a07f97ddf3e649a4d2aa13cb900b5dcf4a75b4aab762127e8083e16661b4021a00">ADD_CHANGE</a>; <a name="l00385"></a>00385 } <a name="l00386"></a>00386 <a name="l00387"></a>00387 <a name="l00388"></a><a class="code" href="a00115.html#ae3e00d415acf61ed63fe0854ebc55ee3">00388</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">bool</span> <a class="code" href="a00115.html#ae3e00d415acf61ed63fe0854ebc55ee3">MetaClass::raiseEvent</a>(<a class="code" href="a00120.html" title="Object is the abstract base class for the main entities.">Object</a>* v, <a class="code" href="a00257.html#aec6d4a238b0cd9ffc8be8f10fd9b652f">Signal</a> a)<span class="keyword"> const</span> <a name="l00389"></a>00389 <span class="keyword"></span>{ <a name="l00390"></a>00390 <span class="keywordtype">bool</span> result(<span class="keyword">true</span>); <a name="l00391"></a>00391 <span class="keywordflow">for</span> (list<Functor*>::const_iterator i = subscribers[a].begin(); <a name="l00392"></a>00392 i != subscribers[a].end(); ++i) <a name="l00393"></a>00393 <span class="comment">// Note that we always call all subscribers, even if one or more</span> <a name="l00394"></a>00394 <span class="comment">// already replied negatively. However, an exception thrown from a</span> <a name="l00395"></a>00395 <span class="comment">// callback method will break the publishing chain.</span> <a name="l00396"></a>00396 <span class="keywordflow">if</span> (!(*i)->callback(v,a)) result = <span class="keyword">false</span>; <a name="l00397"></a>00397 <a name="l00398"></a>00398 <span class="comment">// Raise the event also on the category, if there is a valid one</span> <a name="l00399"></a>00399 <span class="keywordflow">return</span> (<a class="code" href="a00115.html#a0183becf741251599d5d277a030a33c2">category</a> && <a class="code" href="a00115.html#a0183becf741251599d5d277a030a33c2">category</a>!=<span class="keyword">this</span>) ? <a name="l00400"></a>00400 (result && <a class="code" href="a00115.html#a0183becf741251599d5d277a030a33c2">category</a>-><a class="code" href="a00115.html#ae3e00d415acf61ed63fe0854ebc55ee3">raiseEvent</a>(v,a)) : <a name="l00401"></a>00401 result; <a name="l00402"></a>00402 } <a name="l00403"></a>00403 <a name="l00404"></a>00404 <a name="l00405"></a><a class="code" href="a00114.html#a7842f6be8852a47e3a1d4ececb40c42e">00405</a> <a class="code" href="a00120.html" title="Object is the abstract base class for the main entities.">Object</a>* <a class="code" href="a00114.html#a7842f6be8852a47e3a1d4ececb40c42e">MetaCategory::ControllerDefault</a> (<span class="keyword">const</span> <a class="code" href="a00115.html" title="This class stores metadata about the classes in the library. The stored information...">MetaClass</a>* cat, <span class="keyword">const</span> <a class="code" href="a00003.html" title="This class represents a dictionary of keyword + value pairs.">AttributeList</a>& in) <a name="l00406"></a>00406 { <a name="l00407"></a>00407 <a class="code" href="a00257.html#a07f97ddf3e649a4d2aa13cb900b5dcf4">Action</a> act = <a class="code" href="a00257.html#a07f97ddf3e649a4d2aa13cb900b5dcf4a8f6183fcf54ca6985ff2b5ef80673a25">ADD</a>; <a name="l00408"></a>00408 <span class="keywordflow">switch</span> (act) <a name="l00409"></a>00409 { <a name="l00410"></a>00410 <span class="keywordflow">case</span> <a class="code" href="a00257.html#a07f97ddf3e649a4d2aa13cb900b5dcf4a6b9fb19e9a6595385dec31b63e0054e1">REMOVE</a>: <a name="l00411"></a>00411 <span class="keywordflow">throw</span> <a class="code" href="a00048.html" title="An exception of this type is thrown when data errors are found.">DataException</a> <a name="l00412"></a>00412 (<span class="stringliteral">"Entity "</span> + cat-><a class="code" href="a00115.html#a1c94d25992dd871a1eee6825ab84d28a">type</a> + <span class="stringliteral">" doesn't support REMOVE action"</span>); <a name="l00413"></a>00413 <span class="keywordflow">case</span> <a class="code" href="a00257.html#a07f97ddf3e649a4d2aa13cb900b5dcf4a1b9888c025bb8f78e322471fd5e14423">CHANGE</a>: <a name="l00414"></a>00414 <span class="keywordflow">throw</span> <a class="code" href="a00048.html" title="An exception of this type is thrown when data errors are found.">DataException</a> <a name="l00415"></a>00415 (<span class="stringliteral">"Entity "</span> + cat-><a class="code" href="a00115.html#a1c94d25992dd871a1eee6825ab84d28a">type</a> + <span class="stringliteral">" doesn't support CHANGE action"</span>); <a name="l00416"></a>00416 <span class="keywordflow">default</span>: <a name="l00417"></a>00417 <span class="comment">/* Lookup for the class in the map of registered classes. */</span> <a name="l00418"></a>00418 <span class="keyword">const</span> <a class="code" href="a00115.html" title="This class stores metadata about the classes in the library. The stored information...">MetaClass</a>* j; <a name="l00419"></a>00419 <span class="keywordflow">if</span> (cat-><a class="code" href="a00115.html#a0183becf741251599d5d277a030a33c2">category</a>) <a name="l00420"></a>00420 <span class="comment">// Class metadata passed: we already know what type to create</span> <a name="l00421"></a>00421 j = cat; <a name="l00422"></a>00422 <span class="keywordflow">else</span> <a name="l00423"></a>00423 { <a name="l00424"></a>00424 <span class="comment">// Category metadata passed: we need to look up the type</span> <a name="l00425"></a>00425 <span class="keyword">const</span> <a class="code" href="a00047.html" title="This abstract class represents a attribute and value pair for updating objects in...">DataElement</a>* <a class="code" href="a00115.html#a1c94d25992dd871a1eee6825ab84d28a">type</a> = in.<a class="code" href="a00003.html#afc79347bc21694cedfe218f8d023235f">get</a>(<a class="code" href="a00176.html#a6745112e0237e378e2b0cbe41aa5926a">Tags::tag_type</a>); <a name="l00426"></a>00426 j = <span class="keyword">static_cast<</span><span class="keyword">const </span><a class="code" href="a00114.html" title="A MetaCategory instance represents metadata for a category of object.">MetaCategory</a>&<span class="keyword">></span>(*cat).<a class="code" href="a00115.html#a9ad93304bf62c6141f2881bdd2bf914d">findClass</a>(*type ? <a class="code" href="a00096.html#a9df960daad4f157b92cc4974694093da">Keyword::hash</a>(type-><a class="code" href="a00047.html#a053aa4cde35b21a399f26bca0132ab3f">getString</a>()) : MetaCategory::defaultHash); <a name="l00427"></a>00427 <span class="keywordflow">if</span> (!j) <a name="l00428"></a>00428 { <a name="l00429"></a>00429 <span class="keywordtype">string</span> t(*type ? type-><a class="code" href="a00047.html#a053aa4cde35b21a399f26bca0132ab3f">getString</a>() : <span class="stringliteral">"default"</span>); <a name="l00430"></a>00430 <span class="keywordflow">throw</span> <a class="code" href="a00111.html" title="An exception of this type is thrown when the library gets in an inconsistent state...">LogicException</a>(<span class="stringliteral">"No type "</span> + t + <span class="stringliteral">" registered for category "</span> + cat-><a class="code" href="a00115.html#a1c94d25992dd871a1eee6825ab84d28a">type</a>); <a name="l00431"></a>00431 } <a name="l00432"></a>00432 } <a name="l00433"></a>00433 <a name="l00434"></a>00434 <span class="comment">// Call the factory method</span> <a name="l00435"></a>00435 <a class="code" href="a00120.html" title="Object is the abstract base class for the main entities.">Object</a>* result = j-><a class="code" href="a00115.html#a89b6aced03f5425e5fbb85f4a15f9aad">factoryMethodDefault</a>(); <a name="l00436"></a>00436 <a name="l00437"></a>00437 <span class="comment">// Run the callback methods</span> <a name="l00438"></a>00438 <span class="keywordflow">if</span> (!result-><a class="code" href="a00120.html#a2e5ff5e5d9c32647f692abd04a0d72d2">getType</a>().<a class="code" href="a00115.html#ae3e00d415acf61ed63fe0854ebc55ee3">raiseEvent</a>(result, <a class="code" href="a00257.html#aec6d4a238b0cd9ffc8be8f10fd9b652fa0002e13b1bc824daa2f7eba569780247">SIG_ADD</a>)) <a name="l00439"></a>00439 { <a name="l00440"></a>00440 <span class="comment">// Creation denied</span> <a name="l00441"></a>00441 <span class="keyword">delete</span> result; <a name="l00442"></a>00442 <span class="keywordflow">throw</span> <a class="code" href="a00048.html" title="An exception of this type is thrown when data errors are found.">DataException</a>(<span class="stringliteral">"Can't create object"</span>); <a name="l00443"></a>00443 } <a name="l00444"></a>00444 <a name="l00445"></a>00445 <span class="comment">// Creation accepted</span> <a name="l00446"></a>00446 <span class="keywordflow">return</span> result; <a name="l00447"></a>00447 } <a name="l00448"></a>00448 <span class="keywordflow">throw</span> <a class="code" href="a00111.html" title="An exception of this type is thrown when the library gets in an inconsistent state...">LogicException</a>(<span class="stringliteral">"Unreachable code reached"</span>); <a name="l00449"></a>00449 <span class="keywordflow">return</span> NULL; <a name="l00450"></a>00450 } <a name="l00451"></a>00451 <a name="l00452"></a>00452 <a name="l00453"></a><a class="code" href="a00082.html#aff43518d92c1ac8298ce3df9ad4c9fbb">00453</a> <span class="keywordtype">void</span> <a class="code" href="a00082.html#aff43518d92c1ac8298ce3df9ad4c9fbb">HasDescription::writeElement</a>(<a class="code" href="a00189.html" title="Base class for writing XML formatted data to an output stream.">XMLOutput</a> *o, <span class="keyword">const</span> <a class="code" href="a00096.html" title="This class defines a keyword for the frePPLe data model.">Keyword</a> &t, <a class="code" href="a00257.html#a20c2c7e4c6b668e71c154ae3eb18f398">mode</a> m)<span class="keyword"> const</span> <a name="l00454"></a>00454 <span class="keyword"></span>{ <a name="l00455"></a>00455 <span class="comment">// Note that this function is never called on its own. It is always called</span> <a name="l00456"></a>00456 <span class="comment">// from the writeElement() method of a subclass.</span> <a name="l00457"></a>00457 <span class="comment">// Hence, we don't bother about the mode.</span> <a name="l00458"></a>00458 o-><a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00176.html#a712bcf2d196c0ddae4c4971127d4d43b">Tags::tag_category</a>, cat); <a name="l00459"></a>00459 o-><a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00176.html#ac932faef2edd6d850d233d2c2de7eb68">Tags::tag_subcategory</a>, subcat); <a name="l00460"></a>00460 o-><a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00176.html#a6ae79e34440e259269ed2f902cd47157">Tags::tag_description</a>, descr); <a name="l00461"></a>00461 } <a name="l00462"></a>00462 <a name="l00463"></a>00463 <a name="l00464"></a><a class="code" href="a00082.html#ad6c2b65721b36431bcbb8d6e218fde7c">00464</a> <span class="keywordtype">void</span> <a class="code" href="a00082.html#ad6c2b65721b36431bcbb8d6e218fde7c">HasDescription::endElement</a> (<a class="code" href="a00186.html" title="This class will read in an XML-file and call the appropriate handler functions of...">XMLInput</a>& pIn, <span class="keyword">const</span> <a class="code" href="a00002.html" title="A class to model keyword instances.">Attribute</a>& pAttr, <span class="keyword">const</span> <a class="code" href="a00047.html" title="This abstract class represents a attribute and value pair for updating objects in...">DataElement</a>& pElement) <a name="l00465"></a>00465 { <a name="l00466"></a>00466 <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00176.html#a712bcf2d196c0ddae4c4971127d4d43b">Tags::tag_category</a>)) <a name="l00467"></a>00467 <a class="code" href="a00082.html#a765bec78ade5db873ae5d2c1a56238ab">setCategory</a>(pElement.<a class="code" href="a00047.html#a053aa4cde35b21a399f26bca0132ab3f">getString</a>()); <a name="l00468"></a>00468 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00176.html#ac932faef2edd6d850d233d2c2de7eb68">Tags::tag_subcategory</a>)) <a name="l00469"></a>00469 <a class="code" href="a00082.html#abd65cc21a6a0636f3569e90e89e54e5f">setSubCategory</a>(pElement.<a class="code" href="a00047.html#a053aa4cde35b21a399f26bca0132ab3f">getString</a>()); <a name="l00470"></a>00470 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00176.html#a6ae79e34440e259269ed2f902cd47157">Tags::tag_description</a>)) <a name="l00471"></a>00471 <a class="code" href="a00082.html#a86430aaf17c259450986d8ad73aa2fbf">setDescription</a>(pElement.<a class="code" href="a00047.html#a053aa4cde35b21a399f26bca0132ab3f">getString</a>()); <a name="l00472"></a>00472 } <a name="l00473"></a>00473 <a name="l00474"></a>00474 <a name="l00475"></a>00475 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">bool</span> <a class="code" href="a00257.html#a7aa7d128febae46b7ef265606e6d0a2c">matchWildcard</a>(<span class="keyword">const</span> <span class="keywordtype">char</span>* wild, <span class="keyword">const</span> <span class="keywordtype">char</span> *str) <a name="l00476"></a>00476 { <a name="l00477"></a>00477 <span class="comment">// Empty arguments: always return a match</span> <a name="l00478"></a>00478 <span class="keywordflow">if</span> (!wild || !str) <span class="keywordflow">return</span> 1; <a name="l00479"></a>00479 <a name="l00480"></a>00480 <span class="keyword">const</span> <span class="keywordtype">char</span> *cp = NULL, *mp = NULL; <a name="l00481"></a>00481 <a name="l00482"></a>00482 <span class="keywordflow">while</span> ((*str) && *wild != <span class="charliteral">'*'</span>) <a name="l00483"></a>00483 { <a name="l00484"></a>00484 <span class="keywordflow">if</span> (*wild != *str && *wild != <span class="charliteral">'?'</span>) <a name="l00485"></a>00485 <span class="comment">// Does not match</span> <a name="l00486"></a>00486 <span class="keywordflow">return</span> 0; <a name="l00487"></a>00487 wild++; <a name="l00488"></a>00488 str++; <a name="l00489"></a>00489 } <a name="l00490"></a>00490 <a name="l00491"></a>00491 <span class="keywordflow">while</span> (*str) <a name="l00492"></a>00492 { <a name="l00493"></a>00493 <span class="keywordflow">if</span> (*wild == <span class="charliteral">'*'</span>) <a name="l00494"></a>00494 { <a name="l00495"></a>00495 <span class="keywordflow">if</span> (!*++wild) <span class="keywordflow">return</span> 1; <a name="l00496"></a>00496 mp = wild; <a name="l00497"></a>00497 cp = str+1; <a name="l00498"></a>00498 } <a name="l00499"></a>00499 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (*wild == *str || *wild == <span class="charliteral">'?'</span>) <a name="l00500"></a>00500 { <a name="l00501"></a>00501 wild++; <a name="l00502"></a>00502 str++; <a name="l00503"></a>00503 } <a name="l00504"></a>00504 <span class="keywordflow">else</span> <a name="l00505"></a>00505 { <a name="l00506"></a>00506 wild = mp; <a name="l00507"></a>00507 str = cp++; <a name="l00508"></a>00508 } <a name="l00509"></a>00509 } <a name="l00510"></a>00510 <a name="l00511"></a>00511 <span class="keywordflow">while</span> (*wild == <span class="charliteral">'*'</span>) wild++; <a name="l00512"></a>00512 <span class="keywordflow">return</span> !*wild; <a name="l00513"></a>00513 } <a name="l00514"></a>00514 <a name="l00515"></a>00515 } <span class="comment">// end namespace</span> <a name="l00516"></a>00516 } <span class="comment">// end namespace</span> <a name="l00517"></a>00517 </pre></div></div> <hr size="1"/><address style="align: right;"><small>Documentation generated for frePPLe by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"/></a></small></address> </div> </div> </body> </html>