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.
     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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file
    18  @warning : This file contains Rose Model ID comments - please do not delete
    19 */
    20 
    21 #ifndef	__THTTPHDRVAL_H__
    22 #define	__THTTPHDRVAL_H__
    23 
    24 // System includes
    25 #include <e32std.h>
    26 #include <stringpool.h>
    27 
    28 
    29 //##ModelId=3C4C187E027A
    30 class THTTPHdrVal
    31 /** 
    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.
    35 
    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.
    38 
    39 THTTPHdrVal instances are used to assign values to header fields, their
    40 parts and their associated parameters.
    41 @publishedAll
    42 @released
    43 @see RHTTPHeaders
    44 */
    45 	{
    46 public:
    47 	/**
    48 		@enum THTTPValType
    49 	 */
    50 	typedef enum {
    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*/
    56 	} THTTPValType;
    57 
    58 public: // classes
    59 
    60 	// A converter for 'q' parameter values; apparently real numbers in the HTTP RFC but here passed as fixed point
    61 //##ModelId=3B1E66F2024E
    62 	class TQConv
    63 		{
    64 	public:
    65 		// Construct from a real number representation of 'q'
    66 	//##ModelId=3B1E66F20282
    67 		TQConv(TReal aQ);
    68 
    69 		// Construct from a fixed-point representation of 'q'
    70 	//##ModelId=3B1E66F2028C
    71 		TQConv(TInt aQ);
    72 
    73 		// Integer cast operator to get the fixed-point representation
    74 	//##ModelId=3B1E66F20281
    75 		operator TInt() const;
    76 
    77 		// TReal cast operator to get the real number representation
    78 	//##ModelId=3B1E66F20280
    79 		operator TReal() const;
    80 	private:
    81 		// The real number q-value
    82 	//##ModelId=3B1E66F2027A
    83 		TReal iQ;
    84 		// The integer fixed-point q-value representation
    85 	//##ModelId=3B1E66F2026E
    86 		TInt iFQ;
    87 		};
    88 
    89 public:
    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
    93 	*/
    94 	IMPORT_C THTTPHdrVal();
    95 
    96 	/** Constructor for an integer field value
    97 		@param aIntVal The integer value
    98 	*/
    99 	IMPORT_C THTTPHdrVal(TInt aIntVal);
   100 
   101 	/** Constructor for an string value
   102 		@param aStrVal The string value
   103 	*/
   104 	IMPORT_C THTTPHdrVal(RStringF aStrVal);
   105 	/** Constructor for an string value
   106 		@param aStrVal The string value
   107 	*/
   108 	IMPORT_C THTTPHdrVal(RString aStrVal);
   109 
   110 	/** Constructor for an date/time value
   111 		@param aDateVal The date/time value
   112 	*/
   113 	IMPORT_C THTTPHdrVal(TDateTime aDateVal);
   114 
   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
   118 	*/
   119 	//##ModelId=3C4C187E02F3
   120 	IMPORT_C THTTPHdrVal Copy() const;
   121 
   122 	/** Determine the type of this header field value
   123 		@return A THTTPValType enumeration describing the value's type
   124 	*/
   125 	//##ModelId=3C4C187E02F2
   126 	IMPORT_C THTTPValType Type() const;
   127 
   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
   132 	*/
   133 	//##ModelId=3C4C187E02EA
   134 	IMPORT_C TInt Int() const;
   135 
   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
   140 	*/
   141 	//##ModelId=3C4C187E02E9
   142 	inline operator TInt() const;
   143 
   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
   147 		@return A string
   148 	*/
   149 	//##ModelId=3C4C187E02E8
   150 	IMPORT_C RStringF StrF() const;
   151 	//##ModelId=3C4C187E02E0
   152 	IMPORT_C RString Str() const;
   153 
   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
   158 	*/
   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
   165 	*/
   166 	//##ModelId=3C4C187E02DE
   167 	inline operator RString() const;
   168 
   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
   173 	*/
   174 	//##ModelId=3C4C187E02D6
   175 	IMPORT_C TDateTime DateTime() const;
   176 
   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
   181 	*/
   182 	//##ModelId=3C4C187E02D5
   183 	inline operator TDateTime() const;
   184 
   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
   188 	*/
   189 	//##ModelId=3C4C187E02CC
   190 	IMPORT_C void SetInt(TInt aIntVal);
   191 
   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
   195 	*/
   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);
   203 
   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
   206 	*/
   207 	//##ModelId=3C4C187E02C0
   208 	IMPORT_C void SetDateTime(TDateTime aDateVal);
   209 
   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;
   214 
   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;
   219 
   220 private:
   221 	/** 
   222 		The current type
   223 	*/
   224 	//##ModelId=3C4C187E02AC
   225 	THTTPValType iType;
   226 
   227 	/** 
   228 		The value 
   229 	*/
   230 	//##ModelId=3C4C187E02A4
   231 	TInt iVal;
   232 	//##ModelId=3C4C187E029A
   233 	TInt iMoreSpace;
   234 	};
   235 
   236 inline THTTPHdrVal::TQConv::TQConv(TReal aQ)
   237 	: iQ(aQ), iFQ((TInt)(iQ*1000))
   238 	{
   239 	}
   240 
   241 inline THTTPHdrVal::TQConv::TQConv(TInt aFQ)
   242 	: iQ((TReal)(aFQ/1000.)), iFQ(aFQ)
   243 	{
   244 	}
   245 
   246 inline THTTPHdrVal::TQConv::operator TInt() const
   247 	{
   248 	return iFQ;
   249 	}
   250 
   251 inline THTTPHdrVal::TQConv::operator TReal() const
   252 	{
   253 	return iQ;
   254 	}
   255 
   256 inline THTTPHdrVal::operator TInt() const
   257 	{
   258 	return Int();
   259 	}
   260 
   261 inline THTTPHdrVal::operator RStringF() const
   262 	{
   263 	return StrF();
   264 	}
   265 
   266 inline THTTPHdrVal::operator RString() const
   267 	{
   268 	return Str();
   269 	}
   270 
   271 inline THTTPHdrVal::operator TDateTime() const
   272 	{
   273 	return DateTime();
   274 	}
   275 
   276 
   277 
   278 #endif // __THTTPHDRVAL_H__