Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/doc/src/libraries/util/MathConvert.h @ 7367

Last change on this file since 7367 was 7367, checked in by rgrieder, 14 years ago

Added Doxygen documentation for ExprParser, MathConvert, OrxEnum, OrxAssert and TriBool.
Adjusted Doxygen documentation for Clock and Exception.

  • Property svn:eol-style set to native
File size: 6.6 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *      Reto Grieder
25 *   Co-authors:
26 *      ...
27 */
28
29/**
30@file
31@brief
32    Conversion functions for Math types like Ogre::Vector3 (definitions are in Math.cc)
33*/
34
35#ifndef _MathConvert_H__
36#define _MathConvert_H__
37
38#include "UtilPrereqs.h"
39#include "Math.h"
40#include "Convert.h"
41
42namespace orxonox
43{
44    ////////////////////
45    // Math to string //
46    ////////////////////
47
48    /// Ogre::Vector2 to std::string conversion
49    template <>
50    struct ConverterExplicit<orxonox::Vector2, std::string>
51    {
52        FORCEINLINE static bool convert(std::string* output, const orxonox::Vector2& input)
53        {
54            std::ostringstream ostream;
55            if (ostream << input.x << ',' << input.y)
56            {
57                (*output) = ostream.str();
58                return true;
59            }
60            return false;
61        }
62    };
63
64    /// Ogre::Vector3 to std::string conversion
65    template <>
66    struct ConverterExplicit<orxonox::Vector3, std::string>
67    {
68        FORCEINLINE static bool convert(std::string* output, const orxonox::Vector3& input)
69        {
70            std::ostringstream ostream;
71            if (ostream << input.x << ',' << input.y << ',' << input.z)
72            {
73                (*output) = ostream.str();
74                return true;
75            }
76            return false;
77        }
78    };
79
80    /// Ogre::Vector4 to std::string conversion
81    template <>
82    struct ConverterExplicit<orxonox::Vector4, std::string>
83    {
84        FORCEINLINE static bool convert(std::string* output, const orxonox::Vector4& input)
85        {
86            std::ostringstream ostream;
87            if (ostream << input.x << ',' << input.y << ',' << input.z << ',' << input.w)
88            {
89                (*output) = ostream.str();
90                return true;
91            }
92            return false;
93        }
94    };
95
96    /// Ogre::Quaternion to std::string conversion
97    template <>
98    struct ConverterExplicit<orxonox::Quaternion, std::string>
99    {
100        FORCEINLINE static bool convert(std::string* output, const orxonox::Quaternion& input)
101        {
102            std::ostringstream ostream;
103            if (ostream << input.w << ',' << input.x << ',' << input.y << ',' << input.z)
104            {
105                (*output) = ostream.str();
106                return true;
107            }
108            return false;
109        }
110    };
111
112    /// Ogre::ColourValue to std::string conversion
113    template <>
114    struct ConverterExplicit<orxonox::ColourValue, std::string>
115    {
116        FORCEINLINE static bool convert(std::string* output, const orxonox::ColourValue& input)
117        {
118            std::ostringstream ostream;
119            if (ostream << input.r << ',' << input.g << ',' << input.b << ',' << input.a)
120            {
121                (*output) = ostream.str();
122                return true;
123            }
124            return false;
125        }
126    };
127
128
129    ////////////////////
130    // string to Math //
131    ////////////////////
132
133    /// std::string to Ogre::Vector2 conversion
134    template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector2>
135    { static bool convert(orxonox::Vector2*     output, const std::string& input); };
136    /// std::string to Ogre::Vector3 conversion
137    template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector3>
138    { static bool convert(orxonox::Vector3*     output, const std::string& input); };
139    /// std::string to Ogre::Vector4 conversion
140    template <> struct _UtilExport ConverterFallback<std::string, orxonox::Vector4>
141    { static bool convert(orxonox::Vector4*     output, const std::string& input); };
142    /// std::string to Ogre::Quaternion conversion
143    template <> struct _UtilExport ConverterFallback<std::string, orxonox::Quaternion>
144    { static bool convert(orxonox::Quaternion*  output, const std::string& input); };
145    /// std::string to Ogre::ColourValue conversion
146    template <> struct _UtilExport ConverterFallback<std::string, orxonox::ColourValue>
147    { static bool convert(orxonox::ColourValue* output, const std::string& input); };
148
149
150    ///////////////////////////////
151    // From and to Radian/Degree //
152    ///////////////////////////////
153
154    /// Delegates conversions from Radian to conversions from float
155    template <class ToType>
156    struct ConverterFallback<orxonox::Radian, ToType>
157    {
158        FORCEINLINE static bool convert(ToType* output, const orxonox::Radian& input)
159        {
160            return convertValue<Ogre::Real, ToType>(output, input.valueRadians());
161        }
162    };
163
164    /// Delegates conversions from Degree to conversions from float
165    template <class ToType>
166    struct ConverterFallback<orxonox::Degree, ToType>
167    {
168        FORCEINLINE static bool convert(ToType* output, const orxonox::Degree& input)
169        {
170            return convertValue<Ogre::Real, ToType>(output, input.valueDegrees());
171        }
172    };
173
174    /// Delegates conversions to Radian to conversions to float
175    template <class FromType>
176    struct ConverterFallback<FromType, orxonox::Radian>
177    {
178        FORCEINLINE static bool convert(orxonox::Radian* output, const FromType& input)
179        {
180            float temp;
181            if (convertValue(&temp, input))
182            {
183                *output = temp;
184                return true;
185            }
186            else
187                return false;
188        }
189    };
190
191    /// Delegates conversions to Degree to conversions to float
192    template <class FromType>
193    struct ConverterFallback<FromType, orxonox::Degree>
194    {
195        FORCEINLINE static bool convert(orxonox::Degree* output, const FromType& input)
196        {
197            float temp;
198            if (convertValue(&temp, input))
199            {
200                *output = temp;
201                return true;
202            }
203            else
204                return false;
205        }
206    };
207}
208
209#endif /* _MathConvert_H__ */
Note: See TracBrowser for help on using the repository browser.