mpx/commonframework/common/inc/mpxdataarray.h
changeset 0 a2952bb97e68
equal deleted inserted replaced
-1:000000000000 0:a2952bb97e68
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Array of variable size elements on global chunk
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef RMPXDATAARRAY_H
       
    21 #define RMPXDATAARRAY_H
       
    22 
       
    23 #include <e32base.h>
       
    24 
       
    25 class RMPXDataItem;
       
    26 
       
    27 /**
       
    28 *  Class RMPXDataItemArray. A dynamic array of RMPXDataItems, where each item
       
    29 *  can have variable length data
       
    30 */
       
    31 class RMPXDataItemArray
       
    32     {
       
    33 public:
       
    34     /**
       
    35      * C++ default constructor.
       
    36      */
       
    37     RMPXDataItemArray();
       
    38     
       
    39     /**
       
    40     * Frees resources; object can go out of scope
       
    41     * 
       
    42     * @param aClientHandle, client handle to the global chunk
       
    43     */
       
    44     void Close(TUint aClientHandle);
       
    45     
       
    46 public:
       
    47     /**
       
    48     * Number of items in array
       
    49     * 
       
    50     * @return number of contained media objects
       
    51     */
       
    52     inline TInt Count() const;
       
    53 
       
    54     /**
       
    55     * Data at aIndex
       
    56     * 
       
    57     * @param aClientHandle, client handle to the global chunk
       
    58     * @param aIndex, index of data item
       
    59     * @return raw data of the item
       
    60     */
       
    61     inline TPtrC8 Data(TUint aClientHandle,TInt aIndex);
       
    62 
       
    63     /**
       
    64     * Data item at aIndex
       
    65     * 
       
    66     * @param aClientHandle, client handle to the global chunk
       
    67     * @param aIndex, index of data item
       
    68     * @return data item object
       
    69     */
       
    70     RMPXDataItem* DataItem(TUint aClientHandle,TInt aIndex);
       
    71 
       
    72     /**
       
    73     * Adds an item to the array
       
    74     * 
       
    75     * @param aClientHandle, client handle to the global chunk
       
    76     * @param aItem, data item object
       
    77     */
       
    78     void Append(TUint aClientHandle,RMPXDataItem& aItem);
       
    79 
       
    80     /**
       
    81     * Replaces an item in the array
       
    82     * 
       
    83     * @param aClientHandle, client handle to the global chunk
       
    84     * @param aItem data item object
       
    85     * @param aIndex, index of data item
       
    86     */
       
    87     void Set(TUint aClientHandle,RMPXDataItem& aItem,TInt aIndex);
       
    88 
       
    89     /**
       
    90     * Inserts an item to the array
       
    91     * 
       
    92     * @param aClientHandle, client handle to the global chunk
       
    93     * @param aItem data item object
       
    94     * @param aIndex, index of data item
       
    95     */
       
    96     void Insert(TUint aClientHandle,RMPXDataItem& aItem,TInt aIndex);
       
    97 
       
    98     /**
       
    99     * Removes an item from the array
       
   100     * 
       
   101     * @param aClientHandle, client handle to the global chunk
       
   102     * @param aIndex, index of data item
       
   103     */
       
   104     void Remove(TUint aClientHandle,TInt aIndex);
       
   105 
       
   106     /**
       
   107     * Removes all items from the array
       
   108     * 
       
   109     * @param aClientHandle, client handle to the global chunk
       
   110     */
       
   111     void Reset(TUint aClientHandle);
       
   112     
       
   113     /**
       
   114      * Find an item from the array
       
   115      * 
       
   116      * @param aClientHandle, client handle to the global chunk
       
   117      * @param aItem, data item object
       
   118      */
       
   119     TInt Find(TUint aClientHandle,const RMPXDataItem& aItem);
       
   120     
       
   121 protected: 
       
   122     /**
       
   123     * Deletes an item from the array
       
   124     * 
       
   125     * @param aClientHandle, client handle to the global chunk
       
   126     * @param aItem, data item object
       
   127     */
       
   128     void Delete(TUint aClientHandle,RMPXDataItem* aItem);
       
   129 
       
   130 protected:
       
   131     /**
       
   132     * Offset from the base of the chunk to the first item
       
   133     */
       
   134     TInt iFirstItemOffset;
       
   135     /**
       
   136     * Offset from the base of the chunk to the last item
       
   137     */
       
   138     TInt iLastItemOffset;
       
   139     /**
       
   140     * Number of items stored in this array
       
   141     */
       
   142     TInt iNumItems;
       
   143     /**
       
   144     * Current position within the list, offset from the base of the chunk
       
   145     */
       
   146     TInt iPos; 
       
   147     /**
       
   148     * Current index within the list (i.e. first item=0, last=iNumItems-1)
       
   149     */
       
   150     TInt iIndex; 
       
   151     };
       
   152 
       
   153 /**
       
   154 *  Class RMPXDataItem. Encapsulates an item of data on the heap.
       
   155 */
       
   156 class RMPXDataItem
       
   157     {
       
   158 public:
       
   159     /**
       
   160     * Default C++ constructor
       
   161     */
       
   162     inline RMPXDataItem();
       
   163     
       
   164     /**
       
   165     * Frees resources; object can go out of scope
       
   166     * 
       
   167     * @param aClientHandle, client handle to the global chunk
       
   168     */
       
   169     inline void Close(TUint aClientHandle);
       
   170     
       
   171     /**
       
   172     * Frees resources; object can be reused
       
   173     * 
       
   174     * @param aClientHandle, client handle to the global chunk
       
   175     */
       
   176     void Reset(TUint aClientHandle);
       
   177     
       
   178 public:
       
   179     /**
       
   180     * Sets the data for this object
       
   181     * 
       
   182     * @param aClientHandle, client handle to the global chunk
       
   183     * @param aSrc, source data item
       
   184     * @param aSize, size of data item 
       
   185     */
       
   186     void Copy(TUint aClientHandle,TAny* aSrc,TInt aSize);
       
   187     
       
   188     /**
       
   189     * Sets the data for this object
       
   190     * 
       
   191     * @param aClientHandle, client handle to the global chunk
       
   192     * @param aData, source data item
       
   193     */
       
   194     inline void Copy(TUint aClientHandle,const TDesC8& aData);
       
   195     
       
   196     /**
       
   197     * Pointer to the data for this object
       
   198     * 
       
   199     * @param aClientHandle, client handle to the global chunk
       
   200     * @return data item buffer
       
   201     */
       
   202     TAny* Buf(TUint aClientHandle);
       
   203     
       
   204     /**
       
   205     * Value of the data for this object as a descriptor
       
   206     * 
       
   207     * @param aClientHandle, client handle to the global chunk
       
   208     * @return data item buffer
       
   209     */
       
   210     inline TPtrC8 Data(TUint aClientHandle);
       
   211     
       
   212     /**
       
   213     * Size of the data for this object
       
   214     * 
       
   215     * @return the size of data item
       
   216     */
       
   217     inline TInt Size() const;
       
   218     
       
   219     /**
       
   220     * UID of this object
       
   221     * 
       
   222     * @return uid of the data item
       
   223     */
       
   224     inline TInt Uid() const;
       
   225     
       
   226     /**
       
   227     * Next item in list, or 0 if none
       
   228     * 
       
   229     * @return next item offset
       
   230     */
       
   231     inline TInt NextOffset() const;
       
   232     
       
   233     /**
       
   234     * Previous item in list, or 0 if none
       
   235     * 
       
   236     * @return previous item offset
       
   237     */
       
   238     inline TInt PreviousOffset() const;
       
   239 
       
   240 public:
       
   241     /**
       
   242     * Inserts this object in a doubly linked list. Either (but not
       
   243     * both) can be NULL in which case this item is appended to the
       
   244     * start or end of the list
       
   245     * 
       
   246     * @param aClientHandle, client handle to the global chunk
       
   247     * @param aPrevious, pointer to previous data item
       
   248     * @param aNext, pointer to next data item
       
   249     */
       
   250     void Insert(TUint aClientHandle,RMPXDataItem* aPrevious,RMPXDataItem* aNext);
       
   251     
       
   252     /**
       
   253     * Inserts this object in a doubly linked list. Either (but not
       
   254     * both) can be 0 in which case this item is appended to the
       
   255     * start or end of the list
       
   256     * 
       
   257     * @param aClientHandle, client handle to the global chunk
       
   258     * @param aPreviousOffset, previous data item offset
       
   259     * @param aNextOffset, next data item offset
       
   260     */
       
   261     void Insert(TUint aClientHandle,TInt aPreviousOffset,TInt aNextOffset);
       
   262     
       
   263     /**
       
   264     * Sets this object in a doubly linked list.
       
   265     * 
       
   266     * @param aClientHandle, client handle to the global chunk
       
   267     * @param aOldItem, pointer to old data item
       
   268     */
       
   269     void Set(TUint aClientHandle,RMPXDataItem* aOldItem);
       
   270     
       
   271     /**
       
   272     * Sets this object in a doubly linked list.
       
   273     * 
       
   274     * @param aClientHandle, client handle to the global chunk
       
   275     * @param aOldItemOffset, old data item offset
       
   276     */
       
   277     void Set(TUint aClientHandle,TInt aOldItemOffset);
       
   278   
       
   279     /**
       
   280     * Removes this object from a doubly linked list
       
   281     * 
       
   282     * @param aClientHandle, client handle to the global chunk
       
   283     */
       
   284     void Remove(TUint aClientHandle);
       
   285   
       
   286 protected:
       
   287     /**
       
   288     * Offset from the base of the chunk to the previous data
       
   289     * item, or 0 if none
       
   290     */  
       
   291     TInt iPreviousOffset;
       
   292     /**
       
   293     * Offset from the base of the chunk to the next data
       
   294     * item, or 0 if none
       
   295     */
       
   296     TInt iNextOffset;
       
   297     /**
       
   298     * Offset within this object
       
   299     */
       
   300     TInt iBufOffset;
       
   301     /**
       
   302     * Length of the data buffer
       
   303     */    
       
   304     TInt iBufLen; 
       
   305     /**
       
   306     * Unique ID of data
       
   307     */
       
   308     TInt iUid;
       
   309     };
       
   310 
       
   311 /**
       
   312 * Class RMPXDataObject. Data item which holds an object of type T
       
   313 */
       
   314 template <class T>
       
   315 class RMPXDataObject : public RMPXDataItem
       
   316     {
       
   317 public:
       
   318     /**
       
   319      * Get the data object
       
   320      * 
       
   321      * @param aClientHandle, client handle to the global chunk
       
   322      * @return the data object
       
   323      */
       
   324     inline T* Object(TUint aClientHandle);
       
   325 
       
   326     /**
       
   327      * Copy data object
       
   328      *  
       
   329      * @param aClientHandle, client handle to the global chunk
       
   330      * @param aSrc, source data object
       
   331      */
       
   332     inline void CopyObject(TUint aClientHandle,const T& aSrc);
       
   333 private:
       
   334     T iData;
       
   335     };
       
   336 
       
   337 
       
   338 #include "mpxdataarray.inl"
       
   339 
       
   340 #endif // RMPXDATAARRAY_H