Blame qtools/qgarray.h

Packit Service 50c9f2
/****************************************************************************
Packit Service 50c9f2
** 
Packit Service 50c9f2
**
Packit Service 50c9f2
** Definition of QGArray class
Packit Service 50c9f2
**
Packit Service 50c9f2
** Created : 930906
Packit Service 50c9f2
**
Packit Service 50c9f2
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file is part of the tools module of the Qt GUI Toolkit.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file may be distributed under the terms of the Q Public License
Packit Service 50c9f2
** as defined by Trolltech AS of Norway and appearing in the file
Packit Service 50c9f2
** LICENSE.QPL included in the packaging of this file.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file may be distributed and/or modified under the terms of the
Packit Service 50c9f2
** GNU General Public License version 2 as published by the Free Software
Packit Service 50c9f2
** Foundation and appearing in the file LICENSE.GPL included in the
Packit Service 50c9f2
** packaging of this file.
Packit Service 50c9f2
**
Packit Service 50c9f2
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
Packit Service 50c9f2
** licenses may use this file in accordance with the Qt Commercial License
Packit Service 50c9f2
** Agreement provided with the Software.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
Packit Service 50c9f2
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Packit Service 50c9f2
**
Packit Service 50c9f2
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
Packit Service 50c9f2
**   information about Qt Commercial License Agreements.
Packit Service 50c9f2
** See http://www.trolltech.com/qpl/ for QPL licensing information.
Packit Service 50c9f2
** See http://www.trolltech.com/gpl/ for GPL licensing information.
Packit Service 50c9f2
**
Packit Service 50c9f2
** Contact info@trolltech.com if any conditions of this licensing are
Packit Service 50c9f2
** not clear to you.
Packit Service 50c9f2
**
Packit Service 50c9f2
**********************************************************************/
Packit Service 50c9f2
Packit Service 50c9f2
#ifndef QGARRAY_H
Packit Service 50c9f2
#define QGARRAY_H
Packit Service 50c9f2
Packit Service 50c9f2
#ifndef QT_H
Packit Service 50c9f2
#include "qshared.h"
Packit Service 50c9f2
#endif // QT_H
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
class Q_EXPORT QGArray					// generic array
Packit Service 50c9f2
{
Packit Service 50c9f2
friend class QBuffer;
Packit Service 50c9f2
public:
Packit Service 50c9f2
    //### DO NOT USE THIS.  IT IS PUBLIC BUT DO NOT USE IT IN NEW CODE.
Packit Service 50c9f2
    struct array_data : public QShared {	// shared array
Packit Service 50c9f2
	array_data()	{ data=0; len=0; }
Packit Service 50c9f2
	char *data;				// actual array data
Packit Service 50c9f2
	uint  len;
Packit Service 50c9f2
    };
Packit Service 50c9f2
    QGArray();
Packit Service 50c9f2
protected:
Packit Service 50c9f2
    QGArray( int, int );			// dummy; does not alloc
Packit Service 50c9f2
    QGArray( int size );			// allocate 'size' bytes
Packit Service 50c9f2
    QGArray( const QGArray &a );		// shallow copy
Packit Service 50c9f2
    virtual ~QGArray();
Packit Service 50c9f2
Packit Service 50c9f2
    QGArray    &operator=( const QGArray &a ) { return assign( a ); }
Packit Service 50c9f2
Packit Service 50c9f2
    virtual void detach()	{ duplicate(*this); }
Packit Service 50c9f2
Packit Service 50c9f2
    char       *data()	 const	{ return shd->data; }
Packit Service 50c9f2
    uint	nrefs()	 const	{ return shd->count; }
Packit Service 50c9f2
    uint	size()	 const	{ return shd->len; }
Packit Service 50c9f2
    bool	isEqual( const QGArray &a ) const;
Packit Service 50c9f2
Packit Service 50c9f2
    bool	resize( uint newsize );
Packit Service 50c9f2
Packit Service 50c9f2
    bool	fill( const char *d, int len, uint sz );
Packit Service 50c9f2
Packit Service 50c9f2
    QGArray    &assign( const QGArray &a );
Packit Service 50c9f2
    QGArray    &assign( const char *d, uint len );
Packit Service 50c9f2
    QGArray    &duplicate( const QGArray &a );
Packit Service 50c9f2
    QGArray    &duplicate( const char *d, uint len );
Packit Service 50c9f2
    void	store( const char *d, uint len );
Packit Service 50c9f2
Packit Service 50c9f2
    array_data *sharedBlock()	const		{ return shd; }
Packit Service 50c9f2
    void	setSharedBlock( array_data *p ) { shd=(array_data*)p; }
Packit Service 50c9f2
Packit Service 50c9f2
    QGArray    &setRawData( const char *d, uint len );
Packit Service 50c9f2
    void	resetRawData( const char *d, uint len );
Packit Service 50c9f2
Packit Service 50c9f2
    int		find( const char *d, uint index, uint sz ) const;
Packit Service 50c9f2
    int		contains( const char *d, uint sz ) const;
Packit Service 50c9f2
    
Packit Service 50c9f2
    void	sort( uint sz );
Packit Service 50c9f2
    int		bsearch( const char *d, uint sz ) const;
Packit Service 50c9f2
Packit Service 50c9f2
    char       *at( uint index ) const;
Packit Service 50c9f2
Packit Service 50c9f2
    bool	setExpand( uint index, const char *d, uint sz );
Packit Service 50c9f2
Packit Service 50c9f2
protected:
Packit Service 50c9f2
    virtual array_data *newData();
Packit Service 50c9f2
    virtual void deleteData( array_data *p );
Packit Service 50c9f2
Packit Service 50c9f2
private:
Packit Service 50c9f2
    static void msg_index( uint );
Packit Service 50c9f2
    array_data *shd;
Packit Service 50c9f2
};
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
inline char *QGArray::at( uint index ) const
Packit Service 50c9f2
{
Packit Service 50c9f2
#if defined(CHECK_RANGE)
Packit Service 50c9f2
    if ( index >= size() ) {
Packit Service 50c9f2
	msg_index( index );
Packit Service 50c9f2
	index = 0;
Packit Service 50c9f2
    }
Packit Service 50c9f2
#endif
Packit Service 50c9f2
    return &shd->data[index];
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
#endif // QGARRAY_H