Eneboo - Documentación para desarrolladores
src/qt/src/tools/qmemarray.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qt/qmemarray.h   3.3.8   edited Jan 11 14:38 $
00003 **
00004 ** Definition of QMemArray template/macro class
00005 **
00006 ** Created : 930906
00007 **
00008 ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
00009 **
00010 ** This file is part of the tools module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech ASA of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00022 ** licenses may use this file in accordance with the Qt Commercial License
00023 ** Agreement provided with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
00035 **
00036 **********************************************************************/
00037 
00038 #ifndef QMEMARRAY_H
00039 #define QMEMARRAY_H
00040 
00041 #ifndef QT_H
00042 #include "qgarray.h"
00043 #endif // QT_H
00044 
00045 
00046 template<class type>
00047 class QMemArray : public QGArray
00048 {
00049 public:
00050     typedef type* Iterator;
00051     typedef const type* ConstIterator;
00052     typedef type ValueType;
00053 
00054 protected:
00055     QMemArray( int, int ) : QGArray( 0, 0 ) {}
00056 
00057 public:
00058     QMemArray() {}
00059     QMemArray( int size ) : QGArray(size*sizeof(type)) {} // ### 4.0 Q_EXPLICIT
00060     QMemArray( const QMemArray<type> &a ) : QGArray(a) {}
00061    ~QMemArray() {}
00062     QMemArray<type> &operator=(const QMemArray<type> &a)
00063                                 { return (QMemArray<type>&)QGArray::assign(a); }
00064     type *data()    const       { return (type *)QGArray::data(); }
00065     uint  nrefs()   const       { return QGArray::nrefs(); }
00066     uint  size()    const       { return QGArray::size()/sizeof(type); }
00067     uint  count()   const       { return size(); }
00068     bool  isEmpty() const       { return QGArray::size() == 0; }
00069     bool  isNull()  const       { return QGArray::data() == 0; }
00070     bool  resize( uint size )   { return QGArray::resize(size*sizeof(type)); }
00071     bool  resize( uint size, Optimization optim ) { return QGArray::resize(size*sizeof(type), optim); }
00072     bool  truncate( uint pos )  { return QGArray::resize(pos*sizeof(type)); }
00073     bool  fill( const type &d, int size = -1 )
00074         { return QGArray::fill((char*)&d,size,sizeof(type) ); }
00075     void  detach()              { QGArray::detach(); }
00076     QMemArray<type>   copy() const
00077         { QMemArray<type> tmp; return tmp.duplicate(*this); }
00078     QMemArray<type>& assign( const QMemArray<type>& a )
00079         { return (QMemArray<type>&)QGArray::assign(a); }
00080     QMemArray<type>& assign( const type *a, uint n )
00081         { return (QMemArray<type>&)QGArray::assign((char*)a,n*sizeof(type)); }
00082     QMemArray<type>& duplicate( const QMemArray<type>& a )
00083         { return (QMemArray<type>&)QGArray::duplicate(a); }
00084     QMemArray<type>& duplicate( const type *a, uint n )
00085         { return (QMemArray<type>&)QGArray::duplicate((char*)a,n*sizeof(type)); }
00086     QMemArray<type>& setRawData( const type *a, uint n )
00087         { return (QMemArray<type>&)QGArray::setRawData((char*)a,
00088                                                      n*sizeof(type)); }
00089     void resetRawData( const type *a, uint n )
00090         { QGArray::resetRawData((char*)a,n*sizeof(type)); }
00091     int  find( const type &d, uint i=0 ) const
00092         { return QGArray::find((char*)&d,i,sizeof(type)); }
00093     int  contains( const type &d ) const
00094         { return QGArray::contains((char*)&d,sizeof(type)); }
00095     void sort() { QGArray::sort(sizeof(type)); }
00096     int  bsearch( const type &d ) const
00097         { return QGArray::bsearch((const char*)&d,sizeof(type)); }
00098     // ### Qt 4.0: maybe provide uint overload as work-around for MSVC bug
00099     type& operator[]( int i ) const
00100         { return (type &)(*(type *)QGArray::at(i*sizeof(type))); }
00101     type& at( uint i ) const
00102         { return (type &)(*(type *)QGArray::at(i*sizeof(type))); }
00103          operator const type*() const { return (const type *)QGArray::data(); }
00104     bool operator==( const QMemArray<type> &a ) const { return isEqual(a); }
00105     bool operator!=( const QMemArray<type> &a ) const { return !isEqual(a); }
00106     Iterator begin() { return data(); }
00107     Iterator end() { return data() + size(); }
00108     ConstIterator begin() const { return data(); }
00109     ConstIterator end() const { return data() + size(); }
00110 };
00111 
00112 #ifndef QT_NO_COMPAT
00113 #define QArray QMemArray
00114 #endif
00115 
00116 #define Q_DEFINED_QMEMARRAY
00117 #include "qwinexport.h"
00118 #endif // QARRAY_H
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'