Merge "vp8_rd_pick_best_mbsegmentation code restructure"
[libvpx.git] / vp8 / common / fourcc.hpp
blobc5826285ead527caea4ae041a6549f899be65bf0
1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
12 #ifndef FOURCC_HPP
13 #define FOURCC_HPP
15 #include <iosfwd>
16 #include <cstring>
19 #if defined(__POWERPC__) || defined(__APPLE__) || defined(__MERKS__)
20 using namespace std;
21 #endif
23 class four_cc
25 public:
27 four_cc();
28 four_cc(const char*);
29 explicit four_cc(unsigned long);
31 bool operator==(const four_cc&) const;
32 bool operator!=(const four_cc&) const;
34 bool operator==(const char*) const;
35 bool operator!=(const char*) const;
37 operator unsigned long() const;
38 unsigned long as_long() const;
40 four_cc& operator=(unsigned long);
42 char operator[](int) const;
44 std::ostream& put(std::ostream&) const;
46 bool printable() const;
48 private:
50 union
52 char code[4];
53 unsigned long code_as_long;
59 inline four_cc::four_cc()
63 inline four_cc::four_cc(unsigned long x)
64 : code_as_long(x)
68 inline four_cc::four_cc(const char* str)
70 memcpy(code, str, 4);
74 inline bool four_cc::operator==(const four_cc& rhs) const
76 return code_as_long == rhs.code_as_long;
79 inline bool four_cc::operator!=(const four_cc& rhs) const
81 return !operator==(rhs);
84 inline bool four_cc::operator==(const char* rhs) const
86 return (memcmp(code, rhs, 4) == 0);
89 inline bool four_cc::operator!=(const char* rhs) const
91 return !operator==(rhs);
95 inline four_cc::operator unsigned long() const
97 return code_as_long;
100 inline unsigned long four_cc::as_long() const
102 return code_as_long;
105 inline char four_cc::operator[](int i) const
107 return code[i];
110 inline four_cc& four_cc::operator=(unsigned long val)
112 code_as_long = val;
113 return *this;
116 inline std::ostream& operator<<(std::ostream& os, const four_cc& rhs)
118 return rhs.put(os);
121 #endif