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