mulwidgets/muldatamodel/src/mulvarianttype.cpp
branchRCL_3
changeset 26 0e9bb658ef58
parent 0 e83bab7cf002
equal deleted inserted replaced
25:4ea6f81c838a 26:0e9bb658ef58
       
     1 /*
       
     2 * Copyright (c) 2007-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:  MulVarianttype implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <mul/mulvarianttype.h>
       
    20 
       
    21 #include <mul/imulvarianttype.h>
       
    22 #include <osn/osnnew.h>
       
    23 
       
    24 #include "mulassert.h"
       
    25 
       
    26 using namespace osncore;
       
    27 using namespace std;
       
    28 
       
    29 namespace Alf
       
    30     {
       
    31     
       
    32 _LIT( KUnknownDataType, "Unknown data type" );
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // Defination of class MulVariantTypeImpl
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 
       
    39 class MulVariantType::MulVariantTypeImpl
       
    40     {     
       
    41 public:
       
    42     
       
    43     ~MulVariantTypeImpl()
       
    44         {
       
    45         if( mDataType == IMulVariantType::EDes )
       
    46             {
       
    47             if( mData.mDes )
       
    48                 {
       
    49                 delete mData.mDes;
       
    50                 }
       
    51             }
       
    52         else if( mDataType == IMulVariantType::EMap )
       
    53             {
       
    54             if( mData.mMap )
       
    55                 {
       
    56                 delete mData.mMap;
       
    57                 }
       
    58             }
       
    59       
       
    60         }
       
    61     
       
    62     MulVariantTypeImpl()
       
    63         {
       
    64         mData.mDes = NULL;
       
    65         mData.mMap = NULL;
       
    66         mDataType = IMulVariantType::EUnknown;
       
    67         }
       
    68     
       
    69 public:
       
    70     
       
    71     union TData
       
    72         {
       
    73         bool     mBool;  // Boolean
       
    74         int      mInt;   // 32-bit integer
       
    75         uint     mUint;  // 32-bit unsigned integer
       
    76         double   mReal;  // 64-bit real
       
    77         HBufC*   mDes;   // 16 bit descriptor 
       
    78         IAlfMap* mMap;
       
    79         };
       
    80     
       
    81     TData mData;
       
    82     IMulVariantType::TMulType mDataType;
       
    83     
       
    84     };
       
    85 
       
    86 void MulVariantType::Construct( TMulType aType )
       
    87     {
       
    88     mVarData.reset( new (EMM) MulVariantTypeImpl() );
       
    89     mVarData->mDataType = aType;
       
    90     }
       
    91 
       
    92 // ---------------------------------------------------------------------------
       
    93 // MulVariantType
       
    94 // ---------------------------------------------------------------------------
       
    95 //
       
    96 OSN_EXPORT MulVariantType::MulVariantType()	
       
    97 	{
       
    98 	Construct(IMulVariantType::EUnknown );
       
    99 	// No implementation required
       
   100 	}
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // MulVariantType
       
   104 // ---------------------------------------------------------------------------
       
   105 //
       
   106 OSN_EXPORT MulVariantType::MulVariantType( const TDesC& aDes )
       
   107     {
       
   108     Construct(IMulVariantType::EDes );
       
   109     mVarData->mData.mDes = aDes.AllocL();
       
   110     }
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // MulVariantType
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 OSN_EXPORT MulVariantType::MulVariantType(const int& aValue)
       
   117 	{
       
   118 	Construct(IMulVariantType::EInt );
       
   119 	mVarData->mData.mInt = aValue;
       
   120 	}
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // MulVariantType
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 OSN_EXPORT MulVariantType::MulVariantType(const uint& aValue)	
       
   127 	{
       
   128 	Construct(IMulVariantType::EUint );
       
   129 	mVarData->mData.mUint = aValue;
       
   130 	}
       
   131 
       
   132 // ---------------------------------------------------------------------------
       
   133 // MulVariantType
       
   134 // ---------------------------------------------------------------------------
       
   135 //
       
   136 OSN_EXPORT MulVariantType::MulVariantType(const double& aValue)	
       
   137 	{
       
   138 	Construct(IMulVariantType::EReal );
       
   139 	mVarData->mData.mReal = aValue;
       
   140 	}
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // MulVariantType
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 OSN_EXPORT MulVariantType::MulVariantType(const bool& aValue)	
       
   147 	{
       
   148 	Construct(IMulVariantType::EBool );
       
   149 	mVarData->mData.mBool = aValue;
       
   150 	}
       
   151 
       
   152 // ---------------------------------------------------------------------------
       
   153 // MulVariantType
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 OSN_EXPORT MulVariantType::MulVariantType( IAlfMap& aData )  
       
   157     {
       
   158     Construct(IMulVariantType::EMap );
       
   159     mVarData->mData.mMap = aData.clone();
       
   160     }
       
   161 
       
   162 // ---------------------------------------------------------------------------
       
   163 // ~MulVariantType
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 OSN_EXPORT MulVariantType::~MulVariantType()    
       
   167     {
       
   168     // No implementation required
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // MulType
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 OSN_EXPORT IMulVariantType::TMulType MulVariantType::Type() const
       
   176     {
       
   177     return mVarData->mDataType;
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // DesC
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 OSN_EXPORT const TDesC& MulVariantType::DesC() const
       
   185     {
       
   186     if ( Type() != IMulVariantType::EDes ) 
       
   187         {
       
   188         __MUL_ASSERT(false, KUnknownDataType );
       
   189         }
       
   190     return *mVarData->mData.mDes;
       
   191     }
       
   192 	
       
   193 // ---------------------------------------------------------------------------
       
   194 // Clone
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 OSN_EXPORT std::auto_ptr< IMulVariantType > MulVariantType::Clone()
       
   198 	{
       
   199 	std::auto_ptr<IMulVariantType> clone;
       
   200 	
       
   201 	switch( Type() )
       
   202 		{
       
   203 		case IMulVariantType::EBool:
       
   204 		    {
       
   205 	        clone.reset( new (EMM) MulVariantType( boolean() ) );
       
   206 	        return clone;
       
   207 		    }
       
   208 		case IMulVariantType::EInt:
       
   209 		    {
       
   210 		    clone.reset( new (EMM) MulVariantType( integer() ) ) ;
       
   211 		    return clone;
       
   212 		    }
       
   213 		case IMulVariantType::EUint:
       
   214 		    {
       
   215 		    clone.reset( new (EMM) MulVariantType( uinteger() ) );
       
   216 		    return clone;
       
   217 		    }
       
   218 		case IMulVariantType::EReal:
       
   219 		    {
       
   220 		    clone.reset( new (EMM) MulVariantType( real() ) );
       
   221 		    return clone;
       
   222 		    }
       
   223 		case IMulVariantType::EDes:
       
   224 			{
       
   225 			clone.reset( new (EMM) MulVariantType( DesC() ) ) ;
       
   226 			return clone;
       
   227 			}
       
   228 		case IAlfVariantType::EMap:
       
   229 		    {
       
   230 		    clone.reset( new (EMM) MulVariantType( Map() ) ) ;
       
   231 		    return clone;
       
   232 		    }
       
   233 		case IAlfVariantType::ECustomData: //delebrate fallthrough
       
   234 		default :
       
   235 			{
       
   236 			__MUL_ASSERT( false, KUnknownDataType );
       
   237 			return clone;
       
   238 			}
       
   239 		}
       
   240 	}
       
   241 
       
   242 // ---------------------------------------------------------------------------
       
   243 // boolean
       
   244 // ---------------------------------------------------------------------------
       
   245 //
       
   246 OSN_EXPORT bool MulVariantType::boolean() const
       
   247 	{
       
   248     if ( Type() != IMulVariantType::EBool ) 
       
   249         {
       
   250         __MUL_ASSERT( false, KUnknownDataType );
       
   251         }
       
   252     return mVarData->mData.mBool;
       
   253 	}
       
   254 
       
   255 // ---------------------------------------------------------------------------
       
   256 // integer
       
   257 // ---------------------------------------------------------------------------
       
   258 //
       
   259 OSN_EXPORT int MulVariantType::integer() const
       
   260 	{
       
   261 	if ( Type() != IMulVariantType::EInt ) 
       
   262        {
       
   263        __MUL_ASSERT( false, KUnknownDataType );
       
   264        }
       
   265     return mVarData->mData.mInt;
       
   266 	}
       
   267 
       
   268 // ---------------------------------------------------------------------------
       
   269 // uinteger
       
   270 // ---------------------------------------------------------------------------
       
   271 //
       
   272 OSN_EXPORT uint MulVariantType::uinteger() const
       
   273 	{
       
   274 	if ( Type() != IMulVariantType::EUint ) 
       
   275        {
       
   276        __MUL_ASSERT( false, KUnknownDataType );
       
   277        }
       
   278 	return mVarData->mData.mUint;
       
   279 	}
       
   280 
       
   281 // ---------------------------------------------------------------------------
       
   282 // real
       
   283 // ---------------------------------------------------------------------------
       
   284 //
       
   285 OSN_EXPORT double MulVariantType::real() const
       
   286 	{
       
   287 	if ( Type() != IMulVariantType::EUint ) 
       
   288        {
       
   289        __MUL_ASSERT( false, KUnknownDataType );
       
   290        }
       
   291 	return mVarData->mData.mReal;
       
   292 	}
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // map
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 OSN_EXPORT IAlfMap& MulVariantType::Map() const
       
   299 	{
       
   300 	if ( Type() != IMulVariantType::EMap ) 
       
   301        {
       
   302        __MUL_ASSERT( false, KUnknownDataType );
       
   303        }
       
   304 	return *mVarData->mData.mMap;
       
   305 	}
       
   306 
       
   307     }// namespace Alf	
       
   308 
       
   309 //End of file