[792] | 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 "MultiTypeString.h" |
---|
| 30 | |
---|
| 31 | MultiTypeString::MultiTypeString(MultiType type) : MultiTypePrimitive(type) |
---|
| 32 | { |
---|
| 33 | if (type == MT_constchar) |
---|
| 34 | this->string_ = std::string(""); |
---|
| 35 | else if (type == MT_string) |
---|
| 36 | this->string_ = std::string(""); |
---|
| 37 | } |
---|
| 38 | |
---|
[794] | 39 | MultiTypeString::MultiTypeString(const MultiTypeString& mts) : MultiTypePrimitive(mts) |
---|
[792] | 40 | { |
---|
| 41 | this->type_ = mts.type_; |
---|
| 42 | this->value_ = mts.value_; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | MultiTypeString& MultiTypeString::operator=(const MultiTypeString& mts) |
---|
| 46 | { |
---|
| 47 | this->type_ = mts.type_; |
---|
| 48 | this->value_ = mts.value_; |
---|
| 49 | return *this; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | bool MultiTypeString::operator==(const MultiTypeString& mts) const |
---|
| 53 | { |
---|
| 54 | if (!MultiTypePrimitive::operator==(mts) && this->type_ == mts.type_) |
---|
| 55 | { |
---|
| 56 | if (this->type_ == MT_constchar) |
---|
| 57 | return (this->string_ == mts.string_); |
---|
| 58 | else if (this->type_ == MT_string) |
---|
| 59 | return (this->string_ == mts.string_); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | return false; |
---|
| 63 | } |
---|
| 64 | |
---|
| 65 | bool MultiTypeString::operator!=(const MultiTypeString& mts) const |
---|
| 66 | { |
---|
| 67 | if (MultiTypePrimitive::operator==(mts) && this->type_ == mts.type_) |
---|
| 68 | { |
---|
| 69 | if (this->type_ == MT_constchar) |
---|
| 70 | return (this->string_ != mts.string_); |
---|
| 71 | else if (this->type_ == MT_string) |
---|
| 72 | return (this->string_ != mts.string_); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | return true; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | void MultiTypeString::setValue(const MultiTypeString& mts) |
---|
| 79 | { |
---|
| 80 | this->type_ = mts.type_; |
---|
| 81 | this->value_ = mts.value_; |
---|
| 82 | } |
---|
[797] | 83 | |
---|
| 84 | std::ostream& operator<<(std::ostream& out, MultiTypeString& mts) |
---|
| 85 | { |
---|
| 86 | if (mts.isA(MT_constchar)) |
---|
| 87 | out << mts.getConstChar(); |
---|
| 88 | else if (mts.isA(MT_string)) |
---|
| 89 | out << mts.getString(); |
---|
| 90 | else |
---|
| 91 | out << ((MultiTypePrimitive)mts); |
---|
| 92 | |
---|
| 93 | return out; |
---|
| 94 | } |
---|