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