/***************************************************************************
                            QXmlInputSource.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_QXmlInputSource.h>
#include <qtobjc/QXmlInputSource.h>
#include <qtobjc/QTextStream.h>
#include <qtobjc/QFile.h>
#include <qtobjc/QByteArray.h>

@implementation  QXmlInputSource

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

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

- initWithFile: (QFile *)file
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QXmlInputSource2((qt_QFile *) [file qt])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

- initWithTextStream: (QTextStream*)stream
{
	if ([self qt] == 0L) {
		[self setQt: qt_new_QXmlInputSource3((qt_QTextStream*) [stream qt])];
		[self setAllocatedInObjcWorld: YES];
		[QtSupport setObject: self forQtKey: [self qt]];
	}
	[super init];
	return self;
}

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

- setData: (NSString *)dat
{
static qt_QString * _qstring_dat = 0L;
	qt_QXmlInputSource_setData((qt_QXmlInputSource *)[self qt], (qt_QString *) [dat toQString: &_qstring_dat]);
	return self;
}

- setDataFromByteArray: (QByteArray*)dat
{
	qt_QXmlInputSource_setData1((qt_QXmlInputSource *)[self qt], (qt_QByteArray*) [dat qt]);
	return self;
}

- fetchData
{
	qt_QXmlInputSource_fetchData((qt_QXmlInputSource *)[self qt]);
	return self;
}

- (NSString *) data
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QXmlInputSource_data((qt_QXmlInputSource *)[self qt]);
	return [NSString fromQString: _qstring];
}

- (unichar*) next
{
	return (unichar*) qt_QXmlInputSource_next((qt_QXmlInputSource *)[self qt]);
}

- reset
{
	qt_QXmlInputSource_reset((qt_QXmlInputSource *)[self qt]);
	return self;
}

- (NSString *) fromRawData: (QByteArray*)data beginning: (BOOL)beginning
{
static qt_QString * _qstring = 0L;
	_qstring = qt_QXmlInputSource_fromRawData((qt_QXmlInputSource *)[self qt], (qt_QByteArray*) [data qt], (int)beginning);
	return [NSString fromQString: _qstring];
}

@end
