- Partly implemented client side prediction (still unstable).
[peakengine.git] / engine / include / core / Util.h
blob7965508d93f6a8f2789113cad7674f5cff4724e7
1 /*
2 Copyright (C) 2008 Mathias Gottschlag, Lukas Kropatschek
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in the
6 Software without restriction, including without limitation the rights to use,
7 copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
8 Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #ifndef _UTIL_H_
23 #define _UTIL_H_
25 #include <string>
27 #include "core/Vector3D.h"
28 #include "core/Vector2D.h"
29 #include "core/Vector2DI.h"
31 //tolua_begin
32 namespace peak
34 /**
35 * \brief Removes all whitespaces from the beginning and the end of the specified string.
36 * \param str Pointer to the string
37 * \return Number of deleted characters
39 int trimString(std::string *str);
40 /**
41 * \brief Splits a string in two.
43 * The function searches for the character c and puts the string before into
44 * str1 and the string afterwards into str2.
46 * Example:
47 * \code
48 * splitString("abcdefgh", 'd', &str1, &str2);
49 * \endcode
50 * This would create the strings "abc" and "efgh", not including the 'd'.
51 * \param str String to be splitted
52 * \param c Character to look for
53 * \param str1 Pointer to the string variable for the first part
54 * \param str2 Pointer to the string variable for the second part
55 * \return Returns false if c could not be found.
57 bool splitString(std::string str, char c, std::string *str1, std::string *str2);
58 /**
59 * \brief Splits a string in two.
61 * The function searches for the characters in split and puts the string
62 * before into str1 and the string afterwards into str2.
63 * \param str String to be splitted
64 * \param split String holding the characters to look for
65 * \param str1 Pointer to the string variable for the first part
66 * \param str2 Pointer to the string variable for the second part
67 * \return Returns false if no character in split could be found.
69 bool splitString(std::string str, std::string split, std::string *str1, std::string *str2);
71 /**
72 * \brief Converts a string to a float.
73 * \param str String to be converted
74 * \return Value of the extracted number
76 float toFloat(std::string str);
77 /**
78 * \brief Converts a string to a int.
79 * \param str String to be converted
80 * \return Value of the extracted number
82 int toInt(std::string str);
84 /**
85 * \brief Converts a string to a Vector3D
86 * \param str String to be converted.
87 * \return string as Vector3D
89 Vector3D toVector3D(std::string str);
91 /**
92 * \brief Converts a string to a Vector2D
93 * \param str String to be converted.
94 * \return string as Vector2D
96 Vector2D toVector2D(std::string str);
98 /**
99 * \brief Converts a string to a Vector2DI
100 * \param str String to be converted.
101 * \return string as Vector2DI
103 Vector2DI toVector2DI(std::string str);
106 * \brief Converts a string to a bool.
107 * \param str String to be converted
108 * \return string as bool.
110 bool toBool(std::string str);
113 * \brief Creates a string from an int.
114 * \param v Value of the number
115 * \return Created string
117 std::string toString(int v);
119 * \brief Creates a string from a bool.
120 * \param b Boolean value
121 * \return Created string
123 std::string toString(bool b);
125 * \brief Creates a string from a float.
126 * \param v Value of the number
127 * \return Created string
129 std::string toString(float v);
131 * \brief Creates a string from a Vector3D.
132 * \param v Value of the number
133 * \return Created string
135 std::string toString(Vector3D v);
137 * \brief Creates a string from a Vector2D.
138 * \param v Value of the number
139 * \return Created string
141 std::string toString(Vector2D v);
143 * \brief Creates a string from a Vector2DI.
144 * \param v Value of the number
145 * \return Created string
147 std::string toString(Vector2DI v);
150 * \brief Converts a string to a wide string.
152 std::wstring toWString(std::string s);
155 * \brief Strips the directory from a file name
157 std::string trimFilename(std::string filename);
159 * \brief Returns the extension of a file name
161 std::string getExtension(std::string filename);
164 * \brief Converts a string to lower case
166 std::string lowerCase(std::string s);
169 * \brief Returns true if the two given pointers are equal and false if not.
171 bool equals(void *p1, void *p2);
174 * \brief Corrects a false euler Vector3D.
176 void correct(Vector3D v);
178 //tolua_end
180 #endif