inc/alf/alfmodeloperation.h
branchRCL_3
changeset 19 4ea6f81c838a
parent 17 514d98f21c43
child 20 0e9bb658ef58
equal deleted inserted replaced
17:514d98f21c43 19:4ea6f81c838a
     1 /*
       
     2 * Copyright (c) 2004 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:  This interface defines a generic data type
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef ALFMODELOPERATION_H
       
    22 #define ALFMODELOPERATION_H
       
    23 
       
    24 
       
    25 //INCLUDES
       
    26 #include <osn/osndefines.h>
       
    27 #include <osn/ustring.h>
       
    28 
       
    29 using namespace osncore;
       
    30 
       
    31 namespace Alf
       
    32     {
       
    33 
       
    34 /* Forward declarations*/
       
    35 class IAlfVariantType;
       
    36 
       
    37 /** @class AlfModelOperation alfmodeloperation.h "alf/alfmodeloperation.h"
       
    38 *  A class for storing information about changes in the model.
       
    39 *  CAlfModelOperation can be used to make changes in a batch mode,
       
    40 *  i.e., executing multiple changes in one call.
       
    41 *  @lib hitchcockwidgetmodel.lib
       
    42 *  @since S60 ?S60_version
       
    43 *  @status Draft
       
    44 */
       
    45 class AlfModelOperation
       
    46     {
       
    47 public:
       
    48 
       
    49     /** The operation constants. */
       
    50     enum OperationType{EOperationAdd, EOperationRemove, EOperationUpdate};
       
    51 
       
    52     /**
       
    53      * constructor. The new operation is left on the cleanup stack.
       
    54      *
       
    55 	 * @exception std::bad_alloc     
       
    56      * @since S60 ?S60_version
       
    57      * @param aOperation The operation to be performed.
       
    58      * @param aNumContainerIndices The number of indices in aContainerIndices.
       
    59      * @param aContainerIndices The container indices to find the correct location
       
    60      *                          in the data hierarchy. The ownership is transferred.
       
    61      * @param aData The new data in EOperationAdd and EOperationUpdate operations.
       
    62      *              The ownership is transferred.
       
    63      */
       
    64     OSN_IMPORT static AlfModelOperation* create( OperationType aOperation,
       
    65             int aNumContainerIndices,
       
    66             int* aContainerIndices,
       
    67             IAlfVariantType* aData = 0 );
       
    68 
       
    69     /**
       
    70      * constructor for adding or updating a map item.
       
    71      * The new operation is left on the cleanup stack.
       
    72      *
       
    73 	 * @exception std::bad_alloc     
       
    74      * @since S60 ?S60_version
       
    75      * @param aOperation The operation to be performed.
       
    76      * @param aNumContainerIndices The number of indices in aContainerIndices.
       
    77      * @param aContainerIndices The container indices to find the correct location
       
    78      *                          in the data hierarchy. The ownership is transferred.
       
    79      * @param aData The new data. The ownership is transferred.
       
    80      * @param aDataName The name of the new data in EOperationAdd and EOperationUpdate
       
    81      *                  operations. Only needed when adding or updating a map item.
       
    82      */
       
    83     OSN_IMPORT static AlfModelOperation* create( OperationType aOperation,
       
    84             int aNumContainerIndices,
       
    85             int* aContainerIndices,
       
    86             IAlfVariantType* aData,
       
    87             const UString& aDataName );
       
    88 
       
    89     /** Destructor.*/
       
    90     OSN_IMPORT ~AlfModelOperation();
       
    91 
       
    92     /**
       
    93      * Get the name of the new data field in the container map.
       
    94      * Panics if the operation is EOperationRemove.
       
    95      *
       
    96      * @exception osncore::AlfDataException Thrown with the error code osncore::EInvalidModelOperation\n 
       
    97      *										  when wrong operation is performed on Model.
       
    98      * @return The new data.
       
    99      * @since S60 ?S60_version
       
   100      */
       
   101     OSN_IMPORT const UString& newDataName() const;
       
   102 
       
   103     /**
       
   104      * Get the new data used in EOperationAdd or EOperationUpdate operations.
       
   105      * Panics if the operation is EOperationRemove.
       
   106      *
       
   107      * @exception osncore::AlfDataException Thrown with the error code osncore::EInvalidModelOperation\n 
       
   108      *										  when wrong operation is performed on Model.
       
   109      * @return The new data.
       
   110      * @since S60 ?S60_version
       
   111      */
       
   112     OSN_IMPORT IAlfVariantType& newData() const;
       
   113 
       
   114     /**
       
   115      * Get the new data used in EOperationAdd or EOperationUpdate operations.
       
   116      * Panics if the operation is EOperationRemove.
       
   117      * The ownership of the data is transferred to the caller,
       
   118      * and the data of this operation is set to NULL.
       
   119      *
       
   120      * @exception osncore::AlfDataException Thrown with the error code osncore::EInvalidModelOperation\n 
       
   121      *										  when wrong operation is performed on Model.
       
   122      * @return The new data.
       
   123      * @since S60 ?S60_version
       
   124      */
       
   125     OSN_IMPORT IAlfVariantType* getNewData();
       
   126 
       
   127     /**
       
   128      * Get the Operation.
       
   129      *
       
   130      * @return The new data.
       
   131      * @since S60 ?S60_version
       
   132      */
       
   133     OSN_IMPORT AlfModelOperation::OperationType operation() const;
       
   134 
       
   135     /**
       
   136      * Get the parent data for the operation. The parent data
       
   137      * is a container for the data to be added, removed or updated.
       
   138      * The index of the data can be queried using Index().
       
   139      *
       
   140      * @exception osncore::AlfDataException Thrown with the error code osncore::EInvalidContainerOperation\n 
       
   141      *										  when wrong operation is performed on Model.
       
   142      * @param aRoot The root of the data hierarchy to perform the operation.
       
   143      * @return The parent data.
       
   144      * @since S60 ?S60_version
       
   145      */
       
   146     OSN_IMPORT IAlfVariantType* parentData(IAlfVariantType& aRoot ) const;
       
   147 
       
   148     /**
       
   149      * Get the index of the data inside the parent container.
       
   150      * The parent container can be queried using ParentData().
       
   151      * If the parent container is a branch, index 0 refers to
       
   152      * the branch data, and index 1 refers to the child data.
       
   153      *
       
   154      * @return The new data.
       
   155      * @since S60 ?S60_version
       
   156      */
       
   157     OSN_IMPORT int index() const;
       
   158 
       
   159     /**
       
   160      * Get the number of container indices to find the
       
   161      * location in the data hierarchy.
       
   162      *
       
   163      * @return The number of container indices.
       
   164      * @since S60 ?S60_version
       
   165      */
       
   166     OSN_IMPORT int numContainerIndices() const;
       
   167 
       
   168     /**
       
   169      * Get the container index to traverse through the data hierarchy.
       
   170      * If the container in the hierarchy is a branch, index 0 refers to
       
   171      * the branch data, and index 1 refers to the child data.
       
   172      *
       
   173      * @return The container index.
       
   174      * @since S60 ?S60_version
       
   175      */
       
   176     OSN_IMPORT int containerIndex( int aIndex ) const;
       
   177 
       
   178 private:
       
   179 
       
   180     AlfModelOperation(
       
   181         OperationType aOperation,
       
   182         int aNumContainerIndices,
       
   183         int* aContainerIndices,
       
   184         IAlfVariantType* aData = 0 );
       
   185 
       
   186     AlfModelOperation(
       
   187         OperationType aOperation,
       
   188         int aNumContainerIndices,
       
   189         int* aContainerIndices,
       
   190         IAlfVariantType* aData,
       
   191         const UString& aDataName );
       
   192 
       
   193 private: // data
       
   194 
       
   195     // Target location in the data hierarchy
       
   196     int mNumContainerIndices;
       
   197     int* mContainerIndices;
       
   198 
       
   199     // The new data
       
   200     IAlfVariantType* mData;
       
   201     // The name of the new data, if adding or updating a map item
       
   202     UString mDataName;
       
   203 
       
   204     // The operation to be performed
       
   205     OperationType mOperation;
       
   206     };
       
   207 
       
   208     } // namespace Alf
       
   209 
       
   210 #endif // ALFMODELOPERATION_H