widgetmodel/alfwidgetmodel/src/alfattributevaluetype.cpp
changeset 17 3eca7e70b1b8
parent 3 4526337fb576
equal deleted inserted replaced
3:4526337fb576 17:3eca7e70b1b8
     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:   Implementation to know the type of attribute.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32def.h>
       
    20 #include <osn/osnnew.h>
       
    21 #include <alf/alfdataexception.h>
       
    22 #include <alf/alfattributeexception.h>
       
    23 #include "alf/alfattributevaluetype.h"
       
    24 
       
    25 #include "alfenumvalue.h"
       
    26 #include "alfrealvalue.h"
       
    27 #include "alfstringvalue.h"
       
    28 
       
    29 namespace Alf
       
    30     {
       
    31 
       
    32 class AlfAttributeValueTypeImpl
       
    33     {
       
    34 public:
       
    35     AlfAttributeValueTypeImpl()
       
    36         {
       
    37         mValueType = NULL;
       
    38         }
       
    39 
       
    40     ~AlfAttributeValueTypeImpl()
       
    41         {
       
    42         delete mValueType;
       
    43         }
       
    44 
       
    45     AlfAttributeValueType* mValueType;
       
    46     };
       
    47 
       
    48 // ======== MEMBER FUNCTIONS ========
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // Constructor.
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 AlfAttributeValueType::AlfAttributeValueType()
       
    55     {
       
    56 
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // Constructor.
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 OSN_EXPORT AlfAttributeValueType::AlfAttributeValueType(int aValue,
       
    64         TAlfUnit aUnit)
       
    65     {
       
    66     auto_ptr<AlfEnumValue> value(new (EMM) AlfEnumValue(aValue, aUnit));
       
    67     auto_ptr<AlfAttributeValueTypeImpl> valueType(
       
    68         new (EMM) AlfAttributeValueTypeImpl());
       
    69 
       
    70     mData.reset(valueType.release());       // ownership transferred
       
    71     mData->mValueType = value.release();    // ownership transferred
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // Constructor.
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 OSN_EXPORT AlfAttributeValueType::AlfAttributeValueType(float aValue,
       
    79         TAlfUnit aUnit)
       
    80     {
       
    81     auto_ptr<AlfRealValue> value(new (EMM) AlfRealValue(aValue, aUnit));
       
    82     auto_ptr<AlfAttributeValueTypeImpl> valueType(
       
    83         new (EMM) AlfAttributeValueTypeImpl());
       
    84 
       
    85     mData.reset(valueType.release());       // ownership transferred
       
    86     mData->mValueType = value.release();    // ownership transferred
       
    87     }
       
    88 
       
    89 // ---------------------------------------------------------------------------
       
    90 // Constructor.
       
    91 // ---------------------------------------------------------------------------
       
    92 //
       
    93 OSN_EXPORT AlfAttributeValueType::AlfAttributeValueType(const UString& aValue)
       
    94     {
       
    95     auto_ptr<AlfStringValue> value(new (EMM) AlfStringValue(aValue));
       
    96     auto_ptr<AlfAttributeValueTypeImpl> valueType(
       
    97         new (EMM) AlfAttributeValueTypeImpl());
       
    98 
       
    99     mData.reset(valueType.release());       // ownership transferred
       
   100     mData->mValueType = value.release();    // ownership transferred
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // Destructor.
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 OSN_EXPORT AlfAttributeValueType::~AlfAttributeValueType()
       
   108     {
       
   109 
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // Gets the enum value.
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 OSN_EXPORT int AlfAttributeValueType::enumValue() const
       
   117     {
       
   118     return intValue();
       
   119     }
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // Gets the string value.
       
   123 // ---------------------------------------------------------------------------
       
   124 //
       
   125 OSN_EXPORT const UString& AlfAttributeValueType::stringValue() const
       
   126     {
       
   127     if (type() != EString)
       
   128         {
       
   129         ALF_THROW(AlfDataException,EInvalidAttributeValue,"AlfAttributeValueType")
       
   130         }
       
   131     return mData->mValueType->stringValue();
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // Gets the int value.
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 OSN_EXPORT int AlfAttributeValueType::intValue() const
       
   139     {
       
   140     if (type() != EInt)
       
   141         {
       
   142         ALF_THROW(AlfDataException,EInvalidAttributeValue,"AlfAttributeValueType")
       
   143         }
       
   144     return mData->mValueType->enumValue();
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // Gets the real value.
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 OSN_EXPORT float AlfAttributeValueType::realValue() const
       
   152     {
       
   153     if (type() != EFloat)
       
   154         {
       
   155         ALF_THROW(AlfDataException,EInvalidAttributeValue,"AlfAttributeValueType")
       
   156         }
       
   157     return mData->mValueType->realValue();
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // Gets the RGB value.
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 OSN_EXPORT float AlfAttributeValueType::rgbValue() const
       
   165     {
       
   166     return realValue();
       
   167     }
       
   168 
       
   169 // ---------------------------------------------------------------------------
       
   170 // Gets the type of the atrribute value.
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 OSN_EXPORT AlfAttributeValueType::Type AlfAttributeValueType::type() const
       
   174     {
       
   175     return mData->mValueType->type();
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // Gets the unit.
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 OSN_EXPORT TAlfUnit AlfAttributeValueType::unit() const
       
   183     {
       
   184     return mData->mValueType->unit();
       
   185     }
       
   186 
       
   187     } // Alf