Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/libraries/util/MultiType.cc @ 11071

Last change on this file since 11071 was 11071, checked in by landauf, 8 years ago

merged branch cpp11_v3 back to trunk

  • Property svn:eol-style set to native
File size: 9.6 KB
RevLine 
[1716]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 *   Co-authors:
25 *      ...
26 *
27 */
28
[1791]29/**
[2171]30    @file
[1791]31    @brief Implementation of the MultiType.
32*/
33
[1716]34#include "MultiType.h"
35#include "MultiTypeValue.h"
36
[2171]37namespace orxonox
[1716]38{
[9550]39    const MultiType MultiType::Null;
40
[2171]41    /**
42        @brief Converts the current value of the MultiType to a new type.
43        @param type The type
44    */
[11071]45    bool MultiType::convert(Type type)
[1716]46    {
[2171]47        switch (type)
48        {
[9550]49            case Type::Null:
[2662]50                this->reset(); return true;
[9550]51            case Type::Char:
[2171]52                return this->convert<char>(); break;
[9550]53            case Type::UnsignedChar:
[2171]54                return this->convert<unsigned char>(); break;
[9550]55            case Type::Short:
[2171]56                return this->convert<short>(); break;
[9550]57            case Type::UnsignedShort:
[2171]58                return this->convert<unsigned short>(); break;
[9550]59            case Type::Int:
[2171]60                return this->convert<int>(); break;
[9550]61            case Type::UnsignedInt:
[2171]62                return this->convert<unsigned int>(); break;
[9550]63            case Type::Long:
[2171]64                return this->convert<long>(); break;
[9550]65            case Type::UnsignedLong:
[2171]66                return this->convert<unsigned long>(); break;
[9550]67            case Type::LongLong:
[2171]68                return this->convert<long long>(); break;
[9550]69            case Type::UnsignedLongLong:
[2171]70                return this->convert<unsigned long long>(); break;
[9550]71            case Type::Float:
[2171]72                return this->convert<float>(); break;
[9550]73            case Type::Double:
[2171]74                return this->convert<double>(); break;
[9550]75            case Type::LongDouble:
[2171]76                return this->convert<long double>(); break;
[9550]77            case Type::Bool:
[2171]78                return this->convert<bool>(); break;
[9550]79            case Type::VoidPointer:
[2171]80                return this->convert<void*>(); break;
[9550]81            case Type::String:
[2171]82                return this->convert<std::string>(); break;
[9550]83            case Type::Vector2:
[2171]84                return this->convert<orxonox::Vector2>(); break;
[9550]85            case Type::Vector3:
[2171]86                return this->convert<orxonox::Vector3>(); break;
[9550]87            case Type::Vector4:
[2171]88                return this->convert<orxonox::Vector4>(); break;
[9550]89            case Type::ColourValue:
[2171]90                return this->convert<orxonox::ColourValue>(); break;
[9550]91            case Type::Quaternion:
[2171]92                return this->convert<orxonox::Quaternion>(); break;
[9550]93            case Type::Radian:
[2171]94                return this->convert<orxonox::Radian>(); break;
[9550]95            case Type::Degree:
[2171]96                return this->convert<orxonox::Degree>(); break;
97            default:
98                this->reset(); return false; break;
99        };
100    }
[1716]101
[2171]102    /**
103        @brief Returns the name of the current type.
104        @return The name
105    */
106    std::string MultiType::getTypename() const
[1716]107    {
[11071]108        Type type = (this->value_) ? this->value_->type_ : Type::Null;
[1716]109
[2171]110        switch (type)
111        {
[9550]112            case Type::Char:
[2171]113                return "char"; break;
[9550]114            case Type::UnsignedChar:
[2171]115                return "unsigned char"; break;
[9550]116            case Type::Short:
[2171]117                return "short"; break;
[9550]118            case Type::UnsignedShort:
[2171]119                return "unsigned short"; break;
[9550]120            case Type::Int:
[2171]121                return "int"; break;
[9550]122            case Type::UnsignedInt:
[2171]123                return "unsigned int"; break;
[9550]124            case Type::Long:
[2171]125                return "long"; break;
[9550]126            case Type::UnsignedLong:
[2171]127                return "unsigned long"; break;
[9550]128            case Type::LongLong:
[2171]129                return "long long"; break;
[9550]130            case Type::UnsignedLongLong:
[2171]131                return "unsigned long long"; break;
[9550]132            case Type::Float:
[2171]133                return "float"; break;
[9550]134            case Type::Double:
[2171]135                return "double"; break;
[9550]136            case Type::LongDouble:
[2171]137                return "long double"; break;
[9550]138            case Type::Bool:
[2171]139                return "bool"; break;
[9550]140            case Type::VoidPointer:
[2171]141                return "void*"; break;
[9550]142            case Type::String:
[2171]143                return "std::string"; break;
[9550]144            case Type::Vector2:
[2171]145                return "orxonox::Vector2"; break;
[9550]146            case Type::Vector3:
[2171]147                return "orxonox::Vector3"; break;
[9550]148            case Type::Vector4:
[2171]149                return "orxonox::Vector4"; break;
[9550]150            case Type::ColourValue:
[2171]151                return "orxonox::ColourValue"; break;
[9550]152            case Type::Quaternion:
[2171]153                return "orxonox::Quaternion"; break;
[9550]154            case Type::Radian:
[2171]155                return "orxonox::Radian"; break;
[9550]156            case Type::Degree:
[2171]157                return "orxonox::Degree"; break;
158            default:
159                return "unknown"; break;
160        };
161    }
[1716]162
[9550]163    template <> void MultiType::createNewValueContainer(const char& value)                 { this->value_ = new MT_Value<char>                (value, Type::Char            ); }
164    template <> void MultiType::createNewValueContainer(const unsigned char& value)        { this->value_ = new MT_Value<unsigned char>       (value, Type::UnsignedChar    ); }
165    template <> void MultiType::createNewValueContainer(const short& value)                { this->value_ = new MT_Value<short>               (value, Type::Short           ); }
166    template <> void MultiType::createNewValueContainer(const unsigned short& value)       { this->value_ = new MT_Value<unsigned short>      (value, Type::UnsignedShort   ); }
167    template <> void MultiType::createNewValueContainer(const int& value)                  { this->value_ = new MT_Value<int>                 (value, Type::Int             ); }
168    template <> void MultiType::createNewValueContainer(const unsigned int& value)         { this->value_ = new MT_Value<unsigned int>        (value, Type::UnsignedInt     ); }
169    template <> void MultiType::createNewValueContainer(const long& value)                 { this->value_ = new MT_Value<long>                (value, Type::Long            ); }
170    template <> void MultiType::createNewValueContainer(const unsigned long& value)        { this->value_ = new MT_Value<unsigned long>       (value, Type::UnsignedLong    ); }
171    template <> void MultiType::createNewValueContainer(const long long& value)            { this->value_ = new MT_Value<long long>           (value, Type::LongLong        ); }
172    template <> void MultiType::createNewValueContainer(const unsigned long long& value)   { this->value_ = new MT_Value<unsigned long long>  (value, Type::UnsignedLongLong); }
173    template <> void MultiType::createNewValueContainer(const float& value)                { this->value_ = new MT_Value<float>               (value, Type::Float           ); }
174    template <> void MultiType::createNewValueContainer(const double& value)               { this->value_ = new MT_Value<double>              (value, Type::Double          ); }
175    template <> void MultiType::createNewValueContainer(const long double& value)          { this->value_ = new MT_Value<long double>         (value, Type::LongDouble      ); }
176    template <> void MultiType::createNewValueContainer(const bool& value)                 { this->value_ = new MT_Value<bool>                (value, Type::Bool            ); }
177    template <> void MultiType::createNewValueContainer(      void* const& value)          { this->value_ = new MT_Value<void*>               (value, Type::VoidPointer     ); }
178    template <> void MultiType::createNewValueContainer(const std::string& value)          { this->value_ = new MT_Value<std::string>         (value, Type::String          ); }
179    template <> void MultiType::createNewValueContainer(const orxonox::Vector2& value)     { this->value_ = new MT_Value<orxonox::Vector2>    (value, Type::Vector2         ); }
180    template <> void MultiType::createNewValueContainer(const orxonox::Vector3& value)     { this->value_ = new MT_Value<orxonox::Vector3>    (value, Type::Vector3         ); }
181    template <> void MultiType::createNewValueContainer(const orxonox::Vector4& value)     { this->value_ = new MT_Value<orxonox::Vector4>    (value, Type::Vector4         ); }
182    template <> void MultiType::createNewValueContainer(const orxonox::ColourValue& value) { this->value_ = new MT_Value<orxonox::ColourValue>(value, Type::ColourValue     ); }
183    template <> void MultiType::createNewValueContainer(const orxonox::Quaternion& value)  { this->value_ = new MT_Value<orxonox::Quaternion> (value, Type::Quaternion      ); }
184    template <> void MultiType::createNewValueContainer(const orxonox::Radian& value)      { this->value_ = new MT_Value<orxonox::Radian>     (value, Type::Radian          ); }
185    template <> void MultiType::createNewValueContainer(const orxonox::Degree& value)      { this->value_ = new MT_Value<orxonox::Degree>     (value, Type::Degree          ); }
[2171]186}
Note: See TracBrowser for help on using the repository browser.