wlan_bearer/wlanldd/wlan_common/umac_common/inc/umaccarraypolicy.h
changeset 0 c40eb8fe8501
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     1 /*
       
     2 * Copyright (c) 2005-2007 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 the License "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:   Policies for constant size arrays class template 
       
    15 *                (see umaccarray.h). 
       
    16 *
       
    17 */
       
    18 
       
    19 /*
       
    20 * %version: 10 %
       
    21 */
       
    22 
       
    23 #ifndef _POLICYCARRAY_H
       
    24 #define _POLICYCARRAY_H
       
    25 
       
    26 /*
       
    27  *
       
    28  * Copy ctor and assignment operator policies 4 Carray
       
    29  *
       
    30  * @usage examples:
       
    31  *
       
    32  *       Carray<int* , 2, true, DeepCopy<int> > obj;
       
    33  *       Carray<int* , 2, true, DeepCopy<int> > obj2;
       
    34  *       obj[0] = new int(1);
       
    35  *       obj[1] = new int(2); 
       
    36  *       // test deep copy
       
    37  *       Carray<int* , 2, true, DeepCopy<int> > obj6(obj);
       
    38  *       // test deep assignment
       
    39  *       obj2 = obj6;
       
    40  *
       
    41  *       Carray<int , 2> obj3;
       
    42  *       Carray<int , 2> obj4;
       
    43  *       obj3[0] = 1;
       
    44  *       obj3[1] = 2;
       
    45  *       // test shallow copy
       
    46  *       Carray<int , 2> obj5(obj3);
       
    47  *       // test shallow assignment
       
    48  *      obj4 = obj3;
       
    49  *
       
    50  *       Carray<clonable* , 2, true, CloneCopy<clonable> > obj7;
       
    51  *       Carray<clonable* , 2, true, CloneCopy<clonable> > obj9;
       
    52  *       obj7[0] = new clonable(1);
       
    53  *       obj7[1] = new clonable(2);
       
    54  *       // test clone copy
       
    55  *       Carray<clonable* , 2, true, CloneCopy<clonable> > obj8(obj7);
       
    56  *       // test clone assignment
       
    57  *       obj9 = obj7;
       
    58  *
       
    59  *       Carray<int , 2, false, NoCopy<int> > obj10;
       
    60  *       Carray<int , 2, false, NoCopy<int> > obj11;
       
    61  *       // does not compile as it should not
       
    62  *       obj10 = obj11;
       
    63  */
       
    64 
       
    65 #include "algorithm.h"
       
    66 
       
    67 // normal shallow copy
       
    68 template <class T>
       
    69 struct ShallowCopy
       
    70 {
       
    71 typedef T* iterator;
       
    72 
       
    73         static void Copy(iterator srcbegin, iterator srcend, iterator trgbegin)
       
    74         {
       
    75                 copy(srcbegin, srcend, trgbegin);
       
    76         }
       
    77 };
       
    78 
       
    79 // calls Clone() 4 copy
       
    80 template <class T>
       
    81 struct CloneCopy
       
    82 {
       
    83 typedef T** iterator;
       
    84 
       
    85         static void Copy(iterator srcbegin, iterator srcend, iterator trgbegin)
       
    86         {
       
    87                 while(srcbegin != srcend)
       
    88                 {
       
    89                         *trgbegin = (*srcbegin)->Clone();
       
    90 
       
    91                         ++srcbegin;
       
    92                         ++trgbegin;
       
    93                 }
       
    94         }
       
    95 };
       
    96 
       
    97 // just what name states copying and assignment are not allowed
       
    98 template <class T>
       
    99 struct NoCopy {};
       
   100 
       
   101 // global new and delete operators
       
   102 struct OpNewAlloc
       
   103 {
       
   104         static void* operator new(size_t size)
       
   105         {
       
   106                 return ::operator new(size);
       
   107         }
       
   108         
       
   109         static void operator delete(void* p , size_t /*size*/)
       
   110         {
       
   111                 ::operator delete(p);
       
   112         }
       
   113 };
       
   114 
       
   115 #endif //_POLICYCARRAY_H