From 9d27f798aa91873e0020d6920789e9a927c5d2cf Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sat, 26 May 2012 18:02:57 +1000 Subject: [PATCH] Add forgotten implementation for fourcc It was pulled from types.hpp recently. --- fourcc.cpp | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ fourcc.hpp | 38 +++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 fourcc.cpp create mode 100644 fourcc.hpp diff --git a/fourcc.cpp b/fourcc.cpp new file mode 100644 index 00000000..485a8182 --- /dev/null +++ b/fourcc.cpp @@ -0,0 +1,71 @@ +/* + * This file is part of libgim. + * + * libgim is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * libgim is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with libgim. If not, see . + * + * Copyright 2011 Danny Robson + */ + +#include "fourcc.hpp" + + +fourcc +fourcc::from_chars (uint8_t a, uint8_t b, uint8_t c, uint8_t d) { + fourcc lhs; + + lhs.data[0] = a; + lhs.data[1] = b; + lhs.data[2] = c; + lhs.data[3] = d; + + return lhs; +} + + +fourcc +fourcc::from_str (const char data[4]) { + fourcc lhs; + + lhs.data[0] = (uint8_t)data[0]; + lhs.data[1] = (uint8_t)data[1]; + lhs.data[2] = (uint8_t)data[2]; + lhs.data[3] = (uint8_t)data[3]; + + return lhs; +} + + +bool +fourcc::operator== (const char rhs[4]) const { + return data[0] == rhs[0] && + data[1] == rhs[1] && + data[2] == rhs[2] && + data[3] == rhs[3]; +} + + +fourcc::operator uint32_t (void) const { + return (uint32_t)(data[0] << 24U | + data[1] << 16U | + data[2] << 8U | + data[3]); +} + + +ostream& +operator<< (ostream &os, fourcc f) { + os << f.data[0] << f.data[1] << f.data[2] << f.data[3]; + return os; +} + diff --git a/fourcc.hpp b/fourcc.hpp new file mode 100644 index 00000000..ed8eef1b --- /dev/null +++ b/fourcc.hpp @@ -0,0 +1,38 @@ +/* + * This file is part of libgim. + * + * libgim is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * libgim is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with libgim. If not, see . + * + * Copyright 2011 Danny Robson + */ + +#ifndef __UTIL_FOURCC_HPP +#define __UTIL_FOURCC_HPP + +#include +#include + +struct fourcc { + uint8_t data[4]; + + static fourcc from_str(const char[4]); + static fourcc from_chars(uint8_t, uint8_t, uint8_t, uint8_t); + + bool operator== (const char[4]) const; + operator uint32_t (void) const; +}; + +std::ostream& operator<< (std::ostream&, fourcc); + +#endif