Base Framework
Public Types | Public Member Functions | List of all members
MimeType Class Reference

Internet Media Type. More...

#include <base/net/MimeType.h>

Inherits Object.

Public Types

enum  MediaType {
  APPLICATION, AUDIO, IMAGE, MESSAGE,
  MULTIPART, TEXT, VIDEO, EXTENSION,
  UNINITIALIZED
}
 

Public Member Functions

 MimeType ()
 
 MimeType (const String &type, const String &subtype) noexcept
 
 MimeType (MediaType mediaType, const String &subtype)
 
 MimeType (const String &value)
 
MimeTypeoperator= (const MimeType &assign) noexcept
 
bool isValid () const noexcept
 
bool operator== (const MimeType &value) const noexcept
 
bool operator!= (const MimeType &value) const noexcept
 
const StringgetType () const noexcept
 
const StringgetSubtype () const noexcept
 
MediaType getMediaType () const noexcept
 
bool matches (MediaType mediaType, const String &subtype) const noexcept
 

Detailed Description

Internet Media Type.

Multipurpose Internet Mail Extensions (MIME) (see RFC 2046).

Version
1.0

Member Enumeration Documentation

◆ MediaType

Top-level media types.

Enumerator
APPLICATION 

Application type.

AUDIO 

Audio type.

IMAGE 

Image type.

MESSAGE 

Message type.

MULTIPART 

Multipart type.

TEXT 

Text type.

VIDEO 

Video type.

EXTENSION 

Unspecified type.

UNINITIALIZED 

Used internally.

Constructor & Destructor Documentation

◆ MimeType() [1/4]

MimeType::MimeType ( )

Initializes the mime type as "application/octet-stream".

◆ MimeType() [2/4]

MimeType::MimeType ( const String type,
const String subtype 
)
noexcept

Initializes the mime object with specified values. Use the isValid() method to validate against grammar.

Parameters
typeThe type of the mime object (e.g. image).
subtypeThe subtype of the mime object (e.g. jpeg).

◆ MimeType() [3/4]

MimeType::MimeType ( MediaType  mediaType,
const String subtype 
)

Initializes the mime object with specified values. Use the isValid() method to validate against grammar. The media type must be APPLICATION, AUDIO, IMAGE, MESSAGE, MULTIPART, TEXT, or VIDEO. OutOfDomain is raised for all other values.

Parameters
mediaTypeThe media type of the mime object (e.g. VIDEO).
subtypeThe subtype of the mime object (e.g. mpeg).

◆ MimeType() [4/4]

MimeType::MimeType ( const String value)

Initializes the mime object with specified values. Only raises InvalidFormat is '/' is missing. Use the isValid() method to validate against grammar.

Parameters
valueThe string representation of the mime object (e.g. "text/html").

Member Function Documentation

◆ getMediaType()

MediaType MimeType::getMediaType ( ) const
noexcept

Returns the top-level type.

Returns
EXTENSION if the media type is unknown.

◆ getSubtype()

const String& MimeType::getSubtype ( ) const
inlinenoexcept

Returns the subtype.

◆ getType()

const String& MimeType::getType ( ) const
inlinenoexcept

Returns the type.

◆ isValid()

bool MimeType::isValid ( ) const
noexcept

Returns true if the type and subtype complies with the grammar described in RFC 2045.

◆ matches()

bool MimeType::matches ( MediaType  mediaType,
const String subtype 
) const
noexcept

Returns true if the media type and subtype matches.

Returns
Always false if specified type is EXTENSION.

◆ operator!=()

bool MimeType::operator!= ( const MimeType value) const
inlinenoexcept

Returns false if the objects are different.

◆ operator=()

MimeType& MimeType::operator= ( const MimeType assign)
noexcept

Assignment of MIME type to MIME type.

◆ operator==()

bool MimeType::operator== ( const MimeType value) const
noexcept

Returns true if the objects are equal.