Added some more docs to String
[libs.git] / docs / html / _util_8h-source.html
blob9932a006c28df8965674fce22c4ef11dce556e33
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
3 <title>LibSylph: Sylph/Core/Util.h Source File</title>
4 <link href="doxygen.css" rel="stylesheet" type="text/css">
5 </head><body>
6 <!-- Generated by Doxygen 1.5.8 -->
7 <div class="navigation" id="top">
8 <div class="tabs">
9 <ul>
10 <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
11 <li><a href="namespaces.html"><span>Namespaces</span></a></li>
12 <li><a href="classes.html"><span>Classes</span></a></li>
13 <li class="current"><a href="files.html"><span>Files</span></a></li>
14 <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
15 </ul>
16 </div>
17 <div class="tabs">
18 <ul>
19 <li><a href="files.html"><span>File&nbsp;List</span></a></li>
20 </ul>
21 </div>
22 <h1>Sylph/Core/Util.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
23 <a name="l00002"></a>00002 <span class="comment"> * LibSylph Class Library</span>
24 <a name="l00003"></a>00003 <span class="comment"> * Copyright (C) 2009 Frank "SeySayux" Erens &lt;seysayux@gmail.com&gt;</span>
25 <a name="l00004"></a>00004 <span class="comment"> *</span>
26 <a name="l00005"></a>00005 <span class="comment"> * This library is free software; you can redistribute it and/or</span>
27 <a name="l00006"></a>00006 <span class="comment"> * modify it under the terms of the LibSylph Pulbic License as published</span>
28 <a name="l00007"></a>00007 <span class="comment"> * by the LibSylph Developers; either version 1.0 of the License, or</span>
29 <a name="l00008"></a>00008 <span class="comment"> * (at your option) any later version.</span>
30 <a name="l00009"></a>00009 <span class="comment"> *</span>
31 <a name="l00010"></a>00010 <span class="comment"> * This library is distributed in the hope that it will be useful,</span>
32 <a name="l00011"></a>00011 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
33 <a name="l00012"></a>00012 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the LibSylph</span>
34 <a name="l00013"></a>00013 <span class="comment"> * Public License for more details.</span>
35 <a name="l00014"></a>00014 <span class="comment"> *</span>
36 <a name="l00015"></a>00015 <span class="comment"> * You should have received a copy of the LibSylph Public License</span>
37 <a name="l00016"></a>00016 <span class="comment"> * along with this Library, if not, contact the LibSylph Developers.</span>
38 <a name="l00017"></a>00017 <span class="comment"> *</span>
39 <a name="l00018"></a>00018 <span class="comment"> * Created on 9 december 2008, 15:34</span>
40 <a name="l00019"></a>00019 <span class="comment"> */</span>
41 <a name="l00020"></a>00020
42 <a name="l00021"></a>00021 <span class="preprocessor">#ifndef UTIL_H_</span>
43 <a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#define UTIL_H_</span>
44 <a name="l00023"></a>00023 <span class="preprocessor"></span>
45 <a name="l00024"></a>00024 <span class="preprocessor">#include "Object.h"</span> <span class="comment">// macros</span>
46 <a name="l00025"></a>00025 <span class="preprocessor">#include "Exception.h"</span>
47 <a name="l00026"></a>00026 <span class="preprocessor">#include "Array.h"</span>
48 <a name="l00027"></a>00027
49 <a name="l00028"></a>00028 <span class="preprocessor">#include &lt;math.h&gt;</span>
50 <a name="l00029"></a>00029
51 <a name="l00030"></a>00030 SYLPH_BEGIN_NAMESPACE
52 <a name="l00031"></a>00031 SYLPH_PUBLIC
53 <a name="l00032"></a>00032
54 <a name="l00033"></a>00033 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;
55 <a name="l00034"></a>00034 <span class="keyword">inline</span> <span class="keywordtype">void</span> carraycopy(<span class="keyword">const</span> T src[], std::size_t srcPos, T dest[],
56 <a name="l00035"></a>00035 std::size_t destPos, std::size_t length) <span class="keywordflow">throw</span> (Exception) {
57 <a name="l00036"></a>00036 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i &lt; length; i++) {
58 <a name="l00037"></a>00037 dest[destPos + i] = src[srcPos + i];
59 <a name="l00038"></a>00038 }
60 <a name="l00039"></a>00039 }
61 <a name="l00040"></a>00040
62 <a name="l00041"></a>00041 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;
63 <a name="l00042"></a>00042 <span class="keyword">inline</span> <span class="keywordtype">void</span> arraycopy(<span class="keyword">const</span> Array&lt;T&gt; &amp; src, std::size_t srcPos, Array&lt;T&gt; &amp; dest,
64 <a name="l00043"></a>00043 std::size_t destPos, std::size_t length) <span class="keywordflow">throw</span> (Exception) {
65 <a name="l00044"></a>00044
66 <a name="l00045"></a>00045 std::size_t srcSize = src.length;
67 <a name="l00046"></a>00046 std::size_t destSize = dest.length;
68 <a name="l00047"></a>00047 <span class="keywordflow">if</span> (srcPos + length &gt; srcSize) sthrow(ArrayException, <span class="stringliteral">"Source array too short"</span>);
69 <a name="l00048"></a>00048 <span class="keywordflow">if</span> (destPos + length &gt; destSize) sthrow(ArrayException, <span class="stringliteral">"Dest array too short"</span>);
70 <a name="l00049"></a>00049
71 <a name="l00050"></a>00050 <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i &lt; length; i++) {
72 <a name="l00051"></a>00051 dest[destPos + i] = src[srcPos + i];
73 <a name="l00052"></a>00052 }
74 <a name="l00053"></a>00053 }
75 <a name="l00054"></a>00054
76 <a name="l00055"></a>00055 <span class="keyword">template</span> &lt;<span class="keyword">typename</span> T, std::<span class="keywordtype">size_t</span> N&gt;
77 <a name="l00056"></a>00056 <span class="keyword">inline</span> std::size_t carraysize(T(&amp;)[N]) {
78 <a name="l00057"></a>00057 <span class="keywordflow">return</span> N;
79 <a name="l00058"></a>00058 }
80 <a name="l00059"></a>00059
81 <a name="l00060"></a>00060 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T, <span class="keyword">class</span> U = T&gt;
82 <a name="l00061"></a>00061 <span class="keyword">inline</span> U abs(T t) {
83 <a name="l00062"></a>00062 <span class="keywordflow">return</span> t &gt; 0 ? t : -t;
84 <a name="l00063"></a>00063 }
85 <a name="l00064"></a>00064
86 <a name="l00065"></a>00065 <span class="keyword">template</span>&lt;&gt;
87 <a name="l00066"></a>00066 <span class="keyword">inline</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> abs&lt;int, unsigned int&gt;(<span class="keywordtype">int</span> t) {
88 <a name="l00067"></a>00067 <span class="keywordflow">return</span> t &gt; 0 ? t : -t;
89 <a name="l00068"></a>00068 }
90 <a name="l00069"></a>00069
91 <a name="l00070"></a>00070 <span class="keyword">template</span>&lt;&gt;
92 <a name="l00071"></a>00071 <span class="keyword">inline</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> abs&lt;long, unsigned long&gt;(<span class="keywordtype">long</span> t) {
93 <a name="l00072"></a>00072 <span class="keywordflow">return</span> t &gt; 0 ? t : -t;
94 <a name="l00073"></a>00073 }
95 <a name="l00074"></a>00074
96 <a name="l00075"></a>00075 <span class="keyword">template</span>&lt;&gt;
97 <a name="l00076"></a>00076 <span class="keyword">inline</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> abs&lt;short, unsigned short&gt;(<span class="keywordtype">short</span> t) {
98 <a name="l00077"></a>00077 <span class="keywordflow">return</span> t &gt; 0 ? t : -t;
99 <a name="l00078"></a>00078 }
100 <a name="l00079"></a>00079
101 <a name="l00080"></a>00080 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;
102 <a name="l00081"></a>00081 <span class="keyword">inline</span> <span class="keywordtype">signed</span> <span class="keywordtype">char</span> sign(T t) {
103 <a name="l00082"></a>00082 <span class="keywordflow">return</span> t &gt; 0? : t == 0? 0 : -1;
104 <a name="l00083"></a>00083 }
105 <a name="l00084"></a>00084
106 <a name="l00085"></a>00085 <span class="keyword">template</span>&lt;&gt;
107 <a name="l00086"></a>00086 <span class="keyword">inline</span> <span class="keywordtype">signed</span> <span class="keywordtype">char</span> sign&lt;double&gt;(<span class="keywordtype">double</span> t) {
108 <a name="l00087"></a>00087 <span class="keywordflow">return</span> copysign(1.0,t);
109 <a name="l00088"></a>00088 }
110 <a name="l00089"></a>00089
111 <a name="l00090"></a>00090
112 <a name="l00091"></a>00091 <span class="keyword">template</span>&lt;&gt;
113 <a name="l00092"></a>00092 <span class="keyword">inline</span> <span class="keywordtype">signed</span> <span class="keywordtype">char</span> sign&lt;float&gt;(<span class="keywordtype">float</span> t) {
114 <a name="l00093"></a>00093 <span class="keywordflow">return</span> copysignf(1.0f, t);
115 <a name="l00094"></a>00094 }
116 <a name="l00095"></a>00095
117 <a name="l00096"></a>00096
118 <a name="l00097"></a>00097 SYLPH_END_NAMESPACE
119 <a name="l00098"></a>00098
120 <a name="l00099"></a>00099 <span class="preprocessor">#endif </span><span class="comment">/* UTIL_H_ */</span>
121 <a name="l00100"></a>00100
122 </pre></div></div>
123 <hr size="1" class="unhidden"><address style="text-align: right;"><small>
124 Documentation for LibSylph by Doxygen
125 </body>
126 </html>