1
0

FourCC.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef FOURCC_HPP
  2. #define FOURCC_HPP
  3. #include <iosfwd>
  4. #include <cstring>
  5. #if defined(__POWERPC__) || defined(__APPLE__) || defined(__MERKS__)
  6. using namespace std;
  7. #endif
  8. class FourCC
  9. {
  10. public:
  11. FourCC();
  12. FourCC(const char*);
  13. explicit FourCC(unsigned long);
  14. bool operator==(const FourCC&) const;
  15. bool operator!=(const FourCC&) const;
  16. bool operator==(const char*) const;
  17. bool operator!=(const char*) const;
  18. operator unsigned long() const;
  19. unsigned long asLong() const;
  20. FourCC& operator=(unsigned long);
  21. char operator[](int) const;
  22. std::ostream& put(std::ostream&) const;
  23. bool printable() const;
  24. private:
  25. union
  26. {
  27. char code[4];
  28. unsigned long codeAsLong;
  29. };
  30. };
  31. inline FourCC::FourCC()
  32. {
  33. }
  34. inline FourCC::FourCC(unsigned long x)
  35. : codeAsLong(x)
  36. {
  37. }
  38. inline FourCC::FourCC(const char* str)
  39. {
  40. memcpy(code, str, 4);
  41. }
  42. inline bool FourCC::operator==(const FourCC& rhs) const
  43. {
  44. return codeAsLong == rhs.codeAsLong;
  45. }
  46. inline bool FourCC::operator!=(const FourCC& rhs) const
  47. {
  48. return !operator==(rhs);
  49. }
  50. inline bool FourCC::operator==(const char* rhs) const
  51. {
  52. return (memcmp(code, rhs, 4) == 0);
  53. }
  54. inline bool FourCC::operator!=(const char* rhs) const
  55. {
  56. return !operator==(rhs);
  57. }
  58. inline FourCC::operator unsigned long() const
  59. {
  60. return codeAsLong;
  61. }
  62. inline unsigned long FourCC::asLong() const
  63. {
  64. return codeAsLong;
  65. }
  66. inline char FourCC::operator[](int i) const
  67. {
  68. return code[i];
  69. }
  70. inline FourCC& FourCC::operator=(unsigned long val)
  71. {
  72. codeAsLong = val;
  73. return *this;
  74. }
  75. inline std::ostream& operator<<(std::ostream& os, const FourCC& rhs)
  76. {
  77. return rhs.put(os);
  78. }
  79. #endif