Inline some methods
This commit is contained in:
parent
71176e1f07
commit
936b2390d8
13 changed files with 52 additions and 268 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,6 +3,7 @@
|
|||
*.layout
|
||||
*.cbtemp
|
||||
*.bak
|
||||
*.swp
|
||||
/bin
|
||||
/lib
|
||||
/obj
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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); }
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -25,28 +25,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)
|
||||
{
|
||||
|
@ -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>&);
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)) {}
|
||||
|
|
Loading…
Reference in a new issue