logger_8c-source.html

来自「仿真人工智能是指用人工的方法和技术」· HTML 代码 · 共 243 行 · 第 1/2 页

HTML
243
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>Logger.C Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body bgcolor="#ffffff"><!-- Generated by Doxygen 1.2.12 --><center><a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; <a class="qindex" href="globals.html">File Members</a> &nbsp; </center><hr><h1>Logger.C</h1><a href="Logger_8C.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <font class="comment">/*</font>00002 <font class="comment">Copyright (c) 2000,2001, Jelle Kok, University of Amsterdam</font>00003 <font class="comment">All rights reserved.</font>00004 <font class="comment"></font>00005 <font class="comment">Redistribution and use in source and binary forms, with or without </font>00006 <font class="comment">modification, are permitted provided that the following conditions are met:</font>00007 <font class="comment"></font>00008 <font class="comment">1. Redistributions of source code must retain the above copyright notice, this </font>00009 <font class="comment">list of conditions and the following disclaimer. </font>00010 <font class="comment"></font>00011 <font class="comment">2. Redistributions in binary form must reproduce the above copyright notice, </font>00012 <font class="comment">this list of conditions and the following disclaimer in the documentation </font>00013 <font class="comment">and/or other materials provided with the distribution. </font>00014 <font class="comment"></font>00015 <font class="comment">3. Neither the name of the University of Amsterdam nor the names of its </font>00016 <font class="comment">contributors may be used to endorse or promote products derived from this </font>00017 <font class="comment">software without specific prior written permission. </font>00018 <font class="comment"></font>00019 <font class="comment">THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" </font>00020 <font class="comment">AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE </font>00021 <font class="comment">IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE </font>00022 <font class="comment">DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE </font>00023 <font class="comment">FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL </font>00024 <font class="comment">DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR </font>00025 <font class="comment">SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER </font>00026 <font class="comment">CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, </font>00027 <font class="comment">OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE </font>00028 <font class="comment">OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</font>00029 <font class="comment">*/</font>00046 <font class="preprocessor">#include "<a class="code" href="Logger_8h.html">Logger.h</a>"</font>00047 <font class="preprocessor">#include &lt;stdio.h&gt;</font>    <font class="comment">// needed for vsprintf</font>00048 <font class="preprocessor">#include &lt;string&gt;</font>     <font class="comment">// needed for string</font>00049 <font class="preprocessor">#ifdef Solaris</font>00050 <font class="preprocessor"></font><font class="preprocessor"> #include &lt;varargs.h&gt;</font> <font class="comment">// needed for va_list and va_start under Solaris</font>00051 <font class="preprocessor">#endif</font>00052 <font class="preprocessor"></font><a name="l00053"></a><a class="code" href="Logger_8C.html#a0">00053</a> <a class="code" href="classLogger.html">Logger</a> <a class="code" href="Logger_8C.html#a0">Log</a>;          00055 <font class="comment">/*****************************************************************************/</font>00056 <font class="comment">/**************************** LOGGER *****************************************/</font>00057 <font class="comment">/*****************************************************************************/</font>00058 <a name="l00066"></a><a class="code" href="classLogger.html#a0">00066</a> <a class="code" href="classLogger.html#a0">Logger::Logger</a>( ostream&amp; o, <font class="keywordtype">int</font> iMin, <font class="keywordtype">int</font> iMax )00067 {00068   <a class="code" href="classLogger.html#o2">iMinLogLevel</a> = iMin;00069   <a class="code" href="classLogger.html#o3">iMaxLogLevel</a> = iMax;00070   strcpy( <a class="code" href="classLogger.html#o5">strHeader</a>, <font class="stringliteral">""</font> );00071   <a class="code" href="classLogger.html#o0">timing</a>.<a class="code" href="classTiming.html#a2">restartTime</a>();00072   <a class="code" href="classLogger.html#o6">os</a> = &amp;o;00073 }00074 <a name="l00082"></a><a class="code" href="classLogger.html#a1">00082</a> <font class="keywordtype">bool</font> <a class="code" href="classLogger.html#a1">Logger::log</a>( <font class="keywordtype">int</font> iLevel, string str)00083 {00084   <font class="keywordflow">if</font>( <a class="code" href="classLogger.html#a5">isInLogLevel</a>( iLevel ) )00085   {00086     *<a class="code" href="classLogger.html#o6">os</a> &lt;&lt; <a class="code" href="classLogger.html#o5">strHeader</a> &lt;&lt; str;00087     <font class="keywordflow">return</font> <font class="keyword">true</font>;00088   }00089 00090   <font class="keywordflow">return</font> <font class="keyword">false</font>;00091 }00092 <a name="l00103"></a><a class="code" href="classLogger.html#a2">00103</a> <font class="keywordtype">bool</font> <a class="code" href="classLogger.html#a1">Logger::log</a>( <font class="keywordtype">int</font> iLevel, <font class="keywordtype">char</font> *str, ... )00104 {00105   <font class="keywordflow">if</font>( <a class="code" href="classLogger.html#a5">isInLogLevel</a>( iLevel ) )00106   {00107     va_list ap;00108 <font class="preprocessor">#ifdef Solaris</font>00109 <font class="preprocessor"></font>    va_start( ap );00110 <font class="preprocessor">#else</font>00111 <font class="preprocessor"></font>    va_start( ap, str );00112 <font class="preprocessor">#endif</font>00113 <font class="preprocessor"></font>    vsprintf( <a class="code" href="classLogger.html#o1">buf</a>, str, ap );00114     va_end(ap);00115 00116     *<a class="code" href="classLogger.html#o6">os</a> &lt;&lt; <a class="code" href="classLogger.html#o5">strHeader</a> &lt;&lt; <a class="code" href="classLogger.html#o1">buf</a> &lt;&lt; endl;00117     <font class="keywordflow">return</font> <font class="keyword">true</font>;00118   }00119 00120   <font class="keywordflow">return</font> <font class="keyword">false</font>;00121 }00122 <a name="l00134"></a><a class="code" href="classLogger.html#a3">00134</a> <font class="keywordtype">bool</font> <a class="code" href="classLogger.html#a3">Logger::logWithTime</a>( <font class="keywordtype">int</font> iLevel, <font class="keywordtype">char</font> *str, ... )00135 {00136   <font class="keywordflow">if</font>( <a class="code" href="classLogger.html#a5">isInLogLevel</a>( iLevel ) )00137   {00138     va_list ap;00139 <font class="preprocessor">#ifdef Solaris</font>00140 <font class="preprocessor"></font>    va_start( ap );00141 <font class="preprocessor">#else</font>00142 <font class="preprocessor"></font>    va_start( ap, str );00143 <font class="preprocessor">#endif</font>00144 <font class="preprocessor"></font>    vsprintf( <a class="code" href="classLogger.html#o1">buf</a>, str, ap );00145     va_end(ap);00146 00147     string s = <a class="code" href="classLogger.html#o5">strHeader</a>;00148     s.append( <a class="code" href="classLogger.html#o1">buf</a> );00149     s.copy( <a class="code" href="classLogger.html#o1">buf</a>, string::npos );00150     <a class="code" href="classLogger.html#o1">buf</a>[s.length()] = <font class="charliteral">'\0'</font>;00151     <a class="code" href="classLogger.html#o0">timing</a>.<a class="code" href="classTiming.html#a0">printTimeDiffWithText</a>( *<a class="code" href="classLogger.html#o6">os</a>, <a class="code" href="classLogger.html#o1">buf</a> );00152     <font class="keywordflow">return</font> <font class="keyword">true</font>;00153   }00154 00155   <font class="keywordflow">return</font> <font class="keyword">false</font>;00156 }00157 <a name="l00159"></a><a class="code" href="classLogger.html#a4">00159</a> <font class="keywordtype">void</font> <a class="code" href="classLogger.html#a4">Logger::restartTimer</a>()00160 {00161   <font class="keywordflow">return</font> <a class="code" href="classLogger.html#o0">timing</a>.<a class="code" href="classTiming.html#a2">restartTime</a>();00162 }00163 <a name="l00169"></a><a class="code" href="classLogger.html#a5">00169</a> <font class="keywordtype">bool</font> <a class="code" href="classLogger.html#a5">Logger::isInLogLevel</a>( <font class="keywordtype">int</font> iLevel )00170 {00171   <font class="keywordflow">return</font> ( iLevel &gt;= <a class="code" href="classLogger.html#a6">getMinLogLevel</a>() &amp;&amp; iLevel &lt;= <a class="code" href="classLogger.html#a8">getMaxLogLevel</a>() ) ||00172          iLevel == <a class="code" href="classLogger.html#o4">iExtraLogLevel</a>; ;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?