diff -r 4ea6f81c838a -r 0e9bb658ef58 widgetmodel/alfwidgetmodel/src/alfattributecontainer.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/widgetmodel/alfwidgetmodel/src/alfattributecontainer.cpp Wed Sep 01 12:23:18 2010 +0100 @@ -0,0 +1,162 @@ +/* +* Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Implements the Container class for atrributes. +* +*/ + + +#include +#include +#include +#include "alf/alfattribute.h" +#include "alf/alfattributecontainer.h" +#include +#include +#include // from libc + +namespace Alf + { + + +/** + * Attribute container implementation. + */ +class AlfAttributeContainerImpl + { +public: + osncore::AlfPtrVector mAttributes; + AlfAttributeContainer::Type mType; + uint mTime; + }; + +// ======== MEMBER FUNCTIONS ======== + +// --------------------------------------------------------------------------- +// Constructor. +// --------------------------------------------------------------------------- +// + +OSN_EXPORT AlfAttributeContainer::AlfAttributeContainer(Type aType) : + mData(new (EMM) AlfAttributeContainerImpl()) + { + mData->mType = aType; + mData->mTime = 0; + } + +// --------------------------------------------------------------------------- +// Destructor. +// --------------------------------------------------------------------------- +// +OSN_EXPORT AlfAttributeContainer::~AlfAttributeContainer() + { + + } + +// --------------------------------------------------------------------------- +// Gets the type of the container. +// --------------------------------------------------------------------------- +// +OSN_EXPORT AlfAttributeContainer::Type AlfAttributeContainer::type() const + { + return mData->mType; + } + +// --------------------------------------------------------------------------- +// Adds a new attribute to the container. +// --------------------------------------------------------------------------- +// +OSN_EXPORT void AlfAttributeContainer::addAttribute(AlfAttribute* aAttribute) + { + mData->mAttributes.resize(mData->mAttributes.count() +1 ); + mData->mAttributes.insert(mData->mAttributes.count(), aAttribute); + } + +// --------------------------------------------------------------------------- +// Returns the attribute count. +// --------------------------------------------------------------------------- +// +OSN_EXPORT unsigned int AlfAttributeContainer::attributeCount()const + { + return mData->mAttributes.count(); + } + +// --------------------------------------------------------------------------- +// Returns the attribute. +// --------------------------------------------------------------------------- +// +OSN_EXPORT AlfAttribute& AlfAttributeContainer::getAttribute( + unsigned int aIndex) const + { + // invariant + assert(aIndex < mData->mAttributes.count()); + if (aIndex >= mData->mAttributes.count()) + { + ALF_THROW(AlfDataException,EInvalidAttribute,"AlfAttributeContainer") + } + + return *(mData->mAttributes[aIndex]); + } + +// --------------------------------------------------------------------------- +// Returns the attribute. +// --------------------------------------------------------------------------- +// +OSN_EXPORT AlfAttribute& AlfAttributeContainer::getAttributeByName( + const char * aName) const + { + for (TInt i=0; i < mData->mAttributes.count(); i++) + { + if (!strcmp(mData->mAttributes[i]->name(), aName)) + { + return *(mData->mAttributes[i]); + } + } + ALF_THROW(AlfDataException,EInvalidAttribute,"AlfAttributeContainer") + } + +// --------------------------------------------------------------------------- +// Removes the attribute. +// --------------------------------------------------------------------------- +// +OSN_EXPORT void AlfAttributeContainer::removeAttribute(unsigned int aIndex) + { + assert(aIndex < mData->mAttributes.count()); + if (aIndex >= mData->mAttributes.count()) + { + ALF_THROW(AlfDataException,EInvalidAttribute,"AlfAttributeContainer") + } + + mData->mAttributes.remove(aIndex); + } + +// --------------------------------------------------------------------------- +// Sets the animation time of the attribute container. +// --------------------------------------------------------------------------- +// +OSN_EXPORT void AlfAttributeContainer::setTime(unsigned int aTime) + { + mData->mTime = aTime; + } + +// --------------------------------------------------------------------------- +// Returns the animation time of the attribute container. +// --------------------------------------------------------------------------- +// +OSN_EXPORT unsigned int AlfAttributeContainer::getTime()const + { + return mData->mTime; + } + + } // Alf +