diff options
| author | ljfa-ag <ljfa-ag@web.de> | 2015-06-23 22:14:00 +0200 |
|---|---|---|
| committer | ljfa-ag <ljfa-ag@web.de> | 2015-06-23 22:20:02 +0200 |
| commit | 2b3f7e4b90b5787dbe8b4b40dcfc806bcb3f014e (patch) | |
| tree | ac2d13d74b7290c6e02435139c4df7f69314595b | |
| parent | 50d94e7d513f68d25cd5e72de880bb6f78de50e7 (diff) | |
| download | Project-Tick-2b3f7e4b90b5787dbe8b4b40dcfc806bcb3f014e.tar.gz Project-Tick-2b3f7e4b90b5787dbe8b4b40dcfc806bcb3f014e.zip | |
Create tag_string.h
| -rw-r--r-- | include/libnbt.h | 1 | ||||
| -rw-r--r-- | include/tag_primitive.h | 6 | ||||
| -rw-r--r-- | include/tag_string.h | 59 | ||||
| -rw-r--r-- | test/nbttest.cpp | 21 |
4 files changed, 84 insertions, 3 deletions
diff --git a/include/libnbt.h b/include/libnbt.h index 7eb0d1341f..4105be7560 100644 --- a/include/libnbt.h +++ b/include/libnbt.h @@ -21,5 +21,6 @@ #define LIBNBT_H_INCLUDED #include "tag_primitive.h" +#include "tag_string.h" #endif // LIBNBT_H_INCLUDED diff --git a/include/tag_primitive.h b/include/tag_primitive.h index 397ea64da3..f5fab1bdf9 100644 --- a/include/tag_primitive.h +++ b/include/tag_primitive.h @@ -44,13 +44,13 @@ public: tag_primitive(T value = 0); - tag_primitive& operator=(T value); - void set(T value); - operator T&(); operator T() const; T get() const; + tag_primitive& operator=(T value); + void set(T value); + tag_type get_type() const noexcept override; private: diff --git a/include/tag_string.h b/include/tag_string.h new file mode 100644 index 0000000000..1e4c76ae6c --- /dev/null +++ b/include/tag_string.h @@ -0,0 +1,59 @@ +/* + * libnbt++ - A library for the Minecraft Named Binary Tag format. + * Copyright (C) 2013, 2015 ljfa-ag + * + * This file is part of libnbt++. + * + * libnbt++ is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * libnbt++ is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with libnbt++. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef TAG_STRING_H_INCLUDED +#define TAG_STRING_H_INCLUDED + +#include "tag.h" +#include <string> + +namespace nbt +{ + +///Contains a UTF-8 string +class tag_string : public tag +{ +public: + ///The type of the tag + static constexpr tag_type type = tag_type::String; + + tag_string(const std::string& str); + tag_string(std::string&& str = ""); + + bool operator==(const std::string& rhs) const; + bool operator!=(const std::string& rhs) const; + + operator std::string&(); + operator const std::string&() const; + const std::string& get() const; + + tag_string& operator=(const std::string& str); + tag_string& operator=(std::string&& str); + void set(const std::string& str); + void set(std::string&& str); + + tag_type get_type() const noexcept override; + +private: + std::string value; +}; + +} + +#endif // TAG_STRING_H_INCLUDED diff --git a/test/nbttest.cpp b/test/nbttest.cpp index 482e28ab64..24846e84da 100644 --- a/test/nbttest.cpp +++ b/test/nbttest.cpp @@ -49,8 +49,29 @@ void test_tag_primitive() ASSERT(tag_double() == 0.0); } +void test_tag_string() +{ + tag_string tag("foo"); + ASSERT(tag.get() == "foo"); + std::string& ref = tag; + ref = "bar"; + ASSERT(tag == "bar"); + ASSERT(tag != "foo"); + tag.set("baz"); + ASSERT(ref == "baz"); + tag = "quux"; + ASSERT("quux" == static_cast<std::string>(tag)); + std::string str("foo"); + tag = str; + ASSERT(tag == str); + + ASSERT(tag_string(str) == "foo"); + ASSERT(tag_string() == ""); +} + int main() { test_get_type(); test_tag_primitive(); + test_tag_string(); } |
