williamr@2: // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: // All rights reserved. williamr@2: // This component and the accompanying materials are made available williamr@4: // under the terms of "Eclipse Public License v1.0" williamr@2: // which accompanies this distribution, and is available williamr@4: // at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@2: // williamr@2: // Initial Contributors: williamr@2: // Nokia Corporation - initial contribution. williamr@2: // williamr@2: // Contributors: williamr@2: // williamr@2: // Description: williamr@2: // williamr@2: williamr@2: /** williamr@4: @file williamr@2: @warning : This file contains Rose Model ID comments - please do not delete williamr@2: */ williamr@2: williamr@2: #ifndef __THTTPHDRVAL_H__ williamr@2: #define __THTTPHDRVAL_H__ williamr@2: williamr@2: // System includes williamr@2: #include williamr@2: #include williamr@2: williamr@2: williamr@2: //##ModelId=3C4C187E027A williamr@2: class THTTPHdrVal williamr@2: /** williamr@2: A representation of a value found in an HTTP header field. Three williamr@2: fundamental types are used in HTTP - integers, strings (which may williamr@2: be free text, 'enumeration values', URIs, etc. or date/times. williamr@2: williamr@2: The class allows any of the three values to be held and the current williamr@2: value (as well as its type) to be determined. williamr@2: williamr@2: THTTPHdrVal instances are used to assign values to header fields, their williamr@2: parts and their associated parameters. williamr@2: @publishedAll williamr@2: @released williamr@2: @see RHTTPHeaders williamr@2: */ williamr@2: { williamr@2: public: williamr@2: /** williamr@2: @enum THTTPValType williamr@2: */ williamr@2: typedef enum { williamr@2: KTIntVal = 0x00, /**< the value is an integer*/ williamr@2: KStrVal = 0x01, /**< the value is a case-sensitive string*/ williamr@2: KDateVal = 0x02, /**< the value is a date/time*/ williamr@2: KStrFVal = 0x03, /**< the value is a case-insensitive string*/ williamr@2: KNoType = 0x04 /**< no value has yet been set*/ williamr@2: } THTTPValType; williamr@2: williamr@2: public: // classes williamr@2: williamr@2: // A converter for 'q' parameter values; apparently real numbers in the HTTP RFC but here passed as fixed point williamr@2: //##ModelId=3B1E66F2024E williamr@2: class TQConv williamr@2: { williamr@2: public: williamr@4: // Construct from a real number representation of 'q' williamr@2: //##ModelId=3B1E66F20282 williamr@2: TQConv(TReal aQ); williamr@2: williamr@4: // Construct from a fixed-point representation of 'q' williamr@2: //##ModelId=3B1E66F2028C williamr@2: TQConv(TInt aQ); williamr@2: williamr@4: // Integer cast operator to get the fixed-point representation williamr@2: //##ModelId=3B1E66F20281 williamr@2: operator TInt() const; williamr@2: williamr@4: // TReal cast operator to get the real number representation williamr@2: //##ModelId=3B1E66F20280 williamr@2: operator TReal() const; williamr@2: private: williamr@4: // The real number q-value williamr@2: //##ModelId=3B1E66F2027A williamr@2: TReal iQ; williamr@4: // The integer fixed-point q-value representation williamr@2: //##ModelId=3B1E66F2026E williamr@2: TInt iFQ; williamr@2: }; williamr@2: williamr@2: public: williamr@2: /** Default constructor williamr@2: Used when constructing an empty header value that is to be filled in by williamr@2: a call to a function. e.g. RHTTPHeaders::GetField williamr@2: */ williamr@2: IMPORT_C THTTPHdrVal(); williamr@2: williamr@2: /** Constructor for an integer field value williamr@2: @param aIntVal The integer value williamr@2: */ williamr@2: IMPORT_C THTTPHdrVal(TInt aIntVal); williamr@2: williamr@2: /** Constructor for an string value williamr@2: @param aStrVal The string value williamr@2: */ williamr@2: IMPORT_C THTTPHdrVal(RStringF aStrVal); williamr@2: /** Constructor for an string value williamr@2: @param aStrVal The string value williamr@2: */ williamr@2: IMPORT_C THTTPHdrVal(RString aStrVal); williamr@2: williamr@2: /** Constructor for an date/time value williamr@2: @param aDateVal The date/time value williamr@2: */ williamr@2: IMPORT_C THTTPHdrVal(TDateTime aDateVal); williamr@2: williamr@2: /** Obtain a copy of this header value. This is critical when the header contains a string, since williamr@2: a new string reference must be created williamr@2: @return The copied header value williamr@2: */ williamr@2: //##ModelId=3C4C187E02F3 williamr@2: IMPORT_C THTTPHdrVal Copy() const; williamr@2: williamr@2: /** Determine the type of this header field value williamr@2: @return A THTTPValType enumeration describing the value's type williamr@2: */ williamr@2: //##ModelId=3C4C187E02F2 williamr@2: IMPORT_C THTTPValType Type() const; williamr@2: williamr@2: /** Obtain the (integer) value held within williamr@2: Panics if the value is of the wring type williamr@2: @pre Requires that the object was previously set to hold a TInt williamr@2: @return An integer value williamr@2: */ williamr@2: //##ModelId=3C4C187E02EA williamr@2: IMPORT_C TInt Int() const; williamr@2: williamr@2: /** Cast operator to obtain the HTTP value as an integer. williamr@2: Note this doesn't convert from a different form to integer! williamr@2: Panics if the value is of the wrong type williamr@2: @pre Requires that the object was previously set to hold a TInt williamr@2: */ williamr@2: //##ModelId=3C4C187E02E9 williamr@2: inline operator TInt() const; williamr@2: williamr@2: /** Obtain the (string) value held within williamr@2: Panics if the value is of the wring type williamr@2: @pre Requires that the object was previously set to hold a string williamr@2: @return A string williamr@2: */ williamr@2: //##ModelId=3C4C187E02E8 williamr@2: IMPORT_C RStringF StrF() const; williamr@2: //##ModelId=3C4C187E02E0 williamr@2: IMPORT_C RString Str() const; williamr@2: williamr@2: /** Cast operator to obtain the HTTP value as a string. williamr@2: Note this doesn't convert from a different form to string! williamr@2: Panics if the value is of the wring type williamr@2: @pre Requires that the object was previously set to hold a string williamr@2: */ williamr@2: //##ModelId=3C4C187E02DF williamr@2: inline operator RStringF() const; williamr@2: /** Cast operator to obtain the HTTP value as a string. williamr@2: Note this doesn't convert from a different form to string! williamr@2: Panics if the value is of the wring type williamr@2: @pre Requires that the object was previously set to hold a string williamr@2: */ williamr@2: //##ModelId=3C4C187E02DE williamr@2: inline operator RString() const; williamr@2: williamr@2: /** Obtain the (date/time) value held within. williamr@2: Panics if the value is of the wrong type williamr@2: @pre Requires that the object was previously set to hold a TDateTime williamr@2: @return An date/time value williamr@2: */ williamr@2: //##ModelId=3C4C187E02D6 williamr@2: IMPORT_C TDateTime DateTime() const; williamr@2: williamr@2: /** Cast operator to obtain the HTTP value as an date/time. williamr@2: Note this doesn't convert from a different form to date! williamr@2: Panics if the value is of the wring type williamr@2: @pre Requires that the object was previously set to hold a TDateTime williamr@2: */ williamr@2: //##ModelId=3C4C187E02D5 williamr@2: inline operator TDateTime() const; williamr@2: williamr@2: /** Set the header value to be the supplied integer. williamr@2: @warning Any previous value, or its type, are lost. williamr@2: @param aIntVal The integer value williamr@2: */ williamr@2: //##ModelId=3C4C187E02CC williamr@2: IMPORT_C void SetInt(TInt aIntVal); williamr@2: williamr@2: /** Set the header value to be the supplied string. williamr@2: @warning Any previous value, or its type, are lost. williamr@2: @param aStrVal The string value williamr@2: */ williamr@2: //##ModelId=3C4C187E02CA williamr@2: IMPORT_C void SetStrF(RStringF aStrVal); williamr@2: /** Set the header value to be the supplied string. Any previous williamr@2: value, or its type, are lost. williamr@2: @param aStrVal The string value */ williamr@2: //##ModelId=3C4C187E02C2 williamr@2: IMPORT_C void SetStr(RString aStrVal); williamr@2: williamr@2: /** Set the header value to be the supplied date/time. Any previous value, or its type, are lost. williamr@2: @param aDateVal The date/time value williamr@2: */ williamr@2: //##ModelId=3C4C187E02C0 williamr@2: IMPORT_C void SetDateTime(TDateTime aDateVal); williamr@2: williamr@2: /** Comparison operator. Does a comparison based on the current type. williamr@2: @param aVal The header value to compare. */ williamr@2: //##ModelId=3C4C187E02B8 williamr@2: IMPORT_C TBool operator==(THTTPHdrVal aVal) const; williamr@2: williamr@2: /** Comparison operator. Does a comparison based on the current type. williamr@2: @param aVal The string to compare. */ williamr@2: //##ModelId=3C4C187E02B6 williamr@2: IMPORT_C TBool operator!=(THTTPHdrVal aVal) const; williamr@2: williamr@2: private: williamr@2: /** williamr@2: The current type williamr@2: */ williamr@2: //##ModelId=3C4C187E02AC williamr@2: THTTPValType iType; williamr@2: williamr@2: /** williamr@2: The value williamr@2: */ williamr@2: //##ModelId=3C4C187E02A4 williamr@2: TInt iVal; williamr@2: //##ModelId=3C4C187E029A williamr@2: TInt iMoreSpace; williamr@2: }; williamr@2: williamr@2: inline THTTPHdrVal::TQConv::TQConv(TReal aQ) williamr@2: : iQ(aQ), iFQ((TInt)(iQ*1000)) williamr@2: { williamr@2: } williamr@2: williamr@2: inline THTTPHdrVal::TQConv::TQConv(TInt aFQ) williamr@2: : iQ((TReal)(aFQ/1000.)), iFQ(aFQ) williamr@2: { williamr@2: } williamr@2: williamr@2: inline THTTPHdrVal::TQConv::operator TInt() const williamr@2: { williamr@2: return iFQ; williamr@2: } williamr@2: williamr@2: inline THTTPHdrVal::TQConv::operator TReal() const williamr@2: { williamr@2: return iQ; williamr@2: } williamr@2: williamr@2: inline THTTPHdrVal::operator TInt() const williamr@2: { williamr@2: return Int(); williamr@2: } williamr@2: williamr@2: inline THTTPHdrVal::operator RStringF() const williamr@2: { williamr@2: return StrF(); williamr@2: } williamr@2: williamr@2: inline THTTPHdrVal::operator RString() const williamr@2: { williamr@2: return Str(); williamr@2: } williamr@2: williamr@2: inline THTTPHdrVal::operator TDateTime() const williamr@2: { williamr@2: return DateTime(); williamr@2: } williamr@2: williamr@2: williamr@2: williamr@2: #endif // __THTTPHDRVAL_H__