#ifndef INCLUDE_WEBM_ELEMENT_H_
#define INCLUDE_WEBM_ELEMENT_H_
#include <cstdint>
#include <limits>
#include <utility>
#include "./id.h"
namespace webm {
template <typename T>
class Element {
public:
constexpr Element() = default;
explicit constexpr Element(const T& value) : value_(value) {}
explicit constexpr Element(T&& value) : value_(std::move(value)) {}
constexpr Element(const T& value, bool is_present)
: value_(value), is_present_(is_present) {}
constexpr Element(T&& value, bool is_present)
: value_(std::move(value)), is_present_(is_present) {}
constexpr Element(const Element<T>& other) = default;
constexpr Element(Element<T>&& other) = default;
~Element() = default;
Element<T>& operator=(const Element<T>& other) = default;
Element<T>& operator=(Element<T>&& other) = default;
void Set(const T& value, bool is_present) {
value_ = value;
is_present_ = is_present;
}
void Set(T&& value, bool is_present) {
value_ = std::move(value);
is_present_ = is_present;
}
constexpr const T& value() const { return value_; }
T* mutable_value() { return &value_; }
constexpr bool is_present() const { return is_present_; }
bool operator==(const Element<T>& other) const {
return is_present_ == other.is_present_ && value_ == other.value_;
}
private:
T value_{};
bool is_present_ = false;
};
struct ElementMetadata {
Id id;
std::uint32_t header_size;
std::uint64_t size;
std::uint64_t position;
bool operator==(const ElementMetadata& other) const {
return id == other.id && header_size == other.header_size &&
size == other.size && position == other.position;
}
};
constexpr std::uint64_t kUnknownHeaderSize =
std::numeric_limits<std::uint32_t>::max();
constexpr std::uint64_t kUnknownElementSize =
std::numeric_limits<std::uint64_t>::max();
constexpr std::uint64_t kUnknownElementPosition =
std::numeric_limits<std::uint64_t>::max();
}
#endif