1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
18 @warning : This file contains Rose Model ID comments - please do not delete
21 #ifndef __THTTPHDRVAL_H__
22 #define __THTTPHDRVAL_H__
26 #include <stringpool.h>
29 //##ModelId=3C4C187E027A
32 A representation of a value found in an HTTP header field. Three
33 fundamental types are used in HTTP - integers, strings (which may
34 be free text, 'enumeration values', URIs, etc. or date/times.
36 The class allows any of the three values to be held and the current
37 value (as well as its type) to be determined.
39 THTTPHdrVal instances are used to assign values to header fields, their
40 parts and their associated parameters.
51 KTIntVal = 0x00, /**< the value is an integer*/
52 KStrVal = 0x01, /**< the value is a case-sensitive string*/
53 KDateVal = 0x02, /**< the value is a date/time*/
54 KStrFVal = 0x03, /**< the value is a case-insensitive string*/
55 KNoType = 0x04 /**< no value has yet been set*/
60 // A converter for 'q' parameter values; apparently real numbers in the HTTP RFC but here passed as fixed point
61 //##ModelId=3B1E66F2024E
65 // Construct from a real number representation of 'q'
66 //##ModelId=3B1E66F20282
69 // Construct from a fixed-point representation of 'q'
70 //##ModelId=3B1E66F2028C
73 // Integer cast operator to get the fixed-point representation
74 //##ModelId=3B1E66F20281
75 operator TInt() const;
77 // TReal cast operator to get the real number representation
78 //##ModelId=3B1E66F20280
79 operator TReal() const;
81 // The real number q-value
82 //##ModelId=3B1E66F2027A
84 // The integer fixed-point q-value representation
85 //##ModelId=3B1E66F2026E
90 /** Default constructor
91 Used when constructing an empty header value that is to be filled in by
92 a call to a function. e.g. RHTTPHeaders::GetField
94 IMPORT_C THTTPHdrVal();
96 /** Constructor for an integer field value
97 @param aIntVal The integer value
99 IMPORT_C THTTPHdrVal(TInt aIntVal);
101 /** Constructor for an string value
102 @param aStrVal The string value
104 IMPORT_C THTTPHdrVal(RStringF aStrVal);
105 /** Constructor for an string value
106 @param aStrVal The string value
108 IMPORT_C THTTPHdrVal(RString aStrVal);
110 /** Constructor for an date/time value
111 @param aDateVal The date/time value
113 IMPORT_C THTTPHdrVal(TDateTime aDateVal);
115 /** Obtain a copy of this header value. This is critical when the header contains a string, since
116 a new string reference must be created
117 @return The copied header value
119 //##ModelId=3C4C187E02F3
120 IMPORT_C THTTPHdrVal Copy() const;
122 /** Determine the type of this header field value
123 @return A THTTPValType enumeration describing the value's type
125 //##ModelId=3C4C187E02F2
126 IMPORT_C THTTPValType Type() const;
128 /** Obtain the (integer) value held within
129 Panics if the value is of the wring type
130 @pre Requires that the object was previously set to hold a TInt
131 @return An integer value
133 //##ModelId=3C4C187E02EA
134 IMPORT_C TInt Int() const;
136 /** Cast operator to obtain the HTTP value as an integer.
137 Note this doesn't convert from a different form to integer!
138 Panics if the value is of the wrong type
139 @pre Requires that the object was previously set to hold a TInt
141 //##ModelId=3C4C187E02E9
142 inline operator TInt() const;
144 /** Obtain the (string) value held within
145 Panics if the value is of the wring type
146 @pre Requires that the object was previously set to hold a string
149 //##ModelId=3C4C187E02E8
150 IMPORT_C RStringF StrF() const;
151 //##ModelId=3C4C187E02E0
152 IMPORT_C RString Str() const;
154 /** Cast operator to obtain the HTTP value as a string.
155 Note this doesn't convert from a different form to string!
156 Panics if the value is of the wring type
157 @pre Requires that the object was previously set to hold a string
159 //##ModelId=3C4C187E02DF
160 inline operator RStringF() const;
161 /** Cast operator to obtain the HTTP value as a string.
162 Note this doesn't convert from a different form to string!
163 Panics if the value is of the wring type
164 @pre Requires that the object was previously set to hold a string
166 //##ModelId=3C4C187E02DE
167 inline operator RString() const;
169 /** Obtain the (date/time) value held within.
170 Panics if the value is of the wrong type
171 @pre Requires that the object was previously set to hold a TDateTime
172 @return An date/time value
174 //##ModelId=3C4C187E02D6
175 IMPORT_C TDateTime DateTime() const;
177 /** Cast operator to obtain the HTTP value as an date/time.
178 Note this doesn't convert from a different form to date!
179 Panics if the value is of the wring type
180 @pre Requires that the object was previously set to hold a TDateTime
182 //##ModelId=3C4C187E02D5
183 inline operator TDateTime() const;
185 /** Set the header value to be the supplied integer.
186 @warning Any previous value, or its type, are lost.
187 @param aIntVal The integer value
189 //##ModelId=3C4C187E02CC
190 IMPORT_C void SetInt(TInt aIntVal);
192 /** Set the header value to be the supplied string.
193 @warning Any previous value, or its type, are lost.
194 @param aStrVal The string value
196 //##ModelId=3C4C187E02CA
197 IMPORT_C void SetStrF(RStringF aStrVal);
198 /** Set the header value to be the supplied string. Any previous
199 value, or its type, are lost.
200 @param aStrVal The string value */
201 //##ModelId=3C4C187E02C2
202 IMPORT_C void SetStr(RString aStrVal);
204 /** Set the header value to be the supplied date/time. Any previous value, or its type, are lost.
205 @param aDateVal The date/time value
207 //##ModelId=3C4C187E02C0
208 IMPORT_C void SetDateTime(TDateTime aDateVal);
210 /** Comparison operator. Does a comparison based on the current type.
211 @param aVal The header value to compare. */
212 //##ModelId=3C4C187E02B8
213 IMPORT_C TBool operator==(THTTPHdrVal aVal) const;
215 /** Comparison operator. Does a comparison based on the current type.
216 @param aVal The string to compare. */
217 //##ModelId=3C4C187E02B6
218 IMPORT_C TBool operator!=(THTTPHdrVal aVal) const;
224 //##ModelId=3C4C187E02AC
230 //##ModelId=3C4C187E02A4
232 //##ModelId=3C4C187E029A
236 inline THTTPHdrVal::TQConv::TQConv(TReal aQ)
237 : iQ(aQ), iFQ((TInt)(iQ*1000))
241 inline THTTPHdrVal::TQConv::TQConv(TInt aFQ)
242 : iQ((TReal)(aFQ/1000.)), iFQ(aFQ)
246 inline THTTPHdrVal::TQConv::operator TInt() const
251 inline THTTPHdrVal::TQConv::operator TReal() const
256 inline THTTPHdrVal::operator TInt() const
261 inline THTTPHdrVal::operator RStringF() const
266 inline THTTPHdrVal::operator RString() const
271 inline THTTPHdrVal::operator TDateTime() const
278 #endif // __THTTPHDRVAL_H__