Sophie

Sophie

distrib > Mandriva > 2011.0 > i586 > by-pkgid > a16d689bc65aac5d987d5129109e6de5 > files > 792

irrlicht-doc-1.7.2-1.i586.rpm

<!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>Irrlicht Engine: coreutil.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<table class="irrlicht" >
  <tr valign="middle"> 
    <td><font size="2"><a class="qindex" href="index.html"><font color="#FFFFFF">Home</font></a> 
      | <a class="qindex" href="namespaces.html"><font color="#FFFFFF">Namespaces</font></a> 
      | <a class="qindex" href="hierarchy.html"><font color="#FFFFFF">Hierarchy</font></a> 
      | <a class="qindex" href="classes.html"><font color="#FFFFFF">Alphabetical 
      List</font></a> | <a class="qindex" href="annotated.html"><font color="#FFFFFF"> 
      Class list</font></a> | <a class="qindex" href="files.html"><font color="#FFFFFF">Files</font></a> 
      | <a class="qindex" href="namespacemembers.html"><font color="#FFFFFF"> 
      Namespace&nbsp;Members</font></a> | <a class="qindex" href="functions.html"><font color="#FFFFFF">Class 
      members</font></a> | <a class="qindex" href="globals.html"><font color="#FFFFFF">File 
      members</font></a> | <a class="qindex" href="pages.html"><font color="#FFFFFF">Tutorials</font></a></font> </td>
  </tr>
</table>
<!-- Generated by Doxygen 1.6.2 -->
<h1>coreutil.h</h1><a href="coreutil_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// Copyright (C) 2002-2010 Nikolaus Gebhardt</span>
<a name="l00002"></a>00002 <span class="comment">// This file is part of the &quot;Irrlicht Engine&quot;.</span>
<a name="l00003"></a>00003 <span class="comment">// For conditions of distribution and use, see copyright notice in irrlicht.h</span>
<a name="l00004"></a>00004 
<a name="l00005"></a>00005 <span class="preprocessor">#ifndef __IRR_CORE_UTIL_H_INCLUDED__</span>
<a name="l00006"></a>00006 <span class="preprocessor"></span><span class="preprocessor">#define __IRR_CORE_UTIL_H_INCLUDED__</span>
<a name="l00007"></a>00007 <span class="preprocessor"></span>
<a name="l00008"></a>00008 <span class="preprocessor">#include &quot;<a class="code" href="irr_string_8h.html">irrString.h</a>&quot;</span>
<a name="l00009"></a>00009 <span class="preprocessor">#include &quot;<a class="code" href="path_8h.html">path.h</a>&quot;</span>
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 <span class="keyword">namespace </span>irr
<a name="l00012"></a>00012 {
<a name="l00013"></a>00013 <span class="keyword">namespace </span>core
<a name="l00014"></a>00014 {
<a name="l00015"></a>00015 
<a name="l00020"></a>00020 <span class="comment">// ----------- some basic quite often used string functions -----------------</span>
<a name="l00021"></a>00021 
<a name="l00023"></a>00023 <span class="keyword">inline</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="namespaceirr_1_1core.html#ab214253f8925de2ed42a7d671d02cf7f" title="search if a filename has a proper extension">isFileExtension</a> (    <span class="keyword">const</span> <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a>&amp; filename,
<a name="l00024"></a>00024                                                                 <span class="keyword">const</span> <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a>&amp; ext0,
<a name="l00025"></a>00025                                                                 <span class="keyword">const</span> <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a>&amp; ext1,
<a name="l00026"></a>00026                                                                 <span class="keyword">const</span> <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a>&amp; ext2)
<a name="l00027"></a>00027 {
<a name="l00028"></a>00028         <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> extPos = filename.findLast ( <span class="charliteral">&#39;.&#39;</span> );
<a name="l00029"></a>00029         <span class="keywordflow">if</span> ( extPos &lt; 0 )
<a name="l00030"></a>00030                 <span class="keywordflow">return</span> 0;
<a name="l00031"></a>00031 
<a name="l00032"></a>00032         extPos += 1;
<a name="l00033"></a>00033         <span class="keywordflow">if</span> ( filename.equals_substring_ignore_case ( ext0, extPos ) ) <span class="keywordflow">return</span> 1;
<a name="l00034"></a>00034         <span class="keywordflow">if</span> ( filename.equals_substring_ignore_case ( ext1, extPos ) ) <span class="keywordflow">return</span> 2;
<a name="l00035"></a>00035         <span class="keywordflow">if</span> ( filename.equals_substring_ignore_case ( ext2, extPos ) ) <span class="keywordflow">return</span> 3;
<a name="l00036"></a><a class="code" href="namespaceirr_1_1core.html#a7a0c7be24d78c02b334c3ae5a18005a1">00036</a>         <span class="keywordflow">return</span> 0;
<a name="l00037"></a>00037 }
<a name="l00038"></a>00038 
<a name="l00040"></a>00040 <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="namespaceirr_1_1core.html#a7a0c7be24d78c02b334c3ae5a18005a1" title="search if a filename has a proper extension">hasFileExtension</a> (  <span class="keyword">const</span> <a class="code" href="classirr_1_1core_1_1string.html">io::path</a>&amp; filename,
<a name="l00041"></a>00041                                                                 <span class="keyword">const</span> <a class="code" href="classirr_1_1core_1_1string.html">io::path</a>&amp; ext0,
<a name="l00042"></a>00042                                                                 <span class="keyword">const</span> <a class="code" href="classirr_1_1core_1_1string.html">io::path</a>&amp; ext1 = <span class="stringliteral">&quot;&quot;</span>,
<a name="l00043"></a>00043                                                                 <span class="keyword">const</span> <a class="code" href="classirr_1_1core_1_1string.html">io::path</a>&amp; ext2 = <span class="stringliteral">&quot;&quot;</span>)
<a name="l00044"></a>00044 {
<a name="l00045"></a><a class="code" href="namespaceirr_1_1core.html#a188da2e914c6d4a6535bee08565d877b">00045</a>         <span class="keywordflow">return</span> <a class="code" href="namespaceirr_1_1core.html#ab214253f8925de2ed42a7d671d02cf7f" title="search if a filename has a proper extension">isFileExtension</a> ( filename, ext0, ext1, ext2 ) &gt; 0;
<a name="l00046"></a>00046 }
<a name="l00047"></a>00047 
<a name="l00049"></a>00049 <span class="keyword">inline</span> <a class="code" href="classirr_1_1core_1_1string.html">io::path</a>&amp; <a class="code" href="namespaceirr_1_1core.html#a188da2e914c6d4a6535bee08565d877b" title="cut the filename extension from a source file path and store it in a dest file path...">cutFilenameExtension</a> ( <a class="code" href="classirr_1_1core_1_1string.html">io::path</a> &amp;dest, <span class="keyword">const</span> <a class="code" href="classirr_1_1core_1_1string.html">io::path</a> &amp;source )
<a name="l00050"></a>00050 {
<a name="l00051"></a>00051         <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> endPos = source.<a class="code" href="classirr_1_1core_1_1string.html#a000258d8ce7a49ba10d20bfb8d9d3ad8" title="finds last occurrence of character in string">findLast</a> ( <span class="charliteral">&#39;.&#39;</span> );
<a name="l00052"></a>00052         dest = source.<a class="code" href="classirr_1_1core_1_1string.html#aa1690a37528bbc5449bc46e6502f47a1" title="Returns a substring.">subString</a> ( 0, endPos &lt; 0 ? source.<a class="code" href="classirr_1_1core_1_1string.html#a062f23675d892012c7e8d5d4e92ecd00" title="Returns length of the string&amp;#39;s content.">size</a> () : endPos );
<a name="l00053"></a><a class="code" href="namespaceirr_1_1core.html#abebbe8b229dc865ebeb9bb0fd367d6ea">00053</a>         <span class="keywordflow">return</span> dest;
<a name="l00054"></a>00054 }
<a name="l00055"></a>00055 
<a name="l00057"></a>00057 <span class="keyword">inline</span> <a class="code" href="classirr_1_1core_1_1string.html">io::path</a>&amp; <a class="code" href="namespaceirr_1_1core.html#abebbe8b229dc865ebeb9bb0fd367d6ea" title="get the filename extension from a file path">getFileNameExtension</a> ( <a class="code" href="classirr_1_1core_1_1string.html">io::path</a> &amp;dest, <span class="keyword">const</span> <a class="code" href="classirr_1_1core_1_1string.html">io::path</a> &amp;source )
<a name="l00058"></a>00058 {
<a name="l00059"></a>00059         <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> endPos = source.<a class="code" href="classirr_1_1core_1_1string.html#a000258d8ce7a49ba10d20bfb8d9d3ad8" title="finds last occurrence of character in string">findLast</a> ( <span class="charliteral">&#39;.&#39;</span> );
<a name="l00060"></a>00060         <span class="keywordflow">if</span> ( endPos &lt; 0 )
<a name="l00061"></a>00061                 dest = <span class="stringliteral">&quot;&quot;</span>;
<a name="l00062"></a>00062         <span class="keywordflow">else</span>
<a name="l00063"></a>00063                 dest = source.<a class="code" href="classirr_1_1core_1_1string.html#aa1690a37528bbc5449bc46e6502f47a1" title="Returns a substring.">subString</a> ( endPos, source.<a class="code" href="classirr_1_1core_1_1string.html#a062f23675d892012c7e8d5d4e92ecd00" title="Returns length of the string&amp;#39;s content.">size</a> () );
<a name="l00064"></a><a class="code" href="namespaceirr_1_1core.html#a905c95bab4a7e8d5360a19b0726383a9">00064</a>         <span class="keywordflow">return</span> dest;
<a name="l00065"></a>00065 }
<a name="l00066"></a>00066 
<a name="l00068"></a>00068 <span class="keyword">inline</span> <a class="code" href="classirr_1_1core_1_1string.html">io::path</a>&amp; <a class="code" href="namespaceirr_1_1core.html#a905c95bab4a7e8d5360a19b0726383a9" title="delete path from filename">deletePathFromFilename</a>(<a class="code" href="classirr_1_1core_1_1string.html">io::path</a>&amp; filename)
<a name="l00069"></a>00069 {
<a name="l00070"></a>00070         <span class="comment">// delete path from filename</span>
<a name="l00071"></a>00071         <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a813cca9bac9fa0c1427d89720a451460" title="Type name for character type used by the file system.">fschar_t</a>* s = filename.<a class="code" href="classirr_1_1core_1_1string.html#a4abad222c478c108096ee9297870068c" title="Returns character string.">c_str</a>();
<a name="l00072"></a>00072         <span class="keyword">const</span> <a class="code" href="namespaceirr.html#a813cca9bac9fa0c1427d89720a451460" title="Type name for character type used by the file system.">fschar_t</a>* p = s + filename.<a class="code" href="classirr_1_1core_1_1string.html#a062f23675d892012c7e8d5d4e92ecd00" title="Returns length of the string&amp;#39;s content.">size</a>();
<a name="l00073"></a>00073 
<a name="l00074"></a>00074         <span class="comment">// search for path separator or beginning</span>
<a name="l00075"></a>00075         <span class="keywordflow">while</span> ( *p != <span class="charliteral">&#39;/&#39;</span> &amp;&amp; *p != <span class="charliteral">&#39;\\&#39;</span> &amp;&amp; p != s )
<a name="l00076"></a>00076                 p--;
<a name="l00077"></a>00077 
<a name="l00078"></a>00078         <span class="keywordflow">if</span> ( p != s )
<a name="l00079"></a>00079         {
<a name="l00080"></a>00080                 ++p;
<a name="l00081"></a>00081                 filename = p;
<a name="l00082"></a>00082         }
<a name="l00083"></a><a class="code" href="namespaceirr_1_1core.html#a9215d20e34c12cb6c1522366389bfcce">00083</a>         <span class="keywordflow">return</span> filename;
<a name="l00084"></a>00084 }
<a name="l00085"></a>00085 
<a name="l00087"></a>00087 <span class="keyword">inline</span> <a class="code" href="classirr_1_1core_1_1string.html">io::path</a>&amp; <a class="code" href="namespaceirr_1_1core.html#a9215d20e34c12cb6c1522366389bfcce" title="trim paths">deletePathFromPath</a>(<a class="code" href="classirr_1_1core_1_1string.html">io::path</a>&amp; filename, <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> pathCount)
<a name="l00088"></a>00088 {
<a name="l00089"></a>00089         <span class="comment">// delete path from filename</span>
<a name="l00090"></a>00090         <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> i = filename.<a class="code" href="classirr_1_1core_1_1string.html#a062f23675d892012c7e8d5d4e92ecd00" title="Returns length of the string&amp;#39;s content.">size</a>();
<a name="l00091"></a>00091 
<a name="l00092"></a>00092         <span class="comment">// search for path separator or beginning</span>
<a name="l00093"></a>00093         <span class="keywordflow">while</span> ( i&gt;=0 )
<a name="l00094"></a>00094         {
<a name="l00095"></a>00095                 <span class="keywordflow">if</span> ( filename[i] == <span class="charliteral">&#39;/&#39;</span> || filename[i] == <span class="charliteral">&#39;\\&#39;</span> )
<a name="l00096"></a>00096                 {
<a name="l00097"></a>00097                         <span class="keywordflow">if</span> ( --pathCount &lt;= 0 )
<a name="l00098"></a>00098                                 <span class="keywordflow">break</span>;
<a name="l00099"></a>00099                 }
<a name="l00100"></a>00100                 --i;
<a name="l00101"></a>00101         }
<a name="l00102"></a>00102 
<a name="l00103"></a>00103         <span class="keywordflow">if</span> ( i&gt;0 )
<a name="l00104"></a>00104         {
<a name="l00105"></a>00105                 filename [ i + 1 ] = 0;
<a name="l00106"></a>00106                 filename.<a class="code" href="classirr_1_1core_1_1string.html#a24cf2d676ba5f259872d8d5bed141a45" title="verify the existing string.">validate</a>();
<a name="l00107"></a>00107         }
<a name="l00108"></a>00108         <span class="keywordflow">else</span>
<a name="l00109"></a>00109                 filename=<span class="stringliteral">&quot;&quot;</span>;
<a name="l00110"></a>00110         <span class="keywordflow">return</span> filename;
<a name="l00111"></a><a class="code" href="namespaceirr_1_1core.html#afc9926e02ab9727cd5998ab2ffa9fa32">00111</a> }
<a name="l00112"></a>00112 
<a name="l00115"></a>00115 <span class="keyword">inline</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="namespaceirr_1_1core.html#afc9926e02ab9727cd5998ab2ffa9fa32">isInSameDirectory</a> ( <span class="keyword">const</span> <a class="code" href="classirr_1_1core_1_1string.html">io::path</a>&amp; <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">path</a>, <span class="keyword">const</span> <a class="code" href="classirr_1_1core_1_1string.html">io::path</a>&amp; file )
<a name="l00116"></a>00116 {
<a name="l00117"></a>00117         <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> subA = 0;
<a name="l00118"></a>00118         <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> subB = 0;
<a name="l00119"></a>00119         <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> pos;
<a name="l00120"></a>00120 
<a name="l00121"></a>00121         <span class="keywordflow">if</span> ( path.<a class="code" href="classirr_1_1core_1_1string.html#a062f23675d892012c7e8d5d4e92ecd00" title="Returns length of the string&amp;#39;s content.">size</a>() &amp;&amp; !path.<a class="code" href="classirr_1_1core_1_1string.html#a37c19857c3d44a88ae5a98e5be41b74f" title="compares the first n characters of the strings">equalsn</a> ( file, path.<a class="code" href="classirr_1_1core_1_1string.html#a062f23675d892012c7e8d5d4e92ecd00" title="Returns length of the string&amp;#39;s content.">size</a>() ) )
<a name="l00122"></a>00122                 <span class="keywordflow">return</span> -1;
<a name="l00123"></a>00123 
<a name="l00124"></a>00124         pos = 0;
<a name="l00125"></a>00125         <span class="keywordflow">while</span> ( (pos = path.<a class="code" href="classirr_1_1core_1_1string.html#a6d82f74b061b248f01133f34b94841d9" title="finds next occurrence of character in string">findNext</a> ( <span class="charliteral">&#39;/&#39;</span>, pos )) &gt;= 0 )
<a name="l00126"></a>00126         {
<a name="l00127"></a>00127                 subA += 1;
<a name="l00128"></a>00128                 pos += 1;
<a name="l00129"></a>00129         }
<a name="l00130"></a>00130 
<a name="l00131"></a>00131         pos = 0;
<a name="l00132"></a>00132         <span class="keywordflow">while</span> ( (pos = file.<a class="code" href="classirr_1_1core_1_1string.html#a6d82f74b061b248f01133f34b94841d9" title="finds next occurrence of character in string">findNext</a> ( <span class="charliteral">&#39;/&#39;</span>, pos )) &gt;= 0 )
<a name="l00133"></a>00133         {
<a name="l00134"></a>00134                 subB += 1;
<a name="l00135"></a>00135                 pos += 1;
<a name="l00136"></a>00136         }
<a name="l00137"></a>00137 
<a name="l00138"></a>00138         <span class="keywordflow">return</span> subB - subA;
<a name="l00139"></a>00139 }
<a name="l00140"></a>00140 
<a name="l00141"></a>00141 
<a name="l00143"></a><a class="code" href="namespaceirr_1_1core.html#aca7b6fe1985b526a8519885bbbd670bb">00143</a> <span class="preprocessor">#undef isdigit</span>
<a name="l00144"></a><a class="code" href="namespaceirr_1_1core.html#a5d1328379d825a783e8ac832480701b7">00144</a> <span class="preprocessor"></span><span class="preprocessor">#undef isspace</span>
<a name="l00145"></a>00145 <span class="preprocessor"></span><span class="preprocessor">#undef isupper</span>
<a name="l00146"></a>00146 <span class="preprocessor"></span><span class="keyword">inline</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="namespaceirr_1_1core.html#ac7f1fc1c7eb3f8291b8a044214823070" title="some standard function ( to remove dependencies )">isdigit</a>(<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> c) { <span class="keywordflow">return</span> c &gt;= <span class="charliteral">&#39;0&#39;</span> &amp;&amp; c &lt;= <span class="charliteral">&#39;9&#39;</span>; }
<a name="l00147"></a>00147 <span class="keyword">inline</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="namespaceirr_1_1core.html#aca7b6fe1985b526a8519885bbbd670bb">isspace</a>(<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> c) { <span class="keywordflow">return</span> c == <span class="charliteral">&#39; &#39;</span> || c == <span class="charliteral">&#39;\f&#39;</span> || c == <span class="charliteral">&#39;\n&#39;</span> || c == <span class="charliteral">&#39;\r&#39;</span> || c == <span class="charliteral">&#39;\t&#39;</span> || c == <span class="charliteral">&#39;\v&#39;</span>; }
<a name="l00148"></a>00148 <span class="keyword">inline</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <a class="code" href="namespaceirr_1_1core.html#a5d1328379d825a783e8ac832480701b7">isupper</a>(<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> c) { <span class="keywordflow">return</span> c &gt;= <span class="charliteral">&#39;A&#39;</span> &amp;&amp; c &lt;= <span class="charliteral">&#39;Z&#39;</span>; }
<a name="l00149"></a>00149 
<a name="l00150"></a>00150 
<a name="l00151"></a>00151 } <span class="comment">// end namespace core</span>
<a name="l00152"></a>00152 } <span class="comment">// end namespace irr</span>
<a name="l00153"></a>00153 
<a name="l00154"></a>00154 <span class="preprocessor">#endif</span>
<a name="l00155"></a>00155 <span class="preprocessor"></span>
</pre></div></div>
<hr size="1">
<address style="align: right;">
<small> </small>
</address>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
  <tr> 
    <td width="0"> <div align="left"><small><a href="http://irrlicht.sourceforge.net" target="_blank"><img src="irrlicht.png" alt="The Irrlicht Engine" align="middle" border=0 width=88 height=31></a></small></div></td>
    <td> <div align="left"><small><em><font size="2">The <a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht 
        Engine</a> Documentation &copy; 2003-2010 by Nikolaus Gebhardt. Generated 
        on Sun Oct 24 12:41:56 2010 by <a href="http://www.doxygen.org" target="_blank">Doxygen</a> 
        (1.6.2)</font></em></small></div></td>
  </tr>
</table>
<address style="align: right;">
</address>
</body>
</html>