diff options
| author | ljfa-ag <ljfa-ag@web.de> | 2015-07-15 15:42:23 +0200 |
|---|---|---|
| committer | ljfa-ag <ljfa-ag@web.de> | 2015-07-15 15:44:15 +0200 |
| commit | 0060f816c7798148556ebeb445510a3cc78161f2 (patch) | |
| tree | 77a74f2511e3d88e866a0fd84ffe6d6ebdd02104 | |
| parent | 6ec54ee1766a1819d62771620e91328a188341d2 (diff) | |
| download | Project-Tick-0060f816c7798148556ebeb445510a3cc78161f2.tar.gz Project-Tick-0060f816c7798148556ebeb445510a3cc78161f2.zip | |
Revert "Turn tag_list::of into a subtype of tag_list"
This reverts commit 6ec54ee1766a1819d62771620e91328a188341d2.
| -rw-r--r-- | include/tag_list.h | 35 | ||||
| -rw-r--r-- | test/nbttest.cpp | 10 |
2 files changed, 21 insertions, 24 deletions
diff --git a/include/tag_list.h b/include/tag_list.h index c97aaed66d..94403119dc 100644 --- a/include/tag_list.h +++ b/include/tag_list.h @@ -42,13 +42,17 @@ public: typedef std::vector<value>::iterator iterator; typedef std::vector<value>::const_iterator const_iterator; - template<class T> - class of; - ///The type of the tag static constexpr tag_type type = tag_type::List; /** + * @brief Constructs a list with the given contents of type T + * @param init list of values that are, one by one, given to a constructor of T + */ + template<class T> + static tag_list of(std::initializer_list<T> init); + + /** * @brief Constructs an empty list * * The content type is determined when the first tag is added. @@ -148,7 +152,10 @@ public: friend bool operator==(const tag_list& lhs, const tag_list& rhs); friend bool operator!=(const tag_list& lhs, const tag_list& rhs); -protected: +private: + std::vector<value> tags; + tag_type el_type_; + /** * Internally used initialization function that initializes the list with * tags of type T, with the constructor arguments of each T given by il. @@ -156,25 +163,15 @@ protected: */ template<class T, class Arg> void init(std::initializer_list<Arg> il); - -private: - std::vector<value> tags; - tag_type el_type_; }; -/** - * @brief Subclass of tag_list with compile-time-known element type - * @todo Statically override some of the superclass methods to forgo dynamic type checking - */ template<class T> -class tag_list::of : public tag_list +tag_list tag_list::of(std::initializer_list<T> il) { -public: - of(std::initializer_list<T> il) - { - init<T>(il); - } -}; + tag_list result; + result.init<T, T>(il); + return result; +} template<class T, class... Args> void tag_list::emplace_back(Args&&... args) diff --git a/test/nbttest.cpp b/test/nbttest.cpp index 12e36a5db7..3e043f750b 100644 --- a/test/nbttest.cpp +++ b/test/nbttest.cpp @@ -82,7 +82,7 @@ void test_tag_compound() {"foo", int16_t(12)}, {"bar", "baz"}, {"baz", -2.0}, - {"list", tag_list::of<tag_byte>{16, 17}} + {"list", tag_list::of<tag_byte>({16, 17})} }; ASSERT(comp["foo"].get_type() == tag_type::Short); @@ -120,7 +120,7 @@ void test_tag_compound() {"bar", "barbaz"}, {"baz", -2.0}, {"quux", tag_compound{{"Hello", "World"}, {"zero", 0}}}, - {"list", tag_list::of<tag_byte>{16, 17}} + {"list", tag_list::of<tag_byte>({16, 17})} }; ASSERT(comp == comp2); ASSERT(comp != (const tag_compound&)comp2["quux"]); @@ -249,8 +249,8 @@ void test_tag_list() list.pop_back(); ASSERT(list == tag_list{"foo"}); - ASSERT(list == tag_list::of<tag_string>{"foo"}); - ASSERT(tag_list::of<tag_string>{"foo"} == tag_list{"foo"}); + ASSERT(list == tag_list::of<tag_string>({"foo"})); + ASSERT(tag_list::of<tag_string>({"foo"}) == tag_list{"foo"}); ASSERT((list != tag_list{2, 3, 5, 7})); list.clear(); @@ -261,7 +261,7 @@ void test_tag_list() ASSERT(tag_list() == tag_list(tag_type::Int)); ASSERT(tag_list(tag_type::Short) == tag_list(tag_type::Int)); - tag_list::of<tag_short> short_list{25, 36}; + tag_list short_list = tag_list::of<tag_short>({25, 36}); ASSERT(short_list.el_type() == tag_type::Short); ASSERT((short_list == tag_list{int16_t(25), int16_t(36)})); ASSERT((short_list != tag_list{25, 36})); |
