photosgallery/viewframework/medialists/inc/glxmedia.inl
changeset 0 4e91876724a2
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:    Media item
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef C_GLXMEDIA_INL
       
    22 #define C_GLXMEDIA_INL
       
    23 
       
    24 // -----------------------------------------------------------------------------
       
    25 // The attributes provided in this media object
       
    26 // -----------------------------------------------------------------------------
       
    27 //
       
    28 inline const TArray<TMPXAttribute> CGlxMedia::Attributes() const
       
    29     {
       
    30     return iAttributes.Array();
       
    31     }
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // Does this object contain the value for a given attribute
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 inline TBool CGlxMedia::IsSupported(const TMPXAttribute& aAttribute) const
       
    38     {
       
    39     return KErrNotFound != Index(aAttribute);
       
    40     }
       
    41     
       
    42 // -----------------------------------------------------------------------------
       
    43 // The number of attribute values provided in this media object 
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 inline TInt CGlxMedia::Count() const
       
    47     {
       
    48     return iAttributes.Count();
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // The attribute for a specific index
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 inline const TMPXAttribute& CGlxMedia::Attribute(TInt aIndex) const
       
    56     {
       
    57     return iAttributes[aIndex];
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // The index of a given attribute
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 inline TInt CGlxMedia::Index(const TMPXAttribute& aAttribute) const
       
    65     {
       
    66     return iAttributes.Find(aAttribute, TMPXAttribute::Match);
       
    67     }
       
    68   
       
    69 // -----------------------------------------------------------------------------
       
    70 // The value for a specific attribute
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 template <typename T>
       
    74 inline T CGlxMedia::ValueTObject(const TMPXAttribute& aAttribute) const
       
    75     {
       
    76     TInt i = Index(aAttribute);
       
    77 
       
    78     __ASSERT_DEBUG( i != KErrNotFound, Panic( EGlxPanicIllegalArgument ) );
       
    79 
       
    80     __ASSERT_DEBUG(EMPXTypeTObject == iValues[i].iType,
       
    81                                         Panic(EGlxPanicWrongAttributeType));
       
    82     const TValue& value = iValues[i];
       
    83     const T* ptr = reinterpret_cast<const T*>(value.iValue);
       
    84     __ASSERT_DEBUG(ptr != NULL, Panic(EGlxPanicNullPointer));
       
    85     return *ptr;
       
    86     }   
       
    87   
       
    88 template <typename T>
       
    89 inline TBool CGlxMedia::GetValueTObject(T& aValue, const TMPXAttribute& aAttribute) const
       
    90     {
       
    91     TInt i = Index(aAttribute);
       
    92     if (KErrNotFound == i)
       
    93         {
       
    94         return EFalse;
       
    95         }
       
    96 
       
    97     __ASSERT_DEBUG(EMPXTypeTObject == iValues[i].iType,
       
    98                                         Panic(EGlxPanicWrongAttributeType));
       
    99     const TValue& value = iValues[i];
       
   100     const T* ptr = reinterpret_cast<const T*>(value.iValue);
       
   101     __ASSERT_DEBUG(ptr != NULL, Panic(EGlxPanicNullPointer));
       
   102     aValue = *ptr;
       
   103     return ETrue;
       
   104     }   
       
   105 
       
   106   
       
   107 // -----------------------------------------------------------------------------
       
   108 // Set the value for a specific attribute
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 template<typename T> 
       
   112 inline void CGlxMedia::SetTObjectValueL(const TMPXAttribute& aAttribute, T aValue) 
       
   113 	{
       
   114     TAny* ptr = User::AllocL(sizeof(T));
       
   115     memcpy(ptr, &aValue, sizeof(T));
       
   116 
       
   117     SetValueL(aAttribute, ptr, EMPXTypeTObject);
       
   118    	}
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // Constructor
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 CGlxMedia::TValue::TValue(TAny* aValue, TMPXAttributeType aType)
       
   125 	{
       
   126 	iValue = aValue;
       
   127 	iType = aType;
       
   128 	}
       
   129 	
       
   130 #endif // C_GLXMEDIA_INL