wlan_bearer/wlanldd/wlan_common/osa_common/inc/osacarray.h
changeset 0 c40eb8fe8501
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     1 /*
       
     2 * Copyright (c) 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:   wrapper on top of C array with C++ STL interface
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 3 %
       
    20 */
       
    21 
       
    22 #ifndef WLANCARRAY_H
       
    23 #define WLANCARRAY_H
       
    24 
       
    25 #include "algorithm.h"
       
    26 
       
    27 #include "osacarraypolicy.h"
       
    28 
       
    29 /**
       
    30  *  wrapper on top of C array with C++ STL interface
       
    31  *
       
    32  *
       
    33  *  @lib wlanosa.lib
       
    34  *  @since S60 v3.2
       
    35  */
       
    36 template
       
    37 <
       
    38     class T, 
       
    39     TInt the_size,
       
    40     // check out osacarraypolicy.h 4 these
       
    41     class CopyingPolicy = NoCopy<T>
       
    42 > 
       
    43 class Carray : protected CopyingPolicy, public DBase
       
    44     {
       
    45 
       
    46 	typedef Carray<T, the_size, CopyingPolicy> Self;
       
    47 
       
    48 public:
       
    49 
       
    50 	// type definitions
       
    51 	typedef T		    value_type;
       
    52 	typedef T*		    iterator;
       
    53 	typedef const T*	const_iterator;
       
    54 	typedef T&		    reference;
       
    55 	typedef const T&	const_reference;
       
    56 	typedef TInt	    size_type;
       
    57 	
       
    58     /**
       
    59      * Constructor.
       
    60      *
       
    61      * @since S60 v3.2
       
    62      */
       
    63 	Carray() {};
       
    64 
       
    65     /**
       
    66      * Constructor. Construct with inital data
       
    67      *
       
    68      * @since S60 v3.2
       
    69      * @param aP initial data
       
    70      */
       
    71 	explicit inline Carray( T* aP ) { copy( aP, aP + the_size, begin()); }
       
    72 
       
    73     /**
       
    74      * returns iterator to begin of the sequence
       
    75      *
       
    76      * @since S60 v3.2
       
    77      * @return iterator to begin of the sequence
       
    78      */
       
    79     inline iterator begin() { return v; }
       
    80 
       
    81     /**
       
    82      * returns const iterator to begin of the sequence
       
    83      *
       
    84      * @since S60 v3.2
       
    85      * @return const iterator to begin of the sequence
       
    86      */
       
    87     inline const_iterator begin() const { return v; }
       
    88 
       
    89     /**
       
    90      * returns iterator to end of the sequence
       
    91      *
       
    92      * @since S60 v3.2
       
    93      * @return iterator to end of the sequence
       
    94      */
       
    95     inline iterator end() { return v + the_size; }
       
    96 
       
    97     /**
       
    98      * returns const iterator to end of the sequence
       
    99      *
       
   100      * @since S60 v3.2
       
   101      * @return const iterator to end of the sequence
       
   102      */
       
   103     inline const_iterator end() const { return v + the_size; }
       
   104 
       
   105     /**
       
   106      * returns size of the storage
       
   107      *
       
   108      * @since S60 v3.2
       
   109      * @return size of the storage
       
   110      */
       
   111     inline size_type size() const { return the_size; }
       
   112 
       
   113     /**
       
   114      * returns max size of the storage
       
   115      *
       
   116      * @since S60 v3.2
       
   117      * @return max size of the storage
       
   118      */
       
   119     inline size_type max_size() const { return the_size; }
       
   120 
       
   121     /**
       
   122      * non const [] operator access
       
   123      *
       
   124      * @since S60 v3.2
       
   125      * @return non const reference to element
       
   126      */
       
   127     inline reference operator[](TInt i) { return v[i]; } 
       
   128 
       
   129     /**
       
   130      * const [] operator access
       
   131      *
       
   132      * @since S60 v3.2
       
   133      * @return const reference to element
       
   134      */
       
   135     inline const_reference operator[](TInt i) const { return v[i]; } 
       
   136 
       
   137     /**
       
   138      * return non const reference to front of sequence
       
   139      *
       
   140      * @since S60 v3.2
       
   141      * @return non const reference to front of sequence
       
   142      */
       
   143     inline reference front() { return v[0]; }
       
   144 
       
   145     /**
       
   146      * return const reference to front of sequence
       
   147      *
       
   148      * @since S60 v3.2
       
   149      * @return const reference to front of sequence
       
   150      */
       
   151     inline const_reference front() const { return v[0]; }
       
   152 
       
   153     /**
       
   154      * return non const reference to back of sequence
       
   155      *
       
   156      * @since S60 v3.2
       
   157      * @return non const reference to back of sequence
       
   158      */
       
   159     inline reference back() { return v[the_size-1]; }
       
   160 
       
   161     /**
       
   162      * return const reference to back of sequence
       
   163      *
       
   164      * @since S60 v3.2
       
   165      * @return const reference to back of sequence
       
   166      */
       
   167     inline const_reference back() const { return v[the_size-1]; }
       
   168 
       
   169     /**
       
   170      * conversion to ordinary array
       
   171      *
       
   172      * @since S60 v3.2
       
   173      * @return const pointer to begin of the sequence
       
   174      */
       
   175     inline const T* data() const { return v; }
       
   176 
       
   177     /**
       
   178      * conversion to ordinary array
       
   179      *
       
   180      * @since S60 v3.2
       
   181      * @return non const pointer to begin of the sequence
       
   182      */
       
   183     inline T* data() { return v; }
       
   184 
       
   185     /**
       
   186      * assignment operator
       
   187      *
       
   188      * @since S60 v3.2
       
   189      */
       
   190 	Self& operator=( const Self& );
       
   191 
       
   192     /**
       
   193      * copy constructor
       
   194      *
       
   195      * @since S60 v3.2
       
   196      */
       
   197     inline Carray( const Self& o ) 
       
   198         { 
       
   199         Copy( 
       
   200             const_cast<iterator>(o.begin()), 
       
   201             const_cast<iterator>(o.end()), 
       
   202             begin() ); 
       
   203         }
       
   204 
       
   205 private:
       
   206 
       
   207 	T v[the_size];
       
   208 };
       
   209 
       
   210 #include "osacarray.inl"
       
   211 
       
   212 #endif // WLANCARRAY_H