Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core/src/util/MultiTypeMath.cc @ 797

Last change on this file since 797 was 797, checked in by landauf, 16 years ago

config-values are working again, now with a totally reworked ConfigValueContainer using MultiTypes (this commit is just a bugfix, the major work was done before, see r792)

added << operator to std::ostream for all MultiTypes

File size: 4.1 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Fabian 'x3n' Landau
23 *   Co-authors:
24 *      ...
25 *
26 *   Inspiration: MultiType by Benjamin Grauer
27 */
28
29#include "MultiTypeMath.h"
30
31MultiTypeMath::MultiTypeMath(MultiType type) : MultiTypeString(type)
32{
33    if (type == MT_vector2)
34        this->vector2_ = orxonox::Vector2(0, 0);
35    else if (type == MT_vector3)
36        this->vector3_ = orxonox::Vector3(0, 0, 0);
37    else if (type == MT_colourvalue)
38        this->colourvalue_ = orxonox::ColourValue(0, 0, 0, 0);
39    else if (type == MT_quaternion)
40        this->quaternion_ = orxonox::Quaternion(1, 0, 0, 0);
41    else if (type == MT_radian)
42        this->radian_ = orxonox::Radian(0);
43    else if (type == MT_degree)
44        this->degree_ = orxonox::Degree(0);
45}
46
47MultiTypeMath::MultiTypeMath(const MultiTypeMath& mtm) : MultiTypeString(mtm)
48{
49    this->type_ = mtm.type_;
50    this->value_ = mtm.value_;
51}
52
53MultiTypeMath& MultiTypeMath::operator=(const MultiTypeMath& mtm)
54{
55    this->type_ = mtm.type_;
56    this->value_ = mtm.value_;
57    return *this;
58}
59
60bool MultiTypeMath::operator==(const MultiTypeMath& mtm) const
61{
62    if (!MultiTypeString::operator==(mtm) && this->type_ == mtm.type_)
63    {
64        if (this->type_ == MT_vector2)
65            return (this->vector2_ == mtm.vector2_);
66        else if (this->type_ == MT_vector3)
67            return (this->vector3_ == mtm.vector3_);
68        else if (this->type_ == MT_colourvalue)
69            return (this->colourvalue_ == mtm.colourvalue_);
70        else if (this->type_ == MT_quaternion)
71            return (this->quaternion_ == mtm.quaternion_);
72        else if (this->type_ == MT_radian)
73            return (this->radian_ == mtm.radian_);
74        else if (this->type_ == MT_degree)
75            return (this->degree_ == mtm.degree_);
76    }
77
78    return false;
79}
80
81bool MultiTypeMath::operator!=(const MultiTypeMath& mtm) const
82{
83    if (MultiTypeString::operator==(mtm) && this->type_ == mtm.type_)
84    {
85        if (this->type_ == MT_vector2)
86            return (this->vector2_ != mtm.vector2_);
87        else if (this->type_ == MT_vector3)
88            return (this->vector3_ != mtm.vector3_);
89        else if (this->type_ == MT_colourvalue)
90            return (this->colourvalue_ != mtm.colourvalue_);
91        else if (this->type_ == MT_quaternion)
92            return (this->quaternion_ != mtm.quaternion_);
93        else if (this->type_ == MT_radian)
94            return (this->radian_ != mtm.radian_);
95        else if (this->type_ == MT_degree)
96            return (this->degree_ != mtm.degree_);
97    }
98
99    return true;
100}
101
102void MultiTypeMath::setValue(const MultiTypeMath& mtm)
103{
104    this->type_ = mtm.type_;
105    this->value_ = mtm.value_;
106}
107
108std::ostream& operator<<(std::ostream& out, MultiTypeMath& mtm)
109{
110    if (mtm.isA(MT_vector2))
111        out << mtm.getVector2();
112    else if (mtm.isA(MT_vector3))
113        out << mtm.getVector3();
114    else if (mtm.isA(MT_colourvalue))
115        out << mtm.getColourValue();
116    else if (mtm.isA(MT_quaternion))
117        out << mtm.getQuaternion();
118    else if (mtm.isA(MT_radian))
119        out << mtm.getRadian();
120    else if (mtm.isA(MT_degree))
121        out << mtm.getDegree();
122    else
123        out << ((MultiTypeString)mtm);
124
125    return out;
126}
Note: See TracBrowser for help on using the repository browser.