javaextensions/pim/common/inc.s60/tpimfielddata.h
branchRCL_3
changeset 14 04becd199f91
equal deleted inserted replaced
13:f5050f1da672 14:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Class for holding PIM field data
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef TPIMFIELDDATA_H
       
    20 #define TPIMFIELDDATA_H
       
    21 
       
    22 // INTERNAL INCLUDES
       
    23 #include "pimtypes.h"
       
    24 #include "pimcommon.h"
       
    25 
       
    26 // EXTERNAL INCLUDES
       
    27 #include <e32std.h>
       
    28 #include <badesca.h>
       
    29 
       
    30 /**
       
    31  * Class for holding PIM field values;
       
    32  */
       
    33 NONSHARABLE_CLASS(TPIMFieldData)
       
    34 {
       
    35 public:
       
    36 
       
    37     // -- Constructors --
       
    38 
       
    39     /**
       
    40      * Default C++ constructor. Not applicable for this class
       
    41      * but still needed to represent
       
    42      */
       
    43     inline TPIMFieldData() :
       
    44             iDateValue(Time::NullTTime()),
       
    45             iStringValue(NULL),
       
    46             iStringArrayValue(NULL),
       
    47             iBinaryValue(NULL)
       
    48     {}
       
    49 
       
    50     /**
       
    51      * Constructor for integer and boolean types field data.
       
    52      * This should be used only with integer and boolean fields.
       
    53      * Getters panic if wrong data type is used with this object.
       
    54      * NOTE: This constructor is exception and takes field data
       
    55      * type as a paramater because integer and boolean values
       
    56      * cannot be overloaded. See TBool and TInt
       
    57      *
       
    58      * @param aField        PIM field type
       
    59      * @param aDataType     Data type of this field
       
    60      * @param aAttributes   Attributes of this field
       
    61      * @param aValue        Value of this field
       
    62      */
       
    63     inline TPIMFieldData(TPIMField aField, TPIMFieldDataType aDataType,
       
    64                          TPIMAttribute aAttributes, TInt aValue) :
       
    65             iField(aField), iDataType(aDataType), iAttributes(aAttributes), iIndex(
       
    66                 0), iIntegerBooleanValue(aValue)
       
    67     {
       
    68     }
       
    69 
       
    70     /**
       
    71      * Constructor for integer type field data. This should be
       
    72      * used only with date fields. Getters panic if wrong
       
    73      * data type is used with this object
       
    74      *
       
    75      * @param aField        PIM field type
       
    76      * @param aAttributes   Attributes of this field
       
    77      * @param aValue        Value of this field
       
    78      */
       
    79     inline TPIMFieldData(TPIMField aField, TPIMAttribute aAttributes,
       
    80                          TPIMDate aValue) :
       
    81             iField(aField), iDataType(EPIMFieldDate), iAttributes(aAttributes),
       
    82             iIndex(0), iDateValue(aValue)
       
    83     {
       
    84     }
       
    85 
       
    86     /**
       
    87      * Constructor for integer type field data. This should be
       
    88      * used only with string fields. Getters panic if wrong
       
    89      * data type is used with this object
       
    90      *
       
    91      * @param aField        PIM field type
       
    92      * @param aAttributes   Attributes of this field
       
    93      * @param aValue        Value of this field
       
    94      */
       
    95     inline TPIMFieldData(TPIMField aField, TPIMAttribute aAttributes,
       
    96                          const HBufC* aValue) :
       
    97             iField(aField), iDataType(EPIMFieldString), iAttributes(aAttributes),
       
    98             iIndex(0), iStringValue(aValue)
       
    99     {
       
   100     }
       
   101 
       
   102     /**
       
   103      * Constructor for integer type field data. This should be
       
   104      * used only with string array fields. Getters panic if wrong
       
   105      * data type is used with this object
       
   106      *
       
   107      * @param aField        PIM field type
       
   108      * @param aAttributes   Attributes of this field
       
   109      * @param aValue        Value of this field
       
   110      */
       
   111     inline TPIMFieldData(TPIMField aField, TPIMAttribute aAttributes,
       
   112                          const CDesCArray* aValue) :
       
   113             iField(aField), iDataType(EPIMFieldStringArray), iAttributes(
       
   114                 aAttributes), iIndex(0), iStringArrayValue(aValue)
       
   115     {
       
   116     }
       
   117 
       
   118     /**
       
   119      * Constructor for integer type field data. This should be
       
   120      * used only with binary fields. Getters panic if wrong
       
   121      * data type is used with this object
       
   122      *
       
   123      * @param aField        PIM field type
       
   124      * @param aAttributes   Attributes of this field
       
   125      * @param aValue        Value of this field
       
   126      */
       
   127     inline TPIMFieldData(TPIMField aField, TPIMAttribute aAttributes,
       
   128                          const CPIMByteArray* aValue) :
       
   129             iField(aField), iDataType(EPIMFieldBinary), iAttributes(aAttributes),
       
   130             iIndex(0), iBinaryValue(aValue)
       
   131     {
       
   132     }
       
   133     ;
       
   134 
       
   135 public: // New functions
       
   136 
       
   137     /**
       
   138      * @return Field
       
   139      */
       
   140     TPIMField Field() const;
       
   141 
       
   142     /**
       
   143      * @return Field's data type
       
   144      */
       
   145     TPIMFieldDataType FieldDataType() const;
       
   146 
       
   147     /**
       
   148      * @return Index of this field
       
   149      */
       
   150     TInt Index() const;
       
   151     void SetIndex(TInt aIndex);
       
   152 
       
   153     /**
       
   154      * @return Attributes of this field
       
   155      */
       
   156     TPIMAttribute Attributes() const;
       
   157 
       
   158     // -- Specific getters --
       
   159 
       
   160     /**
       
   161      * @return Interger value if this field is an integer field.
       
   162      *         If not, a panic is raised
       
   163      */
       
   164     TInt IntegerValue() const;
       
   165 
       
   166     /**
       
   167      * @return Boolean value if this field is a boolean field.
       
   168      *         If not, a panic is raised
       
   169      */
       
   170     TBool BooleanValue() const;
       
   171 
       
   172     /**
       
   173      * @return Date value if this field is a date field.
       
   174      *         If not, a panic is raised
       
   175      */
       
   176     TPIMDate DateValue() const;
       
   177 
       
   178     /**
       
   179      * @return String value if this field is string field.
       
   180      *         If not, a panic is raised
       
   181      */
       
   182     const TDesC& StringValue() const;
       
   183 
       
   184     /**
       
   185      * @return String array value if this field is a string array
       
   186      *         field. If not, a panic is raised
       
   187      */
       
   188     const CDesCArray& StringArrayValue() const;
       
   189 
       
   190     /**
       
   191      * @return Binary value if this field is a binary field.
       
   192      *         If not, a panic is raised
       
   193      */
       
   194     const CPIMByteArray& BinaryValue() const;
       
   195 
       
   196 private: // Data
       
   197 
       
   198     // Holds field info
       
   199     TPIMField iField;
       
   200     TPIMFieldDataType iDataType;
       
   201 
       
   202     // Holds attributes
       
   203     TPIMAttribute iAttributes;
       
   204 
       
   205     // Holds different types of values. Pointer are not owned
       
   206     TInt iIndex;
       
   207     TInt iIntegerBooleanValue;
       
   208     TPIMDate iDateValue;
       
   209 
       
   210     // Pointer values
       
   211     const HBufC* iStringValue;
       
   212     const CDesCArray* iStringArrayValue;
       
   213     const CPIMByteArray* iBinaryValue;
       
   214 
       
   215 private: // Friend classes
       
   216 
       
   217     /**
       
   218      * Friend classes are not encouraged to use but in this
       
   219      * case it is needed, because CPIMField class uses this
       
   220      * class to take and store the pointer values and this
       
   221      * helps the implementation. Value accessors can only return
       
   222      * references to the actual value.
       
   223      */
       
   224     friend class CPIMField;
       
   225 }
       
   226 ;
       
   227 
       
   228 #endif // TPIMFIELDDATA_H
       
   229 // End of file