photosgallery/inc/glxid.inl
changeset 0 4e91876724a2
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:    Type-safe unique id template
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "glxpanic.h"
       
    22 
       
    23 const TUint KGlxInvalidIdValue = KMaxTUint;
       
    24 
       
    25 // -----------------------------------------------------------------------------
       
    26 // Default constructor
       
    27 // -----------------------------------------------------------------------------
       
    28 //
       
    29 template <class T> 
       
    30 inline TGlxId<T>::TGlxId() 
       
    31     { 
       
    32     iIdValue = KGlxInvalidIdValue; 
       
    33     }
       
    34     
       
    35 // -----------------------------------------------------------------------------
       
    36 // Constructor
       
    37 // -----------------------------------------------------------------------------
       
    38 //
       
    39 template <class T> 
       
    40 inline TGlxId<T>::TGlxId(const TGlxId<T>& aId) 
       
    41     { 
       
    42     iIdValue = aId.iIdValue; 
       
    43     }
       
    44     
       
    45 // -----------------------------------------------------------------------------
       
    46 // Constructor
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 template <class T> 
       
    50 inline TGlxId<T>::TGlxId(TUint aIdValue) 
       
    51     { 
       
    52     __ASSERT_DEBUG(aIdValue != KGlxInvalidIdValue, Panic(EGlxPanicIllegalArgument)); 
       
    53     iIdValue = aIdValue; 
       
    54     }
       
    55         
       
    56 // -----------------------------------------------------------------------------
       
    57 // Constructor
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 template <class T> 
       
    61 inline TGlxId<T>::TGlxId(const TGlxIdNone&) 
       
    62     { 
       
    63     iIdValue = KGlxInvalidIdValue; 
       
    64     }
       
    65     
       
    66 // -----------------------------------------------------------------------------
       
    67 // Assignment, checks for invalid value
       
    68 // -----------------------------------------------------------------------------
       
    69 //
       
    70 template <class T> 
       
    71 inline TGlxId<T>& TGlxId<T>::operator=(const TGlxId<T>& aId) 
       
    72     { 
       
    73     __ASSERT_DEBUG(aId.iIdValue != KGlxInvalidIdValue, Panic(EGlxPanicIllegalArgument)); // Use SetValue to set undefined value
       
    74     iIdValue = aId.iIdValue; 
       
    75     return *this; 
       
    76     }
       
    77         
       
    78 // -----------------------------------------------------------------------------
       
    79 // Assignment, checks for invalid value
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 template <class T> 
       
    83 inline TGlxId<T>& TGlxId<T>::operator=(TUint aIdValue) 
       
    84     { 
       
    85     __ASSERT_DEBUG(aIdValue != KGlxInvalidIdValue, Panic(EGlxPanicIllegalArgument)); 
       
    86     iIdValue = aIdValue; 
       
    87     return *this; 
       
    88     }
       
    89         
       
    90 // -----------------------------------------------------------------------------
       
    91 // Assignment 
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 template <class T> 
       
    95 inline TGlxId<T>& TGlxId<T>::operator=(const TGlxIdNone&) 
       
    96     { 
       
    97     iIdValue = KGlxInvalidIdValue;  
       
    98     return *this; 
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // Post-increment
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 template <class T> 
       
   106 inline TGlxId<T> TGlxId<T>::operator++(int) 
       
   107     { 
       
   108     TUint value = iIdValue;
       
   109     iIdValue++; 
       
   110     return TGlxId<T>(value); 
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // Comparison
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 template <class T> 
       
   118 inline TBool TGlxId<T>::operator!=(const TGlxId<T>& aId) const 
       
   119     { 
       
   120     return iIdValue != aId.iIdValue; 
       
   121     }
       
   122     
       
   123 // -----------------------------------------------------------------------------
       
   124 // Comparison
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 template <class T> 
       
   128 inline TBool TGlxId<T>::operator==(const TGlxId<T>& aId) const 
       
   129     { 
       
   130     return iIdValue == aId.iIdValue; 
       
   131     }
       
   132     
       
   133 // -----------------------------------------------------------------------------
       
   134 // Comparison
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 template <class T> 
       
   138 inline TBool TGlxId<T>::operator!=(const TGlxIdNone&) const 
       
   139     { 
       
   140     return iIdValue != KGlxInvalidIdValue; 
       
   141     }
       
   142     
       
   143 // -----------------------------------------------------------------------------
       
   144 // Comparison
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 template <class T> 
       
   148 inline TBool TGlxId<T>::operator==(const TGlxIdNone&) const 
       
   149     { 
       
   150     return iIdValue == KGlxInvalidIdValue; 
       
   151     }
       
   152     
       
   153 // -----------------------------------------------------------------------------
       
   154 // Comparison
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 template <class T> 
       
   158 inline TBool TGlxId<T>::operator>(const TGlxId<T>& aId) const 
       
   159     { 
       
   160     return iIdValue > aId.iIdValue; 
       
   161     }
       
   162     
       
   163 // -----------------------------------------------------------------------------
       
   164 // Comparison
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 template <class T> 
       
   168 inline TBool TGlxId<T>::operator<(const TGlxId<T>& aId) const 
       
   169     { 
       
   170     return iIdValue < aId.iIdValue; 
       
   171     }
       
   172     
       
   173 // -----------------------------------------------------------------------------
       
   174 // Returns current value 
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 template <class T> 
       
   178 inline TUint TGlxId<T>::Value() const 
       
   179     { 
       
   180     return iIdValue; 
       
   181     }
       
   182     
       
   183 // -----------------------------------------------------------------------------
       
   184 // Allows setting undefined as value
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 template <class T> 
       
   188 inline void TGlxId<T>::SetValue(TUint aIdValue) 
       
   189     { 
       
   190     iIdValue = aIdValue; 
       
   191     }
       
   192 
       
   193 /**
       
   194  * TGlxDefaultIdProvider
       
   195  * Simple implementation of id provider
       
   196  */ 
       
   197 // -----------------------------------------------------------------------------
       
   198 // Allows setting undefined as value
       
   199 // -----------------------------------------------------------------------------
       
   200 //
       
   201 template <class T>
       
   202 TGlxDefaultIdProvider<T>::TGlxDefaultIdProvider() 
       
   203     { 
       
   204     iNextIdValue = 0; 
       
   205     }
       
   206     
       
   207 // -----------------------------------------------------------------------------
       
   208 // Allows setting undefined as value
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 template <class T>
       
   212 void TGlxDefaultIdProvider<T>::NextId(T& aId) 
       
   213     { 
       
   214     aId = iNextIdValue++; 
       
   215     }
       
   216