Nebula
Toggle main menu visibility
Loading...
Searching...
No Matches
mediatype.h
Go to the documentation of this file.
1
#pragma once
2
//------------------------------------------------------------------------------
13
#include "
util/string.h
"
14
15
//------------------------------------------------------------------------------
16
namespace
IO
17
{
18
class
MediaType
19
{
20
public
:
22
MediaType
();
24
MediaType
(
const
Util::String
& str);
26
MediaType
(
const
Util::String
&
type
,
const
Util::String
&
subType
);
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
52
private
:
53
Util::String
type
;
54
Util::String
subType
;
55
};
56
57
//------------------------------------------------------------------------------
60
inline
61
MediaType::MediaType
()
62
{
63
// empty
64
}
65
66
//------------------------------------------------------------------------------
69
inline
70
void
71
MediaType::Set
(
const
Util::String
& str)
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
//------------------------------------------------------------------------------
83
inline
84
MediaType::MediaType
(
const
Util::String
& str)
85
{
86
this->
Set
(str);
87
}
88
89
//------------------------------------------------------------------------------
92
inline
93
MediaType::MediaType
(
const
Util::String
& t,
const
Util::String
& s) :
94
type
(t),
95
subType
(s)
96
{
97
n_assert
(this->
type
.IsValid());
98
n_assert
(this->
subType
.IsValid());
99
}
100
101
//------------------------------------------------------------------------------
104
inline
105
MediaType::MediaType
(
const
MediaType
& rhs) :
106
type
(rhs.
type
),
107
subType
(rhs.
subType
)
108
{
109
// empty
110
}
111
112
//------------------------------------------------------------------------------
115
inline
116
void
117
MediaType::operator=
(
const
MediaType
& rhs)
118
{
119
this->
type
= rhs.
type
;
120
this->
subType
= rhs.
subType
;
121
}
122
123
//------------------------------------------------------------------------------
126
inline
bool
127
MediaType::operator==
(
const
MediaType
& rhs)
128
{
129
return
((this->
type
== rhs.
type
) && (this->subType == rhs.
subType
));
130
}
131
132
//------------------------------------------------------------------------------
135
inline
bool
136
MediaType::operator!=
(
const
MediaType
& rhs)
137
{
138
return
!(*
this
== rhs);
139
}
140
141
//------------------------------------------------------------------------------
144
inline
void
145
MediaType::Set
(
const
Util::String
& t,
const
Util::String
& s)
146
{
147
n_assert
(t.
IsValid
() && s.
IsValid
());
148
this->
type
= t;
149
this->
subType
= s;
150
}
151
152
//------------------------------------------------------------------------------
155
inline
Util::String
156
MediaType::AsString
()
const
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
//------------------------------------------------------------------------------
169
inline
const
Util::String
&
170
MediaType::GetType
()
const
171
{
172
return
this->
type
;
173
}
174
175
//------------------------------------------------------------------------------
178
inline
const
Util::String
&
179
MediaType::GetSubType
()
const
180
{
181
return
this->
subType
;
182
}
183
184
//------------------------------------------------------------------------------
187
inline
bool
188
MediaType::IsValid
()
const
189
{
190
return
this->
type
.IsValid() && this->
subType
.IsValid();
191
}
192
193
//------------------------------------------------------------------------------
196
inline
void
197
MediaType::Clear
()
198
{
199
this->
type
.Clear();
200
this->
subType
.Clear();
201
}
202
203
}
// namespace IO
204
//------------------------------------------------------------------------------
IO::MediaType::GetType
const Util::String & GetType() const
get type
Definition
mediatype.h:170
IO::MediaType::operator==
bool operator==(const MediaType &rhs)
equality operator
Definition
mediatype.h:127
IO::MediaType::IsValid
bool IsValid() const
return true if not empty
Definition
mediatype.h:188
IO::MediaType::type
Util::String type
Definition
mediatype.h:53
IO::MediaType::operator!=
bool operator!=(const MediaType &rhs)
inequality operator
Definition
mediatype.h:136
IO::MediaType::Clear
void Clear()
clear the media type object
Definition
mediatype.h:197
IO::MediaType::MediaType
MediaType()
constructor
Definition
mediatype.h:61
IO::MediaType::AsString
Util::String AsString() const
return as string
Definition
mediatype.h:156
IO::MediaType::GetSubType
const Util::String & GetSubType() const
get subtype
Definition
mediatype.h:179
IO::MediaType::Set
void Set(const Util::String &str)
set as string (must be of the form "xxx/yyy")
Definition
mediatype.h:71
IO::MediaType::operator=
void operator=(const MediaType &rhs)
assignment operator
Definition
mediatype.h:117
IO::MediaType::subType
Util::String subType
Definition
mediatype.h:54
Util::Array
Nebula's dynamic array class.
Definition
array.h:61
Util::Array::Size
const SizeT Size() const
get number of elements in array
Definition
array.h:913
n_assert
#define n_assert(exp)
Definition
debug.h:50
IO
Instances of wrapped stream classes.
Definition
multiplayerfeatureunit.cc:324
string.h
Util.String
Nebula's universal string class.
Definition
String.cs:8
Util.String::Reserve
void Reserve(SizeT newSize)
reserve internal buffer size to prevent heap allocs
Definition
string.cc:1435
Util.String::IsValid
bool IsValid() const
return true if string object is not empty
Definition
string.h:714
Util.String::Append
void Append(const String &str)
append string
Definition
string.h:647
Util.String::Tokenize
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:193
code
foundation
io
mediatype.h
Generated on
for Nebula. Dark theme by
Tilen Majerle
. All rights reserved.