diff -r ea65f74e6de4 -r 8e5f6eea9c9f inc/glxid.inl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inc/glxid.inl Tue Aug 31 15:14:51 2010 +0300 @@ -0,0 +1,215 @@ +/* +* Copyright (c) 2008-2009 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: Type-safe unique id template +* +*/ + + + +#include "glxpanic.h" + +const TUint KGlxInvalidIdValue = KMaxTUint; + +// ----------------------------------------------------------------------------- +// Default constructor +// ----------------------------------------------------------------------------- +// +template +inline TGlxId::TGlxId() + { + iIdValue = KGlxInvalidIdValue; + } + +// ----------------------------------------------------------------------------- +// Constructor +// ----------------------------------------------------------------------------- +// +template +inline TGlxId::TGlxId(const TGlxId& aId) + { + iIdValue = aId.iIdValue; + } + +// ----------------------------------------------------------------------------- +// Constructor +// ----------------------------------------------------------------------------- +// +template +inline TGlxId::TGlxId(TUint aIdValue) + { + __ASSERT_DEBUG(aIdValue != KGlxInvalidIdValue, Panic(EGlxPanicIllegalArgument)); + iIdValue = aIdValue; + } + +// ----------------------------------------------------------------------------- +// Constructor +// ----------------------------------------------------------------------------- +// +template +inline TGlxId::TGlxId(const TGlxIdNone&) + { + iIdValue = KGlxInvalidIdValue; + } + +// ----------------------------------------------------------------------------- +// Assignment, checks for invalid value +// ----------------------------------------------------------------------------- +// +template +inline TGlxId& TGlxId::operator=(const TGlxId& aId) + { + __ASSERT_DEBUG(aId.iIdValue != KGlxInvalidIdValue, Panic(EGlxPanicIllegalArgument)); // Use SetValue to set undefined value + iIdValue = aId.iIdValue; + return *this; + } + +// ----------------------------------------------------------------------------- +// Assignment, checks for invalid value +// ----------------------------------------------------------------------------- +// +template +inline TGlxId& TGlxId::operator=(TUint aIdValue) + { + __ASSERT_DEBUG(aIdValue != KGlxInvalidIdValue, Panic(EGlxPanicIllegalArgument)); + iIdValue = aIdValue; + return *this; + } + +// ----------------------------------------------------------------------------- +// Assignment +// ----------------------------------------------------------------------------- +// +template +inline TGlxId& TGlxId::operator=(const TGlxIdNone&) + { + iIdValue = KGlxInvalidIdValue; + return *this; + } + +// ----------------------------------------------------------------------------- +// Post-increment +// ----------------------------------------------------------------------------- +// +template +inline TGlxId TGlxId::operator++(int) + { + TUint value = iIdValue; + iIdValue++; + return TGlxId(value); + } + +// ----------------------------------------------------------------------------- +// Comparison +// ----------------------------------------------------------------------------- +// +template +inline TBool TGlxId::operator!=(const TGlxId& aId) const + { + return iIdValue != aId.iIdValue; + } + +// ----------------------------------------------------------------------------- +// Comparison +// ----------------------------------------------------------------------------- +// +template +inline TBool TGlxId::operator==(const TGlxId& aId) const + { + return iIdValue == aId.iIdValue; + } + +// ----------------------------------------------------------------------------- +// Comparison +// ----------------------------------------------------------------------------- +// +template +inline TBool TGlxId::operator!=(const TGlxIdNone&) const + { + return iIdValue != KGlxInvalidIdValue; + } + +// ----------------------------------------------------------------------------- +// Comparison +// ----------------------------------------------------------------------------- +// +template +inline TBool TGlxId::operator==(const TGlxIdNone&) const + { + return iIdValue == KGlxInvalidIdValue; + } + +// ----------------------------------------------------------------------------- +// Comparison +// ----------------------------------------------------------------------------- +// +template +inline TBool TGlxId::operator>(const TGlxId& aId) const + { + return iIdValue > aId.iIdValue; + } + +// ----------------------------------------------------------------------------- +// Comparison +// ----------------------------------------------------------------------------- +// +template +inline TBool TGlxId::operator<(const TGlxId& aId) const + { + return iIdValue < aId.iIdValue; + } + +// ----------------------------------------------------------------------------- +// Returns current value +// ----------------------------------------------------------------------------- +// +template +inline TUint TGlxId::Value() const + { + return iIdValue; + } + +// ----------------------------------------------------------------------------- +// Allows setting undefined as value +// ----------------------------------------------------------------------------- +// +template +inline void TGlxId::SetValue(TUint aIdValue) + { + iIdValue = aIdValue; + } + +/** + * TGlxDefaultIdProvider + * Simple implementation of id provider + */ +// ----------------------------------------------------------------------------- +// Allows setting undefined as value +// ----------------------------------------------------------------------------- +// +template +TGlxDefaultIdProvider::TGlxDefaultIdProvider() + { + iNextIdValue = 0; + } + +// ----------------------------------------------------------------------------- +// Allows setting undefined as value +// ----------------------------------------------------------------------------- +// +template +void TGlxDefaultIdProvider::NextId(T& aId) + { + aId = iNextIdValue++; + } +