diff -r 000000000000 -r 4e91876724a2 photosgallery/inc/glxid.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/photosgallery/inc/glxid.h Thu Dec 17 08:45:44 2009 +0200 @@ -0,0 +1,101 @@ +/* +* 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 +* +*/ + + + + +#ifndef T_GLXID_H +#define T_GLXID_H + +#include "e32std.h" +#include "glxpanic.h" + +/** Invalid or undefined id value */ +// Use "id == KGlxIdNone" and "id != KGlxIdNone" to check for +// id validity. +class TGlxIdNone {}; +const TGlxIdNone KGlxIdNone = TGlxIdNone(); + +/** + * TGlxId + * + * Type-safe template for ids + * Id value of KMaxTUint is consided to be undefined. + * @usage Define like this: + * class TMyIdBase {}; + * typedef TGlxId TMyId; + * Now use can use TMyId in other code + */ +template +class TGlxId : public T { +public: + inline TGlxId(); + inline TGlxId(const TGlxId& aId); + inline TGlxId(TUint aIdValue); + inline TGlxId(const TGlxIdNone&); + inline TGlxId& operator=(const TGlxId& aId); + inline TGlxId& operator=(TUint aIdValue); + + inline TGlxId& operator=(const TGlxIdNone&); + inline TGlxId operator++(int); // Postfix, keep dummy parameter as int + inline TBool operator!=(const TGlxId& aId) const; + inline TBool operator==(const TGlxId& aId) const; + inline TBool operator!=(const TGlxIdNone&) const; + inline TBool operator==(const TGlxIdNone&) const; + inline TBool operator>(const TGlxId& aId) const; + inline TBool operator<(const TGlxId& aId) const; + + inline TUint Value() const; + inline void SetValue(TUint aIdValue); // Allows setting undefined as value (KMaxTUint) + +private: + TUint iIdValue; +}; + +/** + * MGlxIdProvider + * Abstract interface class to provide ids + * Define as MGlxIdProvider + */ +template +class MGlxIdProvider { +public: + /** + * getNextId + * Returns the next unique id. + * Returns value in the argument, since otherwise cannot have the same + * deriving class provide multiple different types of ids + */ + virtual void NextId(T& aId) = 0; +}; + +/** + * TGlxDefaultIdProvider + * Simple implementation of id provider + */ +template +class TGlxDefaultIdProvider : public MGlxIdProvider { +private: + TUint iNextIdValue; +public: + inline TGlxDefaultIdProvider(); + virtual void NextId(T& aId); +}; + +#include "glxid.inl" + +#endif // T_GLXID_H