[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 | #ifndef _MultiTypeString_H__ |
---|
| 30 | #define _MultiTypeString_H__ |
---|
| 31 | |
---|
| 32 | #include <string> |
---|
[853] | 33 | #include <iostream> |
---|
[792] | 34 | #include "UtilPrereqs.h" |
---|
| 35 | |
---|
| 36 | #include "MultiTypePrimitive.h" |
---|
| 37 | |
---|
| 38 | class _UtilExport MultiTypeString : public MultiTypePrimitive |
---|
| 39 | { |
---|
| 40 | public: |
---|
| 41 | MultiTypeString(MultiType type = MT_null); |
---|
[794] | 42 | inline MultiTypeString(int value) : MultiTypePrimitive(value) {} |
---|
| 43 | inline MultiTypeString(unsigned int value) : MultiTypePrimitive(value) {} |
---|
| 44 | inline MultiTypeString(char value) : MultiTypePrimitive(value) {} |
---|
| 45 | inline MultiTypeString(unsigned char value) : MultiTypePrimitive(value) {} |
---|
| 46 | inline MultiTypeString(short value) : MultiTypePrimitive(value) {} |
---|
| 47 | inline MultiTypeString(unsigned short value) : MultiTypePrimitive(value) {} |
---|
| 48 | inline MultiTypeString(long value) : MultiTypePrimitive(value) {} |
---|
| 49 | inline MultiTypeString(unsigned long value) : MultiTypePrimitive(value) {} |
---|
| 50 | inline MultiTypeString(float value) : MultiTypePrimitive(value) {} |
---|
| 51 | inline MultiTypeString(double value) : MultiTypePrimitive(value) {} |
---|
| 52 | inline MultiTypeString(long double value) : MultiTypePrimitive(value) {} |
---|
| 53 | inline MultiTypeString(bool value) : MultiTypePrimitive(value) {} |
---|
[853] | 54 | inline MultiTypeString(const char* value) { this->setValue(value); } |
---|
| 55 | inline MultiTypeString(const std::string& value) { this->setValue(value); std::cout << "4_1: Created MultiTypeString with value " << value << " and type " << this->getType() << std::endl; } |
---|
| 56 | inline MultiTypeString(const MultiTypeString& mts) { this->setValue(mts); } |
---|
[792] | 57 | |
---|
[794] | 58 | using MultiTypePrimitive::operator=; |
---|
[853] | 59 | inline MultiTypeString& operator=(const char* value) { this->setValue(value); return *this; } |
---|
| 60 | inline MultiTypeString& operator=(const std::string& value) { this->setValue(value); return *this; } |
---|
| 61 | inline MultiTypeString& operator=(const MultiTypeString& mts) { this->setValue(mts); return *this; } |
---|
[792] | 62 | |
---|
[794] | 63 | using MultiTypePrimitive::operator==; |
---|
| 64 | inline bool operator==(const char* value) const { return (this->string_ == std::string(value)); } |
---|
[834] | 65 | inline bool operator==(const std::string& value) const { return (this->string_ == value); } |
---|
[853] | 66 | bool operator==(const MultiTypeString& mts) const; |
---|
[792] | 67 | |
---|
[794] | 68 | using MultiTypePrimitive::operator!=; |
---|
| 69 | inline bool operator!=(const char* value) const { return (this->string_ != std::string(value)); } |
---|
[834] | 70 | inline bool operator!=(const std::string& value) const { return (this->string_ != value); } |
---|
[853] | 71 | bool operator!=(const MultiTypeString& mts) const; |
---|
[792] | 72 | |
---|
[848] | 73 | operator std::string() const; |
---|
| 74 | operator const char*() const; |
---|
[834] | 75 | |
---|
[794] | 76 | using MultiTypePrimitive::setValue; |
---|
[792] | 77 | inline void setValue(const char* value) { this->type_ = MT_string; this->string_ = std::string(value); } |
---|
[834] | 78 | inline void setValue(const std::string& value) { this->type_ = MT_string; this->string_ = value; } |
---|
[853] | 79 | void setValue(const MultiTypeString& mts); |
---|
[792] | 80 | |
---|
[848] | 81 | inline const std::string getString() const { return this->string_; } |
---|
| 82 | inline const char* getConstChar() const { return this->string_.c_str(); } |
---|
[792] | 83 | |
---|
[848] | 84 | inline const std::string& getString() { return this->string_; } |
---|
| 85 | inline const char* getConstChar() { return this->string_.c_str(); } |
---|
| 86 | |
---|
[794] | 87 | using MultiTypePrimitive::getValue; |
---|
[834] | 88 | inline void getValue(std::string* variable) const { (*variable) = this->string_; } |
---|
[797] | 89 | inline void getValue(const char** variable) const { (*variable) = this->string_.c_str(); } |
---|
[792] | 90 | |
---|
[848] | 91 | std::string toString() const; |
---|
| 92 | bool fromString(const std::string value); |
---|
| 93 | |
---|
[792] | 94 | protected: |
---|
| 95 | std::string string_; |
---|
| 96 | }; |
---|
| 97 | |
---|
[797] | 98 | std::ostream& operator<<(std::ostream& out, MultiTypeString& mts); |
---|
| 99 | |
---|
[792] | 100 | #endif /* _MultiTypeString_H__ */ |
---|