Nebula
Loading...
Searching...
No Matches
fourcc.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
12#include "core/types.h"
13#include "util/string.h"
14
15//------------------------------------------------------------------------------
16namespace Util
17{
18class FourCC
19{
20public:
22 FourCC();
24 constexpr FourCC(uint f);
26 FourCC(const String& s);
28 bool operator==(const FourCC& rhs) const;
30 bool operator!=(const FourCC& rhs) const;
32 bool operator<(const FourCC& rhs) const;
34 bool operator<=(const FourCC& rhs) const;
36 bool operator>(const FourCC& rhs) const;
38 bool operator>=(const FourCC& rhs) const;
40 bool IsValid() const;
42 void SetFromUInt(uint f);
44 uint AsUInt() const;
46 void SetFromString(const String& s);
48 String AsString() const;
50 static String ToString(const FourCC& f);
52 static FourCC FromString(const String& s);
54 uint32_t HashCode() const;
55
56private:
58};
59
60//------------------------------------------------------------------------------
63inline
65 fourCC(0)
66{
67 // empty
68}
69
70//------------------------------------------------------------------------------
73constexpr
75 fourCC(f)
76{
77 // empty
78}
79
80//------------------------------------------------------------------------------
83inline
85{
86 this->SetFromString(s);
87}
88
89//------------------------------------------------------------------------------
92inline bool
93FourCC::operator==(const FourCC& rhs) const
94{
95 return (this->fourCC == rhs.fourCC);
96}
97
98//------------------------------------------------------------------------------
101inline bool
102FourCC::operator!=(const FourCC& rhs) const
103{
104 return (this->fourCC != rhs.fourCC);
105}
106
107//------------------------------------------------------------------------------
110inline bool
111FourCC::operator>(const FourCC& rhs) const
112{
113 return (this->fourCC > rhs.fourCC);
114}
115
116//------------------------------------------------------------------------------
119inline bool
120FourCC::operator>=(const FourCC& rhs) const
121{
122 return (this->fourCC >= rhs.fourCC);
123}
124
125//------------------------------------------------------------------------------
128inline bool
129FourCC::operator<(const FourCC& rhs) const
130{
131 return (this->fourCC < rhs.fourCC);
132}
133
134//------------------------------------------------------------------------------
137inline bool
138FourCC::operator<=(const FourCC& rhs) const
139{
140 return (this->fourCC <= rhs.fourCC);
141}
142
143//------------------------------------------------------------------------------
146inline bool
148{
149 return (0 != this->fourCC);
150}
151
152//------------------------------------------------------------------------------
155inline void
157{
158 n_assert(0 != f);
159 this->fourCC = f;
160}
161
162//------------------------------------------------------------------------------
165inline uint
167{
168 return this->fourCC;
169}
170
171//------------------------------------------------------------------------------
174inline void
176{
177 *this = FromString(s);
178}
179
180//------------------------------------------------------------------------------
183inline String
185{
186 return ToString(*this);
187}
188
189//------------------------------------------------------------------------------
192inline String
194{
195 n_assert(f.IsValid());
196 String str("xzyw");
197 str[0] = (char) ((f.fourCC & 0xFF000000) >> 24);
198 str[1] = (char) ((f.fourCC & 0x00FF0000) >> 16);
199 str[2] = (char) ((f.fourCC & 0x0000FF00) >> 8);
200 str[3] = (char) (f.fourCC & 0x000000FF);
201 return str;
202}
203
204//------------------------------------------------------------------------------
207inline FourCC
209{
210 n_assert(s.IsValid() && (s.Length() == 4));
211#if (__WIN32__ || __LINUX__ )
212 return FourCC(uint(s[3] | s[2]<<8 | s[1]<<16 | s[0]<<24));
213#else
214 return FourCC(uint(s[0] | s[1]<<8 | s[2]<<16 | s[3]<<24));
215#endif
216}
217
218//------------------------------------------------------------------------------
221inline uint32_t
223{
224 return this->fourCC;
225}
226
227} // namespace Util
228//------------------------------------------------------------------------------
A four-character-code is a quasi-human-readable 32-bit-id.
Definition fourcc.h:19
void SetFromUInt(uint f)
set from 32-bit-value
Definition fourcc.h:156
uint AsUInt() const
get as 32-bit-value
Definition fourcc.h:166
bool operator!=(const FourCC &rhs) const
inequality operator
Definition fourcc.h:102
bool operator==(const FourCC &rhs) const
equality operator
Definition fourcc.h:93
FourCC()
default constructor
Definition fourcc.h:64
bool operator<(const FourCC &rhs) const
less-then operator
Definition fourcc.h:129
uint fourCC
Definition fourcc.h:57
String AsString() const
get as string
Definition fourcc.h:184
bool operator>(const FourCC &rhs) const
greater-then operator
Definition fourcc.h:111
void SetFromString(const String &s)
set as string
Definition fourcc.h:175
static FourCC FromString(const String &s)
convert string to fourcc
Definition fourcc.h:208
static String ToString(const FourCC &f)
convert fourcc to string
Definition fourcc.h:193
bool IsValid() const
return true if valid
Definition fourcc.h:147
bool operator>=(const FourCC &rhs) const
greater-or-equal operator
Definition fourcc.h:120
uint32_t HashCode() const
return a hashcode (just returns the fourcc)
Definition fourcc.h:222
bool operator<=(const FourCC &rhs) const
less-or-equal operator
Definition fourcc.h:138
#define n_assert(exp)
Definition debug.h:50
A pinned array is an array which manages its own virtual memory.
Definition String.cs:6
Nebula's universal string class.
Definition string.h:50
SizeT Length() const
return length of string
Definition string.h:657
bool IsValid() const
return true if string object is not empty
Definition string.h:684
unsigned int uint
Definition types.h:31