williamr@2
|
1 |
// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
|
williamr@2
|
2 |
// All rights reserved.
|
williamr@2
|
3 |
// This component and the accompanying materials are made available
|
williamr@2
|
4 |
// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
|
williamr@2
|
5 |
// which accompanies this distribution, and is available
|
williamr@2
|
6 |
// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
|
williamr@2
|
7 |
//
|
williamr@2
|
8 |
// Initial Contributors:
|
williamr@2
|
9 |
// Nokia Corporation - initial contribution.
|
williamr@2
|
10 |
//
|
williamr@2
|
11 |
// Contributors:
|
williamr@2
|
12 |
//
|
williamr@2
|
13 |
// Description:
|
williamr@2
|
14 |
//
|
williamr@2
|
15 |
|
williamr@2
|
16 |
|
williamr@2
|
17 |
|
williamr@2
|
18 |
/**
|
williamr@2
|
19 |
@file THTTPHdrVal.h
|
williamr@2
|
20 |
@warning : This file contains Rose Model ID comments - please do not delete
|
williamr@2
|
21 |
*/
|
williamr@2
|
22 |
|
williamr@2
|
23 |
#ifndef __THTTPHDRVAL_H__
|
williamr@2
|
24 |
#define __THTTPHDRVAL_H__
|
williamr@2
|
25 |
|
williamr@2
|
26 |
// System includes
|
williamr@2
|
27 |
#include <e32std.h>
|
williamr@2
|
28 |
#include <stringpool.h>
|
williamr@2
|
29 |
|
williamr@2
|
30 |
|
williamr@2
|
31 |
//##ModelId=3C4C187E027A
|
williamr@2
|
32 |
class THTTPHdrVal
|
williamr@2
|
33 |
/**
|
williamr@2
|
34 |
A representation of a value found in an HTTP header field. Three
|
williamr@2
|
35 |
fundamental types are used in HTTP - integers, strings (which may
|
williamr@2
|
36 |
be free text, 'enumeration values', URIs, etc. or date/times.
|
williamr@2
|
37 |
|
williamr@2
|
38 |
The class allows any of the three values to be held and the current
|
williamr@2
|
39 |
value (as well as its type) to be determined.
|
williamr@2
|
40 |
|
williamr@2
|
41 |
THTTPHdrVal instances are used to assign values to header fields, their
|
williamr@2
|
42 |
parts and their associated parameters.
|
williamr@2
|
43 |
@publishedAll
|
williamr@2
|
44 |
@released
|
williamr@2
|
45 |
@see RHTTPHeaders
|
williamr@2
|
46 |
*/
|
williamr@2
|
47 |
{
|
williamr@2
|
48 |
public:
|
williamr@2
|
49 |
/**
|
williamr@2
|
50 |
@enum THTTPValType
|
williamr@2
|
51 |
*/
|
williamr@2
|
52 |
typedef enum {
|
williamr@2
|
53 |
KTIntVal = 0x00, /**< the value is an integer*/
|
williamr@2
|
54 |
KStrVal = 0x01, /**< the value is a case-sensitive string*/
|
williamr@2
|
55 |
KDateVal = 0x02, /**< the value is a date/time*/
|
williamr@2
|
56 |
KStrFVal = 0x03, /**< the value is a case-insensitive string*/
|
williamr@2
|
57 |
KNoType = 0x04 /**< no value has yet been set*/
|
williamr@2
|
58 |
} THTTPValType;
|
williamr@2
|
59 |
|
williamr@2
|
60 |
public: // classes
|
williamr@2
|
61 |
|
williamr@2
|
62 |
// A converter for 'q' parameter values; apparently real numbers in the HTTP RFC but here passed as fixed point
|
williamr@2
|
63 |
//##ModelId=3B1E66F2024E
|
williamr@2
|
64 |
class TQConv
|
williamr@2
|
65 |
{
|
williamr@2
|
66 |
public:
|
williamr@2
|
67 |
/// Construct from a real number representation of 'q'
|
williamr@2
|
68 |
//##ModelId=3B1E66F20282
|
williamr@2
|
69 |
TQConv(TReal aQ);
|
williamr@2
|
70 |
|
williamr@2
|
71 |
/// Construct from a fixed-point representation of 'q'
|
williamr@2
|
72 |
//##ModelId=3B1E66F2028C
|
williamr@2
|
73 |
TQConv(TInt aQ);
|
williamr@2
|
74 |
|
williamr@2
|
75 |
/// Integer cast operator to get the fixed-point representation
|
williamr@2
|
76 |
//##ModelId=3B1E66F20281
|
williamr@2
|
77 |
operator TInt() const;
|
williamr@2
|
78 |
|
williamr@2
|
79 |
/// TReal cast operator to get the real number representation
|
williamr@2
|
80 |
//##ModelId=3B1E66F20280
|
williamr@2
|
81 |
operator TReal() const;
|
williamr@2
|
82 |
private:
|
williamr@2
|
83 |
/// The real number q-value
|
williamr@2
|
84 |
//##ModelId=3B1E66F2027A
|
williamr@2
|
85 |
TReal iQ;
|
williamr@2
|
86 |
/// The integer fixed-point q-value representation
|
williamr@2
|
87 |
//##ModelId=3B1E66F2026E
|
williamr@2
|
88 |
TInt iFQ;
|
williamr@2
|
89 |
};
|
williamr@2
|
90 |
|
williamr@2
|
91 |
public:
|
williamr@2
|
92 |
/** Default constructor
|
williamr@2
|
93 |
Used when constructing an empty header value that is to be filled in by
|
williamr@2
|
94 |
a call to a function. e.g. RHTTPHeaders::GetField
|
williamr@2
|
95 |
*/
|
williamr@2
|
96 |
IMPORT_C THTTPHdrVal();
|
williamr@2
|
97 |
|
williamr@2
|
98 |
/** Constructor for an integer field value
|
williamr@2
|
99 |
@param aIntVal The integer value
|
williamr@2
|
100 |
*/
|
williamr@2
|
101 |
IMPORT_C THTTPHdrVal(TInt aIntVal);
|
williamr@2
|
102 |
|
williamr@2
|
103 |
/** Constructor for an string value
|
williamr@2
|
104 |
@param aStrVal The string value
|
williamr@2
|
105 |
*/
|
williamr@2
|
106 |
IMPORT_C THTTPHdrVal(RStringF aStrVal);
|
williamr@2
|
107 |
/** Constructor for an string value
|
williamr@2
|
108 |
@param aStrVal The string value
|
williamr@2
|
109 |
*/
|
williamr@2
|
110 |
IMPORT_C THTTPHdrVal(RString aStrVal);
|
williamr@2
|
111 |
|
williamr@2
|
112 |
/** Constructor for an date/time value
|
williamr@2
|
113 |
@param aDateVal The date/time value
|
williamr@2
|
114 |
*/
|
williamr@2
|
115 |
IMPORT_C THTTPHdrVal(TDateTime aDateVal);
|
williamr@2
|
116 |
|
williamr@2
|
117 |
/** Obtain a copy of this header value. This is critical when the header contains a string, since
|
williamr@2
|
118 |
a new string reference must be created
|
williamr@2
|
119 |
@return The copied header value
|
williamr@2
|
120 |
*/
|
williamr@2
|
121 |
//##ModelId=3C4C187E02F3
|
williamr@2
|
122 |
IMPORT_C THTTPHdrVal Copy() const;
|
williamr@2
|
123 |
|
williamr@2
|
124 |
/** Determine the type of this header field value
|
williamr@2
|
125 |
@return A THTTPValType enumeration describing the value's type
|
williamr@2
|
126 |
*/
|
williamr@2
|
127 |
//##ModelId=3C4C187E02F2
|
williamr@2
|
128 |
IMPORT_C THTTPValType Type() const;
|
williamr@2
|
129 |
|
williamr@2
|
130 |
/** Obtain the (integer) value held within
|
williamr@2
|
131 |
Panics if the value is of the wring type
|
williamr@2
|
132 |
@pre Requires that the object was previously set to hold a TInt
|
williamr@2
|
133 |
@return An integer value
|
williamr@2
|
134 |
*/
|
williamr@2
|
135 |
//##ModelId=3C4C187E02EA
|
williamr@2
|
136 |
IMPORT_C TInt Int() const;
|
williamr@2
|
137 |
|
williamr@2
|
138 |
/** Cast operator to obtain the HTTP value as an integer.
|
williamr@2
|
139 |
Note this doesn't convert from a different form to integer!
|
williamr@2
|
140 |
Panics if the value is of the wrong type
|
williamr@2
|
141 |
@pre Requires that the object was previously set to hold a TInt
|
williamr@2
|
142 |
*/
|
williamr@2
|
143 |
//##ModelId=3C4C187E02E9
|
williamr@2
|
144 |
inline operator TInt() const;
|
williamr@2
|
145 |
|
williamr@2
|
146 |
/** Obtain the (string) value held within
|
williamr@2
|
147 |
Panics if the value is of the wring type
|
williamr@2
|
148 |
@pre Requires that the object was previously set to hold a string
|
williamr@2
|
149 |
@return A string
|
williamr@2
|
150 |
*/
|
williamr@2
|
151 |
//##ModelId=3C4C187E02E8
|
williamr@2
|
152 |
IMPORT_C RStringF StrF() const;
|
williamr@2
|
153 |
//##ModelId=3C4C187E02E0
|
williamr@2
|
154 |
IMPORT_C RString Str() const;
|
williamr@2
|
155 |
|
williamr@2
|
156 |
/** Cast operator to obtain the HTTP value as a string.
|
williamr@2
|
157 |
Note this doesn't convert from a different form to string!
|
williamr@2
|
158 |
Panics if the value is of the wring type
|
williamr@2
|
159 |
@pre Requires that the object was previously set to hold a string
|
williamr@2
|
160 |
*/
|
williamr@2
|
161 |
//##ModelId=3C4C187E02DF
|
williamr@2
|
162 |
inline operator RStringF() const;
|
williamr@2
|
163 |
/** Cast operator to obtain the HTTP value as a string.
|
williamr@2
|
164 |
Note this doesn't convert from a different form to string!
|
williamr@2
|
165 |
Panics if the value is of the wring type
|
williamr@2
|
166 |
@pre Requires that the object was previously set to hold a string
|
williamr@2
|
167 |
*/
|
williamr@2
|
168 |
//##ModelId=3C4C187E02DE
|
williamr@2
|
169 |
inline operator RString() const;
|
williamr@2
|
170 |
|
williamr@2
|
171 |
/** Obtain the (date/time) value held within.
|
williamr@2
|
172 |
Panics if the value is of the wrong type
|
williamr@2
|
173 |
@pre Requires that the object was previously set to hold a TDateTime
|
williamr@2
|
174 |
@return An date/time value
|
williamr@2
|
175 |
*/
|
williamr@2
|
176 |
//##ModelId=3C4C187E02D6
|
williamr@2
|
177 |
IMPORT_C TDateTime DateTime() const;
|
williamr@2
|
178 |
|
williamr@2
|
179 |
/** Cast operator to obtain the HTTP value as an date/time.
|
williamr@2
|
180 |
Note this doesn't convert from a different form to date!
|
williamr@2
|
181 |
Panics if the value is of the wring type
|
williamr@2
|
182 |
@pre Requires that the object was previously set to hold a TDateTime
|
williamr@2
|
183 |
*/
|
williamr@2
|
184 |
//##ModelId=3C4C187E02D5
|
williamr@2
|
185 |
inline operator TDateTime() const;
|
williamr@2
|
186 |
|
williamr@2
|
187 |
/** Set the header value to be the supplied integer.
|
williamr@2
|
188 |
@warning Any previous value, or its type, are lost.
|
williamr@2
|
189 |
@param aIntVal The integer value
|
williamr@2
|
190 |
*/
|
williamr@2
|
191 |
//##ModelId=3C4C187E02CC
|
williamr@2
|
192 |
IMPORT_C void SetInt(TInt aIntVal);
|
williamr@2
|
193 |
|
williamr@2
|
194 |
/** Set the header value to be the supplied string.
|
williamr@2
|
195 |
@warning Any previous value, or its type, are lost.
|
williamr@2
|
196 |
@param aStrVal The string value
|
williamr@2
|
197 |
*/
|
williamr@2
|
198 |
//##ModelId=3C4C187E02CA
|
williamr@2
|
199 |
IMPORT_C void SetStrF(RStringF aStrVal);
|
williamr@2
|
200 |
/** Set the header value to be the supplied string. Any previous
|
williamr@2
|
201 |
value, or its type, are lost.
|
williamr@2
|
202 |
@param aStrVal The string value */
|
williamr@2
|
203 |
//##ModelId=3C4C187E02C2
|
williamr@2
|
204 |
IMPORT_C void SetStr(RString aStrVal);
|
williamr@2
|
205 |
|
williamr@2
|
206 |
/** Set the header value to be the supplied date/time. Any previous value, or its type, are lost.
|
williamr@2
|
207 |
@param aDateVal The date/time value
|
williamr@2
|
208 |
*/
|
williamr@2
|
209 |
//##ModelId=3C4C187E02C0
|
williamr@2
|
210 |
IMPORT_C void SetDateTime(TDateTime aDateVal);
|
williamr@2
|
211 |
|
williamr@2
|
212 |
/** Comparison operator. Does a comparison based on the current type.
|
williamr@2
|
213 |
@param aVal The header value to compare. */
|
williamr@2
|
214 |
//##ModelId=3C4C187E02B8
|
williamr@2
|
215 |
IMPORT_C TBool operator==(THTTPHdrVal aVal) const;
|
williamr@2
|
216 |
|
williamr@2
|
217 |
/** Comparison operator. Does a comparison based on the current type.
|
williamr@2
|
218 |
@param aVal The string to compare. */
|
williamr@2
|
219 |
//##ModelId=3C4C187E02B6
|
williamr@2
|
220 |
IMPORT_C TBool operator!=(THTTPHdrVal aVal) const;
|
williamr@2
|
221 |
|
williamr@2
|
222 |
private:
|
williamr@2
|
223 |
/**
|
williamr@2
|
224 |
The current type
|
williamr@2
|
225 |
*/
|
williamr@2
|
226 |
//##ModelId=3C4C187E02AC
|
williamr@2
|
227 |
THTTPValType iType;
|
williamr@2
|
228 |
|
williamr@2
|
229 |
/**
|
williamr@2
|
230 |
The value
|
williamr@2
|
231 |
*/
|
williamr@2
|
232 |
//##ModelId=3C4C187E02A4
|
williamr@2
|
233 |
TInt iVal;
|
williamr@2
|
234 |
//##ModelId=3C4C187E029A
|
williamr@2
|
235 |
TInt iMoreSpace;
|
williamr@2
|
236 |
};
|
williamr@2
|
237 |
|
williamr@2
|
238 |
inline THTTPHdrVal::TQConv::TQConv(TReal aQ)
|
williamr@2
|
239 |
: iQ(aQ), iFQ((TInt)(iQ*1000))
|
williamr@2
|
240 |
{
|
williamr@2
|
241 |
}
|
williamr@2
|
242 |
|
williamr@2
|
243 |
inline THTTPHdrVal::TQConv::TQConv(TInt aFQ)
|
williamr@2
|
244 |
: iQ((TReal)(aFQ/1000.)), iFQ(aFQ)
|
williamr@2
|
245 |
{
|
williamr@2
|
246 |
}
|
williamr@2
|
247 |
|
williamr@2
|
248 |
inline THTTPHdrVal::TQConv::operator TInt() const
|
williamr@2
|
249 |
{
|
williamr@2
|
250 |
return iFQ;
|
williamr@2
|
251 |
}
|
williamr@2
|
252 |
|
williamr@2
|
253 |
inline THTTPHdrVal::TQConv::operator TReal() const
|
williamr@2
|
254 |
{
|
williamr@2
|
255 |
return iQ;
|
williamr@2
|
256 |
}
|
williamr@2
|
257 |
|
williamr@2
|
258 |
inline THTTPHdrVal::operator TInt() const
|
williamr@2
|
259 |
{
|
williamr@2
|
260 |
return Int();
|
williamr@2
|
261 |
}
|
williamr@2
|
262 |
|
williamr@2
|
263 |
inline THTTPHdrVal::operator RStringF() const
|
williamr@2
|
264 |
{
|
williamr@2
|
265 |
return StrF();
|
williamr@2
|
266 |
}
|
williamr@2
|
267 |
|
williamr@2
|
268 |
inline THTTPHdrVal::operator RString() const
|
williamr@2
|
269 |
{
|
williamr@2
|
270 |
return Str();
|
williamr@2
|
271 |
}
|
williamr@2
|
272 |
|
williamr@2
|
273 |
inline THTTPHdrVal::operator TDateTime() const
|
williamr@2
|
274 |
{
|
williamr@2
|
275 |
return DateTime();
|
williamr@2
|
276 |
}
|
williamr@2
|
277 |
|
williamr@2
|
278 |
|
williamr@2
|
279 |
|
williamr@2
|
280 |
#endif // __THTTPHDRVAL_H__
|