Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
InternetMediaType.inl
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4
6
7 /*
8 ********************************************************************************
9 ******************************** InternetMediaType *****************************
10 ********************************************************************************
11 */
12 inline InternetMediaType::InternetMediaType (AtomType type, AtomType subType, optional<AtomType> suffix,
13 const Containers::Mapping<String, String>& parameters)
14 : fType_{type}
15 , fSubType_{subType}
16 , fSuffix_{suffix}
17 , fParameters_{String::EqualsComparer{Characters::eCaseInsensitive}, parameters}
18 {
19 // Require (type.empty () == subType.empty ()); before 3.0d12
20 Require (subType.empty () or not type.empty ()); // if subtype provided, a type must be provided
21 Require (not type.empty () or parameters.empty ()); // dont specify params without type
22 Require (not type.empty () or suffix == nullopt); // dont specify suffix without type
23 }
24 inline InternetMediaType::InternetMediaType (AtomType type, AtomType subType, const Containers::Mapping<String, String>& parameters)
25 : InternetMediaType{type, subType, nullopt, parameters}
26 {
27 }
28 inline InternetMediaType::InternetMediaType (const String& type, const String& subType, const Containers::Mapping<String, String>& parameters)
29 : InternetMediaType{static_cast<AtomType> (type), static_cast<AtomType> (subType), parameters}
30 {
31 }
32 inline InternetMediaType::InternetMediaType (const String& type, const String& subType, const optional<String>& suffix,
33 const Containers::Mapping<String, String>& parameters)
34 : InternetMediaType{static_cast<AtomType> (type), static_cast<AtomType> (subType),
35 suffix == nullopt ? nullopt : optional<AtomType>{static_cast<AtomType> (*suffix)}, parameters}
36 {
37 Require (suffix == nullopt or not suffix->empty ());
38 Require (suffix == nullopt or not suffix->StartsWith ('+'));
39 Require (suffix == nullopt or not suffix->StartsWith ('.'));
40 }
41 inline bool InternetMediaType::empty () const
42 {
43 // Assert (fType_.empty () == fSubType_.empty ()); before 3.0d12
44 Assert (not fType_.empty () or fSubType_.empty ()); // if subtype provided, a type must be provided
45 Assert (not fType_.empty () or fParameters_.empty ()); // dont specify params without type
46 Assert (not fType_.empty () or fSuffix_ == nullopt); // dont specify suffix without type
47 return fType_.empty ();
48 }
49 inline void InternetMediaType::clear ()
50 {
51 fType_.clear ();
52 fSubType_.clear ();
53 fSuffix_ = nullopt;
54 fParameters_.clear ();
55 }
56 template <>
57 inline auto InternetMediaType::GetType () const -> AtomType
58 {
59 return fType_;
60 }
61 template <>
62 inline auto InternetMediaType::GetType () const -> String
63 {
64 return fType_.GetPrintName ();
65 }
66 template <>
67 inline auto InternetMediaType::GetSubType () const -> AtomType
68 {
69 return fSubType_;
70 }
71 template <>
72 inline auto InternetMediaType::GetSubType () const -> String
73 {
74 return fSubType_.GetPrintName ();
75 }
76 template <>
77 inline auto InternetMediaType::GetSuffix () const -> optional<AtomType>
78 {
79 return fSuffix_;
80 }
81 template <>
82 inline auto InternetMediaType::GetSuffix () const -> optional<String>
83 {
84 return fSuffix_ ? optional<String>{fSuffix_->GetPrintName ()} : nullopt;
85 }
86 inline Containers::Mapping<String, String> InternetMediaType::GetParameters () const
87 {
88 return fParameters_;
89 }
90 template <>
91 inline wstring InternetMediaType::As () const
92 {
93 return As<String> ().As<wstring> ();
94 }
95 inline strong_ordering InternetMediaType::operator<=> (const InternetMediaType& rhs) const
96 {
97 return THREEWAYCOMPARE_ (rhs);
98 }
99 inline bool InternetMediaType::operator== (const InternetMediaType& rhs) const
100 {
101 return THREEWAYCOMPARE_ (rhs) == 0;
102 }
103
104}