/***************************************************************************
                            QByteArray.m -  description
                             -------------------
    begin                : Wed Nov 21 12:08:37 2001
    copyright            : (C) 2000-2001 Lost Highway Ltd. All rights reserved.
    email                : Lost_Highway@tipitina.demon.co.uk
    generated by         : duke@tipitina on Wed Nov 21 12:08:37 2001, using kalyptus 0.9.
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This library is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 2 of the    *
 *   License, or (at your option) any later version.                       *
 *                                                                         *
 ***************************************************************************/

#include <qtc/qt_QString.h>
#include <qtc/qt_QCString.h>
#include <qtc/qt_QByteArray.h>
#include <qtobjc/QByteArray.h>

@implementation  QByteArray
- (void *) qt
{
	return _qt;
}

- setQt: (void *) qt
{
	_qt = qt;
	return self;
}

- (BOOL) allocatedInObjcWorld
{
	return _allocatedInObjcWorld;
}

- setAllocatedInObjcWorld: (BOOL) yn
{
	_allocatedInObjcWorld = yn;
	return self;
}


- init
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QByteArray()];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithInt: (int)size
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QByteArray1((int)size)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- copyWithZone: (NSZone *) zone
{
	QByteArray * aCopy;
	aCopy = [[(QByteArray *)[[self class] allocWithZone: zone] setQt: qt_new_QByteArray2([self qt])] init];
	[aCopy setAllocatedInObjcWorld: YES];
	[QtSupport setObject: aCopy forQtKey: [aCopy qt]];
	return aCopy;
}

- (void) dealloc
{
	if ([self allocatedInObjcWorld] && [self qt] != 0L) {
		[QtSupport removeQtKey: [self qt]];
		qt_del_QByteArray((qt_QByteArray *)[self qt]);
		[self setQt: 0L];
		[super dealloc];
	}
}

- (NSString *) data
{
	return (NSString *) [NSString stringWithCString: qt_QByteArray_data((qt_QByteArray *)[self qt])];
}

- (unsigned int) nrefs
{
	return (unsigned int) qt_QByteArray_nrefs((qt_QByteArray *)[self qt]);
}

- (unsigned int) size
{
	return (unsigned int) qt_QByteArray_size((qt_QByteArray *)[self qt]);
}

- (unsigned int) count
{
	return (unsigned int) qt_QByteArray_count((qt_QByteArray *)[self qt]);
}

- (BOOL) isEmpty
{
	return (BOOL) qt_QByteArray_isEmpty((qt_QByteArray *)[self qt]);
}

- (BOOL) isNull
{
	return (BOOL) qt_QByteArray_isNull((qt_QByteArray *)[self qt]);
}

- (BOOL) resize: (unsigned int)size
{
	return (BOOL) qt_QByteArray_resize((qt_QByteArray *)[self qt], (unsigned int)size);
}

- (BOOL) truncate: (unsigned int)pos
{
	return (BOOL) qt_QByteArray_truncate((qt_QByteArray *)[self qt], (unsigned int)pos);
}

- (BOOL) fill: (char)d size: (int)size
{
	return (BOOL) qt_QByteArray_fill((qt_QByteArray *)[self qt], (char)d, (int)size);
}

- (BOOL) fill: (char)d
{
	return (BOOL) qt_QByteArray_fill((qt_QByteArray *)[self qt], (char)d, -1);
}

- detach
{
	qt_QByteArray_detach((qt_QByteArray *)[self qt]);
	return self;
}

- (QByteArray*) copy
{
	return (QByteArray*) [QtSupport objectForQtKey: qt_QByteArray_copy((qt_QByteArray *)[self qt]) withClass: [QByteArray class] allocatedInObjcWorld: YES];
}

- (QByteArray*) assign: (QByteArray*)a
{
	return (QByteArray*) [QtSupport objectForQtKey: qt_QByteArray_assign((qt_QByteArray *)[self qt], (qt_QByteArray*) [a qt]) withClass: [QByteArray class] allocatedInObjcWorld: YES];
}

- (QByteArray*) assign: (NSString *)a n: (unsigned int)n
{
	return (QByteArray*) [QtSupport objectForQtKey: qt_QByteArray_assign1((qt_QByteArray *)[self qt], (char*) [a cString], (unsigned int)n) withClass: [QByteArray class] allocatedInObjcWorld: YES];
}

- (QByteArray*) duplicate: (QByteArray*)a
{
	return (QByteArray*) [QtSupport objectForQtKey: qt_QByteArray_duplicate((qt_QByteArray *)[self qt], (qt_QByteArray*) [a qt]) withClass: [QByteArray class] allocatedInObjcWorld: YES];
}

- (QByteArray*) duplicate: (NSString *)a n: (unsigned int)n
{
	return (QByteArray*) [QtSupport objectForQtKey: qt_QByteArray_duplicate1((qt_QByteArray *)[self qt], (char*) [a cString], (unsigned int)n) withClass: [QByteArray class] allocatedInObjcWorld: YES];
}

- (QByteArray*) setRawData: (NSString *)a n: (unsigned int)n
{
	return (QByteArray*) [QtSupport objectForQtKey: qt_QByteArray_setRawData((qt_QByteArray *)[self qt], (char*) [a cString], (unsigned int)n) withClass: [QByteArray class] allocatedInObjcWorld: YES];
}

- resetRawData: (NSString *)a n: (unsigned int)n
{
	qt_QByteArray_resetRawData((qt_QByteArray *)[self qt], (char*) [a cString], (unsigned int)n);
	return self;
}

//- (int) find: (char)d i: (unsigned int)i
//{
//	return (int) qt_QByteArray_find((qt_QByteArray *)[self qt], (char)d, (unsigned int)i);
//}

//- (int) find: (char)d
//{
//	return (int) qt_QByteArray_find((qt_QByteArray *)[self qt], (char)d, 0);
//}

//- (int) contains: (char)d
//{
//	return (int) qt_QByteArray_contains((qt_QByteArray *)[self qt], (char)d);
//}

- sort
{
	qt_QByteArray_sort((qt_QByteArray *)[self qt]);
	return self;
}

//- (int) bsearch: (char)d
//{
//	return (int) qt_QByteArray_bsearch((qt_QByteArray *)[self qt], (char)d);
//}

- (char) at: (unsigned int)i
{
	return (char) qt_QByteArray_at((qt_QByteArray *)[self qt], (unsigned int)i);
}

//- (Iterator*) begin
//{
//	return (Iterator*) qt_QByteArray_begin((qt_QByteArray *)[self qt]);
//}

//- (Iterator*) end
//{
//	return (Iterator*) qt_QByteArray_end((qt_QByteArray *)[self qt]);
//}

- (int) begin
{
	return (int) qt_QByteArray_begin1((qt_QByteArray *)[self qt]);
}

- (int) end
{
	return (int) qt_QByteArray_end1((qt_QByteArray *)[self qt]);
}

//- QArray: (int)arg1 int: (int)arg2
//{
//	qt_QByteArray_QArray((qt_QByteArray *)[self qt], (int)arg1, (int)arg2);
//	return self;
//}

@end
