Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

qgarray.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** $Id: qgarray.h,v 1.2 2003/07/10 02:40:11 llornkcor Exp $
00003 **
00004 ** Definition of QGArray class
00005 **
00006 ** Created : 930906
00007 **
00008 ** Copyright (C) 1992-2000 Trolltech AS.  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 AS 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.  IT IS PUBLIC BUT DO NOT USE IT IN NEW CODE.
00051     struct array_data : public QShared {        // shared array
00052         array_data():data(0),len(0)
00053 #ifdef QT_QGARRAY_SPEED_OPTIM
00054                     ,maxl(0)
00055 #endif
00056             {}
00057         char *data;                             // actual array data
00058         uint  len;
00059 #ifdef QT_QGARRAY_SPEED_OPTIM
00060         uint maxl;
00061 #endif
00062     };
00063     QGArray();
00064     enum Optimization { MemOptim, SpeedOptim };
00065 protected:
00066     QGArray( int, int );                        // dummy; does not alloc
00067     QGArray( int size );                        // allocate 'size' bytes
00068     QGArray( const QGArray &a );                // shallow copy
00069     virtual ~QGArray();
00070 
00071     QGArray    &operator=( const QGArray &a ) { return assign( a ); }
00072 
00073     virtual void detach()       { duplicate(*this); }
00074 
00075     // ### Qt 4.0: maybe provide two versions of data(), at(), etc.
00076     char       *data()   const  { return shd->data; }
00077     uint        nrefs()  const  { return shd->count; }
00078     uint        size()   const  { return shd->len; }
00079     bool        isEqual( const QGArray &a ) const;
00080 
00081     bool        resize( uint newsize, Optimization optim );
00082     bool        resize( uint newsize );
00083 
00084     bool        fill( const char *d, int len, uint sz );
00085 
00086     QGArray    &assign( const QGArray &a );
00087     QGArray    &assign( const char *d, uint len );
00088     QGArray    &duplicate( const QGArray &a );
00089     QGArray    &duplicate( const char *d, uint len );
00090     void        store( const char *d, uint len );
00091 
00092     array_data *sharedBlock()   const           { return shd; }
00093     void        setSharedBlock( array_data *p ) { shd=(array_data*)p; }
00094 
00095     QGArray    &setRawData( const char *d, uint len );
00096     void        resetRawData( const char *d, uint len );
00097 
00098     int         find( const char *d, uint index, uint sz ) const;
00099     int         contains( const char *d, uint sz ) const;
00100 
00101     void        sort( uint sz );
00102     int         bsearch( const char *d, uint sz ) const;
00103 
00104     char       *at( uint index ) const;
00105 
00106     bool        setExpand( uint index, const char *d, uint sz );
00107 
00108 protected:
00109     virtual array_data *newData();
00110     virtual void deleteData( array_data *p );
00111 
00112 private:
00113     static void msg_index( uint );
00114     array_data *shd;
00115 };
00116 
00117 
00118 inline char *QGArray::at( uint index ) const
00119 {
00120 #if defined(QT_CHECK_RANGE)
00121     if ( index >= size() ) {
00122         msg_index( index );
00123         index = 0;
00124     }
00125 #endif
00126     return &shd->data[index];
00127 }
00128 
00129 
00130 #endif // QGARRAY_H

Generated on Sat Nov 5 16:18:24 2005 for OPIE by  doxygen 1.4.2