diff options
| author | ljfa-ag <ljfa-ag@web.de> | 2015-08-23 10:24:00 +0200 |
|---|---|---|
| committer | ljfa-ag <ljfa-ag@web.de> | 2015-08-23 10:24:00 +0200 |
| commit | 936b2390d89f4e20380c060b39a670dc9fae873f (patch) | |
| tree | 01790ff708026df488d243f9fea428f171fff356 | |
| parent | 71176e1f0700d8567d436a9321ca02ad2a553b26 (diff) | |
| download | Project-Tick-936b2390d89f4e20380c060b39a670dc9fae873f.tar.gz Project-Tick-936b2390d89f4e20380c060b39a670dc9fae873f.zip | |
Inline some methods
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | include/tag_array.h | 26 | ||||
| -rw-r--r-- | include/tag_compound.h | 10 | ||||
| -rw-r--r-- | include/tag_list.h | 16 | ||||
| -rw-r--r-- | include/tag_string.h | 18 | ||||
| -rw-r--r-- | include/value.h | 18 | ||||
| -rw-r--r-- | include/value_initializer.h | 8 | ||||
| -rw-r--r-- | src/tag_array.cpp | 74 | ||||
| -rw-r--r-- | src/tag_compound.cpp | 20 | ||||
| -rw-r--r-- | src/tag_list.cpp | 38 | ||||
| -rw-r--r-- | src/tag_string.cpp | 37 | ||||
| -rw-r--r-- | src/value.cpp | 49 | ||||
| -rw-r--r-- | src/value_initializer.cpp | 5 |
13 files changed, 52 insertions, 268 deletions
diff --git a/.gitignore b/.gitignore index 05dee84b0f..b1ef936ea3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.layout *.cbtemp *.bak +*.swp /bin /lib /obj diff --git a/include/tag_array.h b/include/tag_array.h index 14dd4d4480..342d3a4ceb 100644 --- a/include/tag_array.h +++ b/include/tag_array.h @@ -62,12 +62,12 @@ public: tag_array() {} ///Constructs an array with the given values - tag_array(std::initializer_list<T> init); - tag_array(std::vector<T>&& vec) noexcept; + tag_array(std::initializer_list<T> init): data(init) {} + tag_array(std::vector<T>&& vec) noexcept: data(std::move(vec)) {} ///Returns a reference to the vector that contains the values - std::vector<T>& get(); - const std::vector<T>& get() const; + std::vector<T>& get() { return data; } + const std::vector<T>& get() const { return data; } /** * @brief Accesses a value by index with bounds checking @@ -81,20 +81,20 @@ public: * * No bounds checking is performed. */ - T& operator[](size_t i); - T operator[](size_t i) const; + T& operator[](size_t i) { return data[i]; } + T operator[](size_t i) const { return data[i]; } ///Appends a value at the end of the array - void push_back(T val); + void push_back(T val) { data.push_back(val); } ///Removes the last element from the array - void pop_back(); + void pop_back() { data.pop_back(); } ///Returns the number of values in the array - size_t size() const; + size_t size() const { return data.size(); } ///Erases all values from the array. - void clear(); + void clear() { data.clear(); } //Iterators iterator begin(); @@ -115,8 +115,10 @@ private: std::vector<T> data; }; -template<class T> bool operator==(const tag_array<T>& lhs, const tag_array<T>& rhs); -template<class T> bool operator!=(const tag_array<T>& lhs, const tag_array<T>& rhs); +template<class T> bool operator==(const tag_array<T>& lhs, const tag_array<T>& rhs) +{ return lhs.get() == rhs.get(); } +template<class T> bool operator!=(const tag_array<T>& lhs, const tag_array<T>& rhs) +{ return !(lhs == rhs); } //Typedefs that should be used instead of the template tag_array. typedef tag_array<int8_t> tag_byte_array; diff --git a/include/tag_compound.h b/include/tag_compound.h index bcb0a6cec2..2948059ce9 100644 --- a/include/tag_compound.h +++ b/include/tag_compound.h @@ -106,10 +106,10 @@ public: bool has_key(const std::string& key, tag_type type) const; ///Returns the number of tags in the compound - size_t size() const; + size_t size() const { return tags.size(); } ///Erases all tags from the compound - void clear(); + void clear() { tags.clear(); } //Iterators iterator begin(); @@ -122,8 +122,10 @@ public: void read_payload(io::stream_reader& reader) override; void write_payload(io::stream_writer& writer) const override; - friend bool operator==(const tag_compound& lhs, const tag_compound& rhs); - friend bool operator!=(const tag_compound& lhs, const tag_compound& rhs); + friend bool operator==(const tag_compound& lhs, const tag_compound& rhs) + { return lhs.tags == rhs.tags; } + friend bool operator!=(const tag_compound& lhs, const tag_compound& rhs) + { return !(lhs == rhs); } private: map_t_ tags; diff --git a/include/tag_list.h b/include/tag_list.h index 66f63e6ed9..05150323b9 100644 --- a/include/tag_list.h +++ b/include/tag_list.h @@ -66,10 +66,10 @@ public: * * The content type is determined when the first tag is added. */ - tag_list(); + tag_list(): tag_list(tag_type::Null) {} ///Constructs an empty list with the given content type - explicit tag_list(tag_type type); + explicit tag_list(tag_type type): el_type_(type) {} ///Constructs a list with the given contents tag_list(std::initializer_list<int8_t> init); @@ -106,8 +106,8 @@ public: * Returns a value to the tag at the specified index. No bounds checking * is performed. */ - value& operator[](size_t i); - const value& operator[](size_t i) const; + value& operator[](size_t i) { return tags[i]; } + const value& operator[](size_t i) const { return tags[i]; } /** * @brief Assigns a value at the given index @@ -133,16 +133,16 @@ public: void emplace_back(Args&&... args); ///Removes the last element of the list - void pop_back(); + void pop_back() { tags.pop_back(); } ///Returns the content type of the list, or tag_type::Null if undetermined - tag_type el_type() const; + tag_type el_type() const { return el_type_; } ///Returns the number of tags in the list - size_t size() const; + size_t size() const { return tags.size(); } ///Erases all tags from the list. Preserves the content type. - void clear(); + void clear() { tags.clear(); } /** * @brief Erases all tags from the list and changes the content type. diff --git a/include/tag_string.h b/include/tag_string.h index ab084c44aa..48e7adf497 100644 --- a/include/tag_string.h +++ b/include/tag_string.h @@ -35,14 +35,14 @@ public: //Constructors tag_string() {} - tag_string(const std::string& str); - tag_string(std::string&& str) noexcept; - tag_string(const char* str); + tag_string(const std::string& str): value(str) {} + tag_string(std::string&& str) noexcept: value(std::move(str)) {} + tag_string(const char* str): value(str) {} //Getters - operator std::string&(); - operator const std::string&() const; - const std::string& get() const; + operator std::string&() { return value; } + operator const std::string&() const { return value; } + const std::string& get() const { return value; } //Setters tag_string& operator=(const std::string& str); @@ -62,8 +62,10 @@ private: std::string value; }; -bool operator==(const tag_string& lhs, const tag_string& rhs); -bool operator!=(const tag_string& lhs, const tag_string& rhs); +inline bool operator==(const tag_string& lhs, const tag_string& rhs) +{ return lhs.get() == rhs.get(); } +inline bool operator!=(const tag_string& lhs, const tag_string& rhs) +{ return !(lhs == rhs); } } diff --git a/include/value.h b/include/value.h index 4865c8fd1c..c51a862b4d 100644 --- a/include/value.h +++ b/include/value.h @@ -62,7 +62,7 @@ class value public: //Constructors value() noexcept {} - explicit value(std::unique_ptr<tag>&& t) noexcept; + explicit value(std::unique_ptr<tag>&& t) noexcept: tag_(std::move(t)) {} explicit value(tag&& t); //Moving @@ -87,10 +87,10 @@ public: * * If the value is uninitialized, the behavior is undefined. */ - operator tag&(); - operator const tag&() const; - tag& get(); - const tag& get() const; + operator tag&() { return get(); } + operator const tag&() const { return get(); } + tag& get() { return *tag_; } + const tag& get() const { return *tag_; } /** * @brief Returns a reference to the contained tag as an instance of T @@ -143,7 +143,7 @@ public: explicit operator const std::string&() const; ///Returns true if the value is not uninitialized - explicit operator bool() const; + explicit operator bool() const { return tag_ != nullptr; } /** * @brief In case of a tag_compound, accesses a tag by key with bounds checking @@ -189,10 +189,10 @@ public: const value& operator[](size_t i) const; ///Returns a reference to the underlying std::unique_ptr<tag> - std::unique_ptr<tag>& get_ptr(); - const std::unique_ptr<tag>& get_ptr() const; + std::unique_ptr<tag>& get_ptr() { return tag_; } + const std::unique_ptr<tag>& get_ptr() const { return tag_; } ///Resets the underlying std::unique_ptr<tag> to a different value - void set_ptr(std::unique_ptr<tag>&& t); + void set_ptr(std::unique_ptr<tag>&& t) { tag_ = std::move(t); } ///@sa tag::get_type tag_type get_type() const; diff --git a/include/value_initializer.h b/include/value_initializer.h index 843ee16885..4ec0215740 100644 --- a/include/value_initializer.h +++ b/include/value_initializer.h @@ -44,10 +44,10 @@ namespace nbt class value_initializer : public value { public: - value_initializer(std::unique_ptr<tag>&& t) noexcept; - value_initializer(std::nullptr_t) noexcept; - value_initializer(value&& val) noexcept; - value_initializer(tag&& t); + value_initializer(std::unique_ptr<tag>&& t) noexcept: value(std::move(t)) {} + value_initializer(std::nullptr_t) noexcept : value(nullptr) {} + value_initializer(value&& val) noexcept : value(std::move(val)) {} + value_initializer(tag&& t) : value(std::move(t)) {} value_initializer(int8_t val); value_initializer(int16_t val); diff --git a/src/tag_array.cpp b/src/tag_array.cpp index 41f00eedc3..6c12b9a2cd 100644 --- a/src/tag_array.cpp +++ b/src/tag_array.cpp @@ -26,28 +26,6 @@ namespace nbt { template<class T> -tag_array<T>::tag_array(std::initializer_list<T> init): - data(init) -{} - -template<class T> -tag_array<T>::tag_array(std::vector<T>&& vec) noexcept: - data(std::move(vec)) -{} - -template<class T> -std::vector<T>& tag_array<T>::get() -{ - return data; -} - -template<class T> -const std::vector<T>& tag_array<T>::get() const -{ - return data; -} - -template<class T> T& tag_array<T>::at(size_t i) { return data.at(i); @@ -59,42 +37,6 @@ T tag_array<T>::at(size_t i) const return data.at(i); } -template<class T> -T& tag_array<T>::operator[](size_t i) -{ - return data[i]; -} - -template<class T> -T tag_array<T>::operator[](size_t i) const -{ - return data[i]; -} - -template<class T> -void tag_array<T>::push_back(T val) -{ - data.push_back(val); -} - -template<class T> -void tag_array<T>::pop_back() -{ - data.pop_back(); -} - -template<class T> -size_t tag_array<T>::size() const -{ - return data.size(); -} - -template<class T> -void tag_array<T>::clear() -{ - data.clear(); -} - template<class T> auto tag_array<T>::begin() -> iterator { return data.begin(); } template<class T> auto tag_array<T>::end() -> iterator { return data.end(); } template<class T> auto tag_array<T>::begin() const -> const_iterator { return data.begin(); } @@ -168,24 +110,8 @@ void tag_array<int32_t>::write_payload(io::stream_writer& writer) const writer.write_num(i); } -template<class T> -bool operator==(const tag_array<T>& lhs, const tag_array<T>& rhs) -{ - return lhs.get() == rhs.get(); -} - -template<class T> -bool operator!=(const tag_array<T>& lhs, const tag_array<T>& rhs) -{ - return !(lhs == rhs); -} - //Enforce template instantiations template class tag_array<int8_t>; template class tag_array<int32_t>; -template bool operator==<int8_t> (const tag_array<int8_t>& , const tag_array<int8_t>&); -template bool operator==<int32_t>(const tag_array<int32_t>&, const tag_array<int32_t>&); -template bool operator!=<int8_t> (const tag_array<int8_t>& , const tag_array<int8_t>&); -template bool operator!=<int32_t>(const tag_array<int32_t>&, const tag_array<int32_t>&); } diff --git a/src/tag_compound.cpp b/src/tag_compound.cpp index d0f20512ae..746a07955e 100644 --- a/src/tag_compound.cpp +++ b/src/tag_compound.cpp @@ -82,16 +82,6 @@ bool tag_compound::has_key(const std::string& key, tag_type type) const return it != tags.end() && it->second.get_type() == type; } -size_t tag_compound::size() const -{ - return tags.size(); -} - -void tag_compound::clear() -{ - tags.clear(); -} - auto tag_compound::begin() -> iterator { return tags.begin(); } auto tag_compound::end() -> iterator { return tags.end(); } auto tag_compound::begin() const -> const_iterator { return tags.begin(); } @@ -128,14 +118,4 @@ void tag_compound::write_payload(io::stream_writer& writer) const writer.write_type(tag_type::End); } -bool operator==(const tag_compound& lhs, const tag_compound& rhs) -{ - return lhs.tags == rhs.tags; -} - -bool operator!=(const tag_compound& lhs, const tag_compound& rhs) -{ - return !(lhs == rhs); -} - } diff --git a/src/tag_list.cpp b/src/tag_list.cpp index d2aa01d314..0e7dda4ae6 100644 --- a/src/tag_list.cpp +++ b/src/tag_list.cpp @@ -26,14 +26,6 @@ namespace nbt { -tag_list::tag_list(): - tag_list(tag_type::Null) -{} - -tag_list::tag_list(tag_type type): - el_type_(type) -{} - tag_list::tag_list(std::initializer_list<int8_t> il) { init<tag_byte>(il); } tag_list::tag_list(std::initializer_list<int16_t> il) { init<tag_short>(il); } tag_list::tag_list(std::initializer_list<int32_t> il) { init<tag_int>(il); } @@ -72,16 +64,6 @@ const value& tag_list::at(size_t i) const return tags.at(i); } -value& tag_list::operator[](size_t i) -{ - return tags[i]; -} - -const value& tag_list::operator[](size_t i) const -{ - return tags[i]; -} - void tag_list::set(size_t i, value&& val) { if(val.get_type() != el_type_) @@ -100,26 +82,6 @@ void tag_list::push_back(value_initializer&& val) tags.push_back(std::move(val)); } -void tag_list::pop_back() -{ - tags.pop_back(); -} - -tag_type tag_list::el_type() const -{ - return el_type_; -} - -size_t tag_list::size() const -{ - return tags.size(); -} - -void tag_list::clear() -{ - tags.clear(); -} - void tag_list::reset(tag_type type) { clear(); diff --git a/src/tag_string.cpp b/src/tag_string.cpp index 1a8f1cd5d2..2d04c25fdc 100644 --- a/src/tag_string.cpp +++ b/src/tag_string.cpp @@ -24,33 +24,6 @@ namespace nbt { -tag_string::tag_string(const std::string& str): - value(str) -{} - -tag_string::tag_string(std::string&& str) noexcept: - value(std::move(str)) -{} - -tag_string::tag_string(const char* str): - value(str) -{} - -tag_string::operator std::string&() -{ - return value; -} - -tag_string::operator const std::string&() const -{ - return value; - -} -const std::string& tag_string::get() const -{ - return value; -} - tag_string& tag_string::operator=(const std::string& str) { value = str; @@ -96,14 +69,4 @@ void tag_string::write_payload(io::stream_writer& writer) const writer.write_string(value); } -bool operator==(const tag_string& lhs, const tag_string& rhs) -{ - return lhs.get() == rhs.get(); -} - -bool operator!=(const tag_string& lhs, const tag_string& rhs) -{ - return !(lhs == rhs); -} - } diff --git a/src/value.cpp b/src/value.cpp index 4b3fa47678..8376dc9b9e 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -24,10 +24,6 @@ namespace nbt { -value::value(std::unique_ptr<tag>&& t) noexcept: - tag_(std::move(t)) -{} - value::value(tag&& t): tag_(std::move(t).move_clone()) {} @@ -59,26 +55,6 @@ void value::set(tag&& t) tag_ = std::move(t).move_clone(); } -value::operator tag&() -{ - return get(); -} - -value::operator const tag&() const -{ - return get(); -} - -tag& value::get() -{ - return *tag_; -} - -const tag& value::get() const -{ - return *tag_; -} - //Primitive assignment //FIXME: Make this less copypaste! value& value::operator=(int8_t val) @@ -325,11 +301,6 @@ value::operator double() const } } -value& value::operator=(const std::string& str) -{ - return *this = std::move(std::string(str)); -} - value& value::operator=(std::string&& str) { if(!tag_) @@ -344,11 +315,6 @@ value::operator const std::string&() const return dynamic_cast<tag_string&>(*tag_).get(); } -value::operator bool() const -{ - return tag_ != nullptr; -} - value& value::at(const std::string& key) { return dynamic_cast<tag_compound&>(*tag_).at(key); @@ -389,21 +355,6 @@ const value& value::operator[](size_t i) const return dynamic_cast<const tag_list&>(*tag_)[i]; } -std::unique_ptr<tag>& value::get_ptr() -{ - return tag_; -} - -const std::unique_ptr<tag>& value::get_ptr() const -{ - return tag_; -} - -void value::set_ptr(std::unique_ptr<tag>&& t) -{ - tag_ = std::move(t); -} - tag_type value::get_type() const { return tag_ ? tag_->get_type() : tag_type::Null; diff --git a/src/value_initializer.cpp b/src/value_initializer.cpp index 0431bfaef2..3735bfdf09 100644 --- a/src/value_initializer.cpp +++ b/src/value_initializer.cpp @@ -23,11 +23,6 @@ namespace nbt { -value_initializer::value_initializer(std::unique_ptr<tag>&& t) noexcept: value(std::move(t)) {} -value_initializer::value_initializer(std::nullptr_t) noexcept: value(nullptr) {} -value_initializer::value_initializer(value&& val) noexcept : value(std::move(val)) {} -value_initializer::value_initializer(tag&& t) : value(std::move(t)) {} - value_initializer::value_initializer(int8_t val) : value(tag_byte(val)) {} value_initializer::value_initializer(int16_t val) : value(tag_short(val)) {} value_initializer::value_initializer(int32_t val) : value(tag_int(val)) {} |
