Nebula
Loading...
Searching...
No Matches
mediatype.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
13#include "util/string.h"
14
15//------------------------------------------------------------------------------
16namespace IO
17{
19{
20public:
22 MediaType();
24 MediaType(const Util::String& str);
28 MediaType(const MediaType& rhs);
29
31 void operator=(const MediaType& rhs);
33 bool operator==(const MediaType& rhs);
35 bool operator!=(const MediaType& rhs);
36
38 bool IsValid() const;
40 void Clear();
42 void Set(const Util::String& str);
44 void Set(const Util::String& type, const Util::String& subType);
46 Util::String AsString() const;
48 const Util::String& GetType() const;
50 const Util::String& GetSubType() const;
51
52private:
55};
56
57//------------------------------------------------------------------------------
60inline
62{
63 // empty
64}
65
66//------------------------------------------------------------------------------
69inline
70void
72{
73 n_assert(str.IsValid());
74 Util::Array<Util::String> tokens = str.Tokenize("/");
75 n_assert(tokens.Size() == 2);
76 this->type = tokens[0];
77 this->subType = tokens[1];
78}
79
80//------------------------------------------------------------------------------
83inline
85{
86 this->Set(str);
87}
88
89//------------------------------------------------------------------------------
92inline
94 type(t),
95 subType(s)
96{
97 n_assert(this->type.IsValid());
98 n_assert(this->subType.IsValid());
99}
100
101//------------------------------------------------------------------------------
104inline
106 type(rhs.type),
107 subType(rhs.subType)
108{
109 // empty
110}
111
112//------------------------------------------------------------------------------
115inline
116void
118{
119 this->type = rhs.type;
120 this->subType = rhs.subType;
121}
122
123//------------------------------------------------------------------------------
126inline bool
128{
129 return ((this->type == rhs.type) && (this->subType == rhs.subType));
130}
131
132//------------------------------------------------------------------------------
135inline bool
137{
138 return !(*this == rhs);
139}
140
141//------------------------------------------------------------------------------
144inline void
146{
147 n_assert(t.IsValid() && s.IsValid());
148 this->type = t;
149 this->subType = s;
150}
151
152//------------------------------------------------------------------------------
155inline Util::String
157{
158 Util::String str;
159 str.Reserve(128);
160 str = this->type;
161 str.Append("/");
162 str.Append(this->subType);
163 return str;
164}
165
166//------------------------------------------------------------------------------
169inline const Util::String&
171{
172 return this->type;
173}
174
175//------------------------------------------------------------------------------
178inline const Util::String&
180{
181 return this->subType;
182}
183
184//------------------------------------------------------------------------------
187inline bool
189{
190 return this->type.IsValid() && this->subType.IsValid();
191}
192
193//------------------------------------------------------------------------------
196inline void
198{
199 this->type.Clear();
200 this->subType.Clear();
201}
202
203} // namespace IO
204//------------------------------------------------------------------------------
Encapsulates a MIME conformant media type description (text/plain, image/jpg, etc....
Definition mediatype.h:19
const Util::String & GetType() const
get type
Definition mediatype.h:170
bool operator==(const MediaType &rhs)
equality operator
Definition mediatype.h:127
bool IsValid() const
return true if not empty
Definition mediatype.h:188
Util::String type
Definition mediatype.h:53
bool operator!=(const MediaType &rhs)
inequality operator
Definition mediatype.h:136
void Clear()
clear the media type object
Definition mediatype.h:197
MediaType()
constructor
Definition mediatype.h:61
Util::String AsString() const
return as string
Definition mediatype.h:156
const Util::String & GetSubType() const
get subtype
Definition mediatype.h:179
void Set(const Util::String &str)
set as string (must be of the form "xxx/yyy")
Definition mediatype.h:71
void operator=(const MediaType &rhs)
assignment operator
Definition mediatype.h:117
Util::String subType
Definition mediatype.h:54
Nebula's dynamic array class.
Definition array.h:60
const SizeT Size() const
get number of elements in array
Definition array.h:880
#define n_assert(exp)
Definition debug.h:50
Instances of wrapped stream classes.
Definition orientation.cc:10
Nebula's universal string class.
Definition string.h:50
void Clear()
clear the string
Definition string.h:664
bool IsValid() const
return true if string object is not empty
Definition string.h:682
void Append(const String &str)
append string
Definition string.h:615
SizeT Tokenize(const String &whiteSpace, Array< String > &outTokens) const
tokenize string into a provided String array (faster if tokens array can be reused)
Definition string.cc:203
void Reserve(SizeT newSize)
reserve internal buffer size to prevent heap allocs
Definition string.cc:1336