/***************************************************************************
                            QDataStream.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_QDataStream.h>
#include <qtobjc/QDataStream.h>
#include <qtobjc/QIODevice.h>

#include <qtobjc/QByteArray.h>

@implementation  QDataStream

- (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_QDataStream()];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithIODevice: (QIODevice *)arg1
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QDataStream1((qt_QIODevice *) [arg1 qt])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithByteArray: (QByteArray*)arg1 mode: (int)mode
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QDataStream2((qt_QByteArray*) [arg1 qt], (int)mode)];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

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

- (QIODevice*) device
{
	return (QIODevice*) [QtSupport objectForQtKey: qt_QDataStream_device((qt_QDataStream *)[self qt]) withClass: [QIODevice class] allocatedInObjcWorld: YES];
}

- setDevice: (QIODevice *)arg1
{
	qt_QDataStream_setDevice((qt_QDataStream *)[self qt], (qt_QIODevice *) [arg1 qt]);
	return self;
}

- unsetDevice
{
	qt_QDataStream_unsetDevice((qt_QDataStream *)[self qt]);
	return self;
}

- (BOOL) atEnd
{
	return (BOOL) qt_QDataStream_atEnd((qt_QDataStream *)[self qt]);
}

- (BOOL) eof
{
	return (BOOL) qt_QDataStream_eof((qt_QDataStream *)[self qt]);
}

- (int) byteOrder
{
	return (int) qt_QDataStream_byteOrder((qt_QDataStream *)[self qt]);
}

- setByteOrder: (int)arg1
{
	qt_QDataStream_setByteOrder((qt_QDataStream *)[self qt], (int)arg1);
	return self;
}

- (BOOL) isPrintableData
{
	return (BOOL) qt_QDataStream_isPrintableData((qt_QDataStream *)[self qt]);
}

- setPrintableData: (BOOL)arg1
{
	qt_QDataStream_setPrintableData((qt_QDataStream *)[self qt], (int)arg1);
	return self;
}

- (int) version
{
	return (int) qt_QDataStream_version((qt_QDataStream *)[self qt]);
}

- setVersion: (int)arg1
{
	qt_QDataStream_setVersion((qt_QDataStream *)[self qt], (int)arg1);
	return self;
}

- (QDataStream*) readBytes: (NSString *)arg1 len: (unsigned int)len
{
	return (QDataStream*) [QtSupport objectForQtKey: qt_QDataStream_readBytes((qt_QDataStream *)[self qt], (char*) [arg1 cString], (unsigned int)len) withClass: [QDataStream class] allocatedInObjcWorld: YES];
}

- (QDataStream*) readRawBytes: (NSString *)arg1 len: (unsigned int)len
{
	return (QDataStream*) [QtSupport objectForQtKey: qt_QDataStream_readRawBytes((qt_QDataStream *)[self qt], (char*) [arg1 cString], (unsigned int)len) withClass: [QDataStream class] allocatedInObjcWorld: YES];
}

- (QDataStream*) writeBytes: (NSString *)arg1 len: (unsigned int)len
{
	return (QDataStream*) [QtSupport objectForQtKey: qt_QDataStream_writeBytes((qt_QDataStream *)[self qt], (char*) [arg1 cString], (unsigned int)len) withClass: [QDataStream class] allocatedInObjcWorld: YES];
}

- (QDataStream*) writeRawBytes: (NSString *)arg1 len: (unsigned int)len
{
	return (QDataStream*) [QtSupport objectForQtKey: qt_QDataStream_writeRawBytes((qt_QDataStream *)[self qt], (char*) [arg1 cString], (unsigned int)len) withClass: [QDataStream class] allocatedInObjcWorld: YES];
}

+ (int) BigEndian
{
	return (int) QDATASTREAM_BigEndian;
}

+ (int) LittleEndian
{
	return (int) QDATASTREAM_LittleEndian;
}

@end
