summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/tag_array.h26
-rw-r--r--include/tag_compound.h10
-rw-r--r--include/tag_list.h16
-rw-r--r--include/tag_string.h18
-rw-r--r--include/value.h18
-rw-r--r--include/value_initializer.h8
6 files changed, 51 insertions, 45 deletions
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);