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