Eneboo - Documentación para desarrolladores
src/qt/include/qgarray.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qt/qgarray.h   3.3.8   edited Jan 11 14:38 $
00003 **
00004 ** Definition of QGArray 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 QGARRAY_H
00039 #define QGARRAY_H
00040 
00041 #ifndef QT_H
00042 #include "qshared.h"
00043 #endif // QT_H
00044 
00045 
00046 class Q_EXPORT QGArray                                  // generic array
00047 {
00048 friend class QBuffer;
00049 public:
00050     // do not use this, even though this is public
00051     // ### make protected or private in Qt 4.0 beta?
00052     struct array_data : public QShared {        // shared array
00053         array_data():data(0),len(0)
00054 #ifdef QT_QGARRAY_SPEED_OPTIM
00055                     ,maxl(0)
00056 #endif
00057             {}
00058         char *data;                             // actual array data
00059         uint  len;
00060 #ifdef QT_QGARRAY_SPEED_OPTIM
00061         uint maxl;
00062 #endif
00063     };
00064     QGArray();
00065     enum Optimization { MemOptim, SpeedOptim };
00066 protected:
00067     QGArray( int, int );                        // dummy; does not alloc
00068     QGArray( int size );                        // allocate 'size' bytes
00069     QGArray( const QGArray &a );                // shallow copy
00070     virtual ~QGArray();
00071 
00072     QGArray    &operator=( const QGArray &a ) { return assign( a ); }
00073 
00074     virtual void detach()       { duplicate(*this); }
00075 
00076     // ### Qt 4.0: maybe provide two versions of data(), at(), etc.
00077     char       *data()   const  { return shd->data; }
00078     uint        nrefs()  const  { return shd->count; }
00079     uint        size()   const  { return shd->len; }
00080     bool        isEqual( const QGArray &a ) const;
00081 
00082     bool        resize( uint newsize, Optimization optim );
00083     bool        resize( uint newsize );
00084 
00085     bool        fill( const char *d, int len, uint sz );
00086 
00087     QGArray    &assign( const QGArray &a );
00088     QGArray    &assign( const char *d, uint len );
00089     QGArray    &duplicate( const QGArray &a );
00090     QGArray    &duplicate( const char *d, uint len );
00091     void        store( const char *d, uint len );
00092 
00093     array_data *sharedBlock()   const           { return shd; }
00094     void        setSharedBlock( array_data *p ) { shd=(array_data*)p; }
00095 
00096     QGArray    &setRawData( const char *d, uint len );
00097     void        resetRawData( const char *d, uint len );
00098 
00099     int         find( const char *d, uint index, uint sz ) const;
00100     int         contains( const char *d, uint sz ) const;
00101 
00102     void        sort( uint sz );
00103     int         bsearch( const char *d, uint sz ) const;
00104 
00105     char       *at( uint index ) const;
00106 
00107     bool        setExpand( uint index, const char *d, uint sz );
00108 
00109 protected:
00110     virtual array_data *newData();
00111     virtual void deleteData( array_data *p );
00112 
00113 private:
00114     static void msg_index( uint );
00115     array_data *shd;
00116 };
00117 
00118 
00119 inline char *QGArray::at( uint index ) const
00120 {
00121 #if defined(QT_CHECK_RANGE)
00122     if ( index >= size() ) {
00123         msg_index( index );
00124         index = 0;
00125     }
00126 #endif
00127     return &shd->data[index];
00128 }
00129 
00130 
00131 #endif // QGARRAY_H
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'