webm_parser: Convert style to match the rest of libwebm
Remove webm_parser/clang-format-style. Run clang-format -style=file -i for each source file. Change-Id: Ieaf44bd323375cbcfec67014e94b7742d6bda14a
This commit is contained in:
@@ -60,7 +60,7 @@ class Ancestory {
|
||||
// Constructs an Ancestory using the first count elements of ancestory.
|
||||
// ancestory must have static storage duration.
|
||||
template <std::size_t N>
|
||||
Ancestory(const Id (&ancestory)[N], std::size_t count)
|
||||
Ancestory(const Id(&ancestory)[N], std::size_t count)
|
||||
: begin_(ancestory), end_(ancestory + count) {
|
||||
assert(count <= N);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,8 @@ namespace webm {
|
||||
|
||||
std::uint8_t CountLeadingZeros(std::uint8_t value) {
|
||||
// Special case for 0 since we can't shift by sizeof(T) * 8 bytes.
|
||||
if (value == 0) return 8;
|
||||
if (value == 0)
|
||||
return 8;
|
||||
|
||||
std::uint8_t count = 0;
|
||||
while (!(value & (0x80 >> count))) {
|
||||
|
||||
@@ -50,11 +50,13 @@ class BlockHeaderParser : public Parser {
|
||||
int timecode_bytes_remaining_ = 2;
|
||||
|
||||
enum class State {
|
||||
/* clang-format off */
|
||||
// State Transitions to state When
|
||||
kReadingTrackNumber, // kReadingTimecode track parsed
|
||||
kReadingTimecode, // kReadingFlags timecode parsed
|
||||
kReadingFlags, // kDone flags parsed
|
||||
kDone, // No transitions from here (must call Init)
|
||||
/* clang-format on */
|
||||
} state_ = State::kReadingTrackNumber;
|
||||
};
|
||||
|
||||
|
||||
@@ -274,7 +274,8 @@ Status BasicBlockParser<T>::Feed(Callback* callback, Reader* reader,
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> bool BasicBlockParser<T>::WasSkipped() const {
|
||||
template <typename T>
|
||||
bool BasicBlockParser<T>::WasSkipped() const {
|
||||
return state_ == State::kSkipping;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,8 @@ namespace webm {
|
||||
// http://www.webmproject.org/docs/container/#Block
|
||||
// http://matroska.org/technical/specs/index.html#block_structure
|
||||
// http://matroska.org/technical/specs/index.html#simpleblock_structure
|
||||
template <typename T> class BasicBlockParser : public ElementParser {
|
||||
template <typename T>
|
||||
class BasicBlockParser : public ElementParser {
|
||||
static_assert(std::is_same<T, Block>::value ||
|
||||
std::is_same<T, SimpleBlock>::value,
|
||||
"T must be Block or SimpleBlock");
|
||||
@@ -89,6 +90,7 @@ template <typename T> class BasicBlockParser : public ElementParser {
|
||||
|
||||
// Parsing states for the finite-state machine.
|
||||
enum class State {
|
||||
/* clang-format off */
|
||||
// State Transitions to state When
|
||||
kReadingHeader, // kGettingAction no lacing
|
||||
// kReadingLaceCount yes lacing
|
||||
@@ -106,6 +108,7 @@ template <typename T> class BasicBlockParser : public ElementParser {
|
||||
kSkipping, // No transitions from here (must call Init)
|
||||
kReadingFrames, // kDone all frames read
|
||||
kDone, // No transitions from here (must call Init)
|
||||
/* clang-format on */
|
||||
};
|
||||
|
||||
// The current state of the parser.
|
||||
|
||||
@@ -26,7 +26,8 @@ namespace webm {
|
||||
// Spec reference for string/binary elements:
|
||||
// http://matroska.org/technical/specs/index.html#EBML_ex
|
||||
// https://github.com/Matroska-Org/ebml-specification/blob/master/specification.markdown#ebml-element-types
|
||||
template <typename T> class ByteParser : public ElementParser {
|
||||
template <typename T>
|
||||
class ByteParser : public ElementParser {
|
||||
public:
|
||||
static_assert(std::is_same<T, std::vector<std::uint8_t>>::value ||
|
||||
std::is_same<T, std::string>::value,
|
||||
|
||||
@@ -135,7 +135,8 @@ Status Callback::Skip(Reader* reader, std::uint64_t* bytes_remaining) {
|
||||
assert(reader != nullptr);
|
||||
assert(bytes_remaining != nullptr);
|
||||
|
||||
if (*bytes_remaining == 0) return Status(Status::kOkCompleted);
|
||||
if (*bytes_remaining == 0)
|
||||
return Status(Status::kOkCompleted);
|
||||
|
||||
Status status;
|
||||
do {
|
||||
|
||||
@@ -73,9 +73,9 @@ Status FileReader::Skip(std::uint64_t num_to_skip,
|
||||
}
|
||||
|
||||
// Try seeking forward first.
|
||||
long seek_offset = std::numeric_limits<long>::max(); // NOLINT
|
||||
long seek_offset = std::numeric_limits<long>::max(); // NOLINT
|
||||
if (num_to_skip < static_cast<unsigned long>(seek_offset)) { // NOLINT
|
||||
seek_offset = static_cast<long>(num_to_skip); // NOLINT
|
||||
seek_offset = static_cast<long>(num_to_skip); // NOLINT
|
||||
}
|
||||
// TODO(mjbshaw): Use fseeko64/_fseeki64 if available.
|
||||
if (!std::fseek(file_.get(), seek_offset, SEEK_CUR)) {
|
||||
|
||||
@@ -27,7 +27,8 @@ namespace webm {
|
||||
// http://matroska.org/technical/specs/index.html#EBML_ex
|
||||
// https://github.com/Matroska-Org/ebml-specification/blob/master/specification.markdown#element-data-size
|
||||
// https://github.com/Matroska-Org/ebml-specification/blob/master/specification.markdown#ebml-element-types
|
||||
template <typename T> class IntParser : public ElementParser {
|
||||
template <typename T>
|
||||
class IntParser : public ElementParser {
|
||||
public:
|
||||
static_assert(
|
||||
std::is_same<T, std::int64_t>::value ||
|
||||
|
||||
@@ -55,7 +55,8 @@ class MasterParser : public ElementParser {
|
||||
//
|
||||
// Initializer lists don't support move-only types (i.e. std::unique_ptr), so
|
||||
// instead a variadic template is used.
|
||||
template <typename... T> explicit MasterParser(T&&... parser_pairs) {
|
||||
template <typename... T>
|
||||
explicit MasterParser(T&&... parser_pairs) {
|
||||
// Prefer an odd reserve size. This makes libc++ use a prime number for the
|
||||
// bucket count. Otherwise, if it happens to be a power of 2, then libc++
|
||||
// will use a power-of-2 bucket count (and since Matroska EBML IDs have low
|
||||
@@ -127,6 +128,7 @@ class MasterParser : public ElementParser {
|
||||
private:
|
||||
// Parsing states for the finite-state machine.
|
||||
enum class State {
|
||||
/* clang-format off */
|
||||
// State Transitions to state When
|
||||
kFirstReadOfChildId, // kFinishingReadingChildId size(id) > 1
|
||||
// kReadingChildSize size(id) == 1
|
||||
@@ -142,6 +144,7 @@ class MasterParser : public ElementParser {
|
||||
// kFirstReadOfChildId read < my_size_
|
||||
// kEndReached read == my_size_
|
||||
kEndReached, // No transitions from here (must call Init)
|
||||
/* clang-format on */
|
||||
};
|
||||
|
||||
using StdHashId = std::hash<std::underlying_type<Id>::type>;
|
||||
@@ -204,9 +207,10 @@ class MasterParser : public ElementParser {
|
||||
|
||||
// Inserts the parser into the parsers_ map and asserts it is the only parser
|
||||
// registers to parse the corresponding Id.
|
||||
template <typename T> void InsertParser(T&& parser) {
|
||||
template <typename T>
|
||||
void InsertParser(T&& parser) {
|
||||
bool inserted = parsers_.insert(std::forward<T>(parser)).second;
|
||||
(void)inserted; // Silence unused variable warning.
|
||||
(void)inserted; // Silence unused variable warning.
|
||||
assert(inserted); // Make sure there aren't duplicates.
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,8 @@ namespace webm {
|
||||
// : MasterValueParser(MakeChild<BoolParser>(Id::kBar, &Foo::bar),
|
||||
// MakeChild<BoolParser>(Id::kBaz, &Foo::baz)) {}
|
||||
// };
|
||||
template <typename T> class MasterValueParser : public ElementParser {
|
||||
template <typename T>
|
||||
class MasterValueParser : public ElementParser {
|
||||
public:
|
||||
Status Init(const ElementMetadata& metadata,
|
||||
std::uint64_t max_size) override {
|
||||
@@ -179,7 +180,7 @@ template <typename T> class MasterValueParser : public ElementParser {
|
||||
// If called, OnParseStarted will be called on the parent element when this
|
||||
// particular element is encountered.
|
||||
constexpr SingleChildFactory<Parser, Value, TagUseAsStart, Tags...>
|
||||
UseAsStartEvent() const {
|
||||
UseAsStartEvent() const {
|
||||
return {id_, member_};
|
||||
}
|
||||
|
||||
@@ -187,7 +188,7 @@ template <typename T> class MasterValueParser : public ElementParser {
|
||||
// particular element is fully parsed.
|
||||
constexpr SingleChildFactory<Parser, Value, TagNotifyOnParseComplete,
|
||||
Tags...>
|
||||
NotifyOnParseComplete() const {
|
||||
NotifyOnParseComplete() const {
|
||||
return {id_, member_};
|
||||
}
|
||||
|
||||
@@ -226,7 +227,7 @@ template <typename T> class MasterValueParser : public ElementParser {
|
||||
// If called, OnParseStarted will be called on the parent element when this
|
||||
// particular element is encountered.
|
||||
constexpr RepeatedChildFactory<Parser, Value, TagUseAsStart, Tags...>
|
||||
UseAsStartEvent() const {
|
||||
UseAsStartEvent() const {
|
||||
return {id_, member_};
|
||||
}
|
||||
|
||||
@@ -234,7 +235,7 @@ template <typename T> class MasterValueParser : public ElementParser {
|
||||
// particular element is fully parsed.
|
||||
constexpr RepeatedChildFactory<Parser, Value, TagNotifyOnParseComplete,
|
||||
Tags...>
|
||||
NotifyOnParseComplete() const {
|
||||
NotifyOnParseComplete() const {
|
||||
return {id_, member_};
|
||||
}
|
||||
|
||||
@@ -340,10 +341,12 @@ template <typename T> class MasterValueParser : public ElementParser {
|
||||
|
||||
// Helper struct that will be std::true_type if Tag is in Tags, or
|
||||
// std::false_type otherwise.
|
||||
template <typename Tag, typename... Tags> struct HasTag;
|
||||
template <typename Tag, typename... Tags>
|
||||
struct HasTag;
|
||||
|
||||
// Base condition: Tags is empty, so it trivially does not contain Tag.
|
||||
template <typename Tag> struct HasTag<Tag> : std::false_type {};
|
||||
template <typename Tag>
|
||||
struct HasTag<Tag> : std::false_type {};
|
||||
|
||||
// If the head of the Tags list is a different tag, skip it and check the
|
||||
// remaining tags.
|
||||
@@ -409,7 +412,8 @@ template <typename T> class MasterValueParser : public ElementParser {
|
||||
return Status(Status::kOkCompleted);
|
||||
}
|
||||
|
||||
template <typename Tag> constexpr static bool has_tag() {
|
||||
template <typename Tag>
|
||||
constexpr static bool has_tag() {
|
||||
return HasTag<Tag, Tags...>::value;
|
||||
}
|
||||
};
|
||||
@@ -419,7 +423,7 @@ template <typename T> class MasterValueParser : public ElementParser {
|
||||
template <typename Parser, typename Value, typename... Tags, typename F>
|
||||
static typename std::enable_if<!std::is_constructible<Parser, Value>::value,
|
||||
std::unique_ptr<ElementParser>>::type
|
||||
MakeChildParser(MasterValueParser* parent, F consume_element_value, ...) {
|
||||
MakeChildParser(MasterValueParser* parent, F consume_element_value, ...) {
|
||||
return std::unique_ptr<ElementParser>(new ChildParser<Parser, F, Tags...>(
|
||||
parent, std::move(consume_element_value)));
|
||||
}
|
||||
@@ -429,8 +433,8 @@ template <typename T> class MasterValueParser : public ElementParser {
|
||||
template <typename Parser, typename Value, typename... Tags, typename F>
|
||||
static typename std::enable_if<std::is_constructible<Parser, Value>::value,
|
||||
std::unique_ptr<ElementParser>>::type
|
||||
MakeChildParser(MasterValueParser* parent, F consume_element_value,
|
||||
const Element<Value>* default_value) {
|
||||
MakeChildParser(MasterValueParser* parent, F consume_element_value,
|
||||
const Element<Value>* default_value) {
|
||||
return std::unique_ptr<ElementParser>(new ChildParser<Parser, F, Tags...>(
|
||||
parent, std::move(consume_element_value), default_value->value()));
|
||||
}
|
||||
@@ -440,8 +444,8 @@ template <typename T> class MasterValueParser : public ElementParser {
|
||||
template <typename Parser, typename Value, typename... Tags, typename F>
|
||||
static typename std::enable_if<std::is_constructible<Parser, Value>::value,
|
||||
std::unique_ptr<ElementParser>>::type
|
||||
MakeChildParser(MasterValueParser* parent, F consume_element_value,
|
||||
const std::vector<Element<Value>>* member) {
|
||||
MakeChildParser(MasterValueParser* parent, F consume_element_value,
|
||||
const std::vector<Element<Value>>* member) {
|
||||
Value default_value{};
|
||||
if (!member->empty()) {
|
||||
default_value = member->front().value();
|
||||
|
||||
@@ -24,7 +24,8 @@ namespace webm {
|
||||
// parsing operations. The parser is allocated when Init is called. This class
|
||||
// is intended to be used with recursive elements, where a parser needs to
|
||||
// recursively instantiate parsers of the same type.
|
||||
template <typename T> class RecursiveParser : public ElementParser {
|
||||
template <typename T>
|
||||
class RecursiveParser : public ElementParser {
|
||||
public:
|
||||
RecursiveParser() = default;
|
||||
|
||||
|
||||
@@ -55,10 +55,12 @@ class VirtualBlockParser : public ElementParser {
|
||||
BlockHeaderParser parser_;
|
||||
|
||||
enum class State {
|
||||
/* clang-format off */
|
||||
// State Transitions to state When
|
||||
kReadingHeader, // kValidatingSize header parsed
|
||||
kValidatingSize, // kDone no errors
|
||||
kDone, // No transitions from here (must call Init)
|
||||
/* clang-format on */
|
||||
} state_ = State::kReadingHeader;
|
||||
};
|
||||
|
||||
|
||||
@@ -184,6 +184,7 @@ class WebmParser::DocumentParser {
|
||||
private:
|
||||
// Parsing states for the finite-state machine.
|
||||
enum class State {
|
||||
/* clang-format off */
|
||||
// State Transitions to state When
|
||||
kBegin, // kReadingChildId done
|
||||
kReadingChildId, // kReadingChildSize done
|
||||
@@ -195,6 +196,7 @@ class WebmParser::DocumentParser {
|
||||
kReadingChildBody, // kValidatingChildSize cached metadata
|
||||
// kReadingChildId otherwise
|
||||
kEndReached, // No transitions from here
|
||||
/* clang-format on */
|
||||
};
|
||||
|
||||
// The parser for parsing child element Ids.
|
||||
|
||||
Reference in New Issue
Block a user