- removed the File class in favor of QFile

Wed, 08 Jan 2014 21:43:46 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Wed, 08 Jan 2014 21:43:46 +0200
changeset 609
a8dc74a809c6
parent 608
487db37f0bb3
child 610
f8244301110d

- removed the File class in favor of QFile

src/document.cc file | annotate | diff | comparison | revisions
src/document.h file | annotate | diff | comparison | revisions
src/extprogs.cc file | annotate | diff | comparison | revisions
src/gui_actions.cc file | annotate | diff | comparison | revisions
src/ldconfig.cc file | annotate | diff | comparison | revisions
src/ldtypes.h file | annotate | diff | comparison | revisions
src/main.cc file | annotate | diff | comparison | revisions
src/primitives.cc file | annotate | diff | comparison | revisions
src/types.cc file | annotate | diff | comparison | revisions
src/types.h file | annotate | diff | comparison | revisions
--- a/src/document.cc	Wed Jan 08 13:57:10 2014 +0200
+++ b/src/document.cc	Wed Jan 08 21:43:46 2014 +0200
@@ -222,10 +222,8 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-File* openLDrawFile (QString relpath, bool subdirs)
+static QString findLDrawFilePath (QString relpath, bool subdirs)
 {
-	log ("Opening %1...\n", relpath);
-	File* f = new File;
 	QString fullPath;
 
 	// LDraw models use Windows-style path separators. If we're not on Windows,
@@ -238,14 +236,16 @@
 	// Try find it relative to other currently open documents. We want a file
 	// in the immediate vicinity of a current model to override stock LDraw stuff.
 	QString reltop = basename (dirname (relpath));
+
 	for (LDDocument* doc : g_loadedFiles)
 	{
 		if (doc->getFullPath().isEmpty())
 			continue;
 
 		QString partpath = fmt ("%1/%2", dirname (doc->getFullPath()), relpath);
+		QFile f (partpath);
 
-		if (f->open (partpath, File::Read))
+		if (f.exists())
 		{
 			// ensure we don't mix subfiles and 48-primitives with non-subfiles and non-48
 			QString proptop = basename (dirname (partpath));
@@ -262,18 +262,18 @@
 			}
 
 			if (!bogus)
-				return f;
+				return partpath;
 		}
 	}
 
-	if (f->open (relpath, File::Read))
-		return f;
+	if (QFile::exists (relpath))
+		return relpath;
 
 	// Try with just the LDraw path first
 	fullPath = fmt ("%1" DIRSLASH "%2", io_ldpath, relpath);
 
-	if (f->open (fullPath, File::Read))
-		return f;
+	if (QFile::exists (fullPath))
+		return fullPath;
 
 	if (subdirs)
 	{
@@ -285,15 +285,33 @@
 			{
 				fullPath = fmt ("%1" DIRSLASH "%2" DIRSLASH "%3", topdir, subdir, relpath);
 
-				if (f->open (fullPath, File::Read))
-					return f;
+				if (QFile::exists (fullPath))
+					return fullPath;
 			}
 		}
 	}
 
 	// Did not find the file.
-	log ("Could not find %1.\n", relpath);
-	delete f;
+	return "";
+}
+
+QFile* openLDrawFile (QString relpath, bool subdirs, QString* pathpointer)
+{
+	log ("Opening %1...\n", relpath);
+	QString path = findLDrawFilePath (relpath, subdirs);
+
+	if (pathpointer != null)
+		*pathpointer = path;
+
+	if (path.isEmpty())
+		return null;
+
+	QFile* fp = new QFile (path);
+
+	if (fp->open (QIODevice::ReadOnly))
+		return fp;
+
+	fp->deleteLater();
 	return null;
 }
 
@@ -416,17 +434,17 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-QList<LDObject*> loadFileContents (File* f, int* numWarnings, bool* ok)
+QList<LDObject*> loadFileContents (QFile* fp, int* numWarnings, bool* ok)
 {
-	QList<QString> lines;
+	QStringList lines;
 	QList<LDObject*> objs;
 
 	if (numWarnings)
 		*numWarnings = 0;
 
 	// Read in the lines
-	for (QString line : *f)
-		lines << line;
+	while (fp->atEnd() == false)
+		lines << QString::fromUtf8 (fp->readLine());
 
 	LDFileLoader* loader = new LDFileLoader;
 	loader->setWarnings (numWarnings);
@@ -456,26 +474,28 @@
 	// Convert the file name to lowercase since some parts contain uppercase
 	// file names. I'll assume here that the library will always use lowercase
 	// file names for the actual parts..
-	File* f;
+	QFile* fp;
+	QString fullpath;
 
 	if (search)
-		f = openLDrawFile (path.toLower(), true);
+		fp = openLDrawFile (path.toLower(), true, &fullpath);
 	else
 	{
-		f = new File (path, File::Read);
+		fp = new QFile (path);
+		fullpath = path;
 
-		if (!*f)
+		if (!fp->open (QIODevice::ReadOnly))
 		{
-			delete f;
+			delete fp;
 			return null;
 		}
 	}
 
-	if (!f)
+	if (!fp)
 		return null;
 
 	LDDocument* load = new LDDocument;
-	load->setFullPath (f->getPath());
+	load->setFullPath (fullpath);
 	load->setName (LDDocument::shortenName (load->getFullPath()));
 	dlog ("name: %1 (%2)", load->getName(), load->getFullPath());
 	g_loadedFiles << load;
@@ -485,8 +505,9 @@
 
 	int numWarnings;
 	bool ok;
-	QList<LDObject*> objs = loadFileContents (f, &numWarnings, &ok);
-	delete f;
+	QList<LDObject*> objs = loadFileContents (fp, &numWarnings, &ok);
+	fp->close();
+	fp->deleteLater();
 
 	if (!ok)
 	{
@@ -703,24 +724,23 @@
 	if (!savepath.length())
 		savepath = getFullPath();
 
-	File f (savepath, File::Write);
+	QFile f (savepath);
 
-	if (!f)
+	if (!f.open (QIODevice::WriteOnly))
 		return false;
 
 	// If the second object in the list holds the file name, update that now.
 	// Only do this if the file is explicitly open.
-	LDComment* fpathComment = null;
-	LDObject* first = getObject (1);
+	LDObject* nameObject = getObject (1);
 
-	if (!isImplicit() && first != null && first->getType() == LDObject::EComment)
+	if (!isImplicit() && nameObject != null && nameObject->getType() == LDObject::EComment)
 	{
-		fpathComment = static_cast<LDComment*> (first);
+		LDComment* nameComment = static_cast<LDComment*> (nameObject);
 
-		if (fpathComment->text.left (6) == "Name: ")
+		if (nameComment->text.left (6) == "Name: ")
 		{
 			QString newname = shortenName (savepath);
-			fpathComment->text = fmt ("Name: %1", newname);
+			nameComment->text = fmt ("Name: %1", newname);
 			g_win->buildObjList();
 		}
 	}
@@ -728,7 +748,7 @@
 	// File is open, now save the model to it. Note that LDraw requires files to
 	// have DOS line endings, so we terminate the lines with \r\n.
 	for (LDObject* obj : getObjects())
-		f.write (obj->raw() + "\r\n");
+		f.write ((obj->raw() + "\r\n").toUtf8());
 
 	// File is saved, now clean up.
 	f.close();
--- a/src/document.h	Wed Jan 08 13:57:10 2014 +0200
+++ b/src/document.h	Wed Jan 08 21:43:46 2014 +0200
@@ -164,7 +164,7 @@
 LDDocument* openDocument (QString path, bool search);
 
 // Opens the given file and returns a pointer to it, potentially looking in /parts and /p
-File* openLDrawFile (QString relpath, bool subdirs);
+QFile* openLDrawFile (QString relpath, bool subdirs, QString* pathpointer = null);
 
 // Close all open files, whether user-opened or subfile caches.
 void closeAll();
@@ -182,7 +182,7 @@
 // Is it safe to close all files?
 bool safeToCloseAll();
 
-QList<LDObject*> loadFileContents (File* f, int* numWarnings, bool* ok = null);
+QList<LDObject*> loadFileContents (QFile* f, int* numWarnings, bool* ok = null);
 
 extern QList<LDDocument*> g_loadedFiles;
 
--- a/src/extprogs.cc	Wed Jan 08 13:57:10 2014 +0200
+++ b/src/extprogs.cc	Wed Jan 08 21:43:46 2014 +0200
@@ -99,6 +99,18 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
+static bool mkTempFile (QTemporaryFile& tmp, QString& fname)
+{
+	if (!tmp.open())
+		return false;
+
+	fname = tmp.fileName();
+	tmp.close();
+	return true;
+}
+
+// =============================================================================
+// -----------------------------------------------------------------------------
 static bool checkProgPath (const extprog prog)
 {
 	QString& path = *g_extProgPaths[prog];
@@ -154,19 +166,7 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-static bool mkTempFile (QTemporaryFile& tmp, QString& fname)
-{
-	if (!tmp.open())
-		return false;
-
-	fname = tmp.fileName();
-	tmp.close();
-	return true;
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-static void writeObjects (const QList<LDObject*>& objects, File& f)
+static void writeObjects (const QList<LDObject*>& objects, QFile& f)
 {
 	for (LDObject* obj : objects)
 	{
@@ -181,7 +181,7 @@
 				obj->deleteSelf();
 		}
 		else
-			f.write (obj->raw() + "\r\n");
+			f.write ((obj->raw() + "\r\n").toUtf8());
 	}
 }
 
@@ -190,11 +190,11 @@
 static void writeObjects (const QList<LDObject*>& objects, QString fname)
 {
 	// Write the input file
-	File f (fname, File::Write);
+	QFile f (fname);
 
-	if (!f)
+	if (!f.open (QIODevice::WriteOnly | QIODevice::Text))
 	{
-		critical (fmt ("Couldn't open temporary file %1 for writing.\n", fname));
+		critical (fmt ("Couldn't open temporary file %1 for writing: %2\n", fname, f.errorString()));
 		return;
 	}
 
@@ -234,8 +234,7 @@
 // -----------------------------------------------------------------------------
 bool runUtilityProcess (extprog prog, QString path, QString argvstr)
 {
-	QTemporaryFile input, output;
-	QString inputname, outputname;
+	QTemporaryFile input;
 	QStringList argv = argvstr.split (" ", QString::SkipEmptyParts);
 
 #ifndef _WIN32
@@ -248,17 +247,13 @@
 
 	log ("cmdline: %1 %2\n", path, argv.join (" "));
 
-	// Temporary files for stdin and stdout
-	if (!mkTempFile (input, inputname) || !mkTempFile (output, outputname))
+	if (!input.open())
 		return false;
 
 	QProcess proc;
 
-	// Init stdin
-	File stdinfp (inputname, File::Write);
-
 	// Begin!
-	proc.setStandardInputFile (inputname);
+	proc.setStandardInputFile (input.fileName());
 	proc.start (path, argv);
 
 	if (!proc.waitForStarted())
@@ -268,7 +263,7 @@
 	}
 
 	// Write an enter, the utility tools all expect one
-	stdinfp.write ("\n");
+	input.write ("\n");
 
 	// Wait while it runs
 	proc.waitForFinished();
@@ -300,9 +295,9 @@
 #endif // RELEASE
 
 	// Read the output file
-	File f (fname, File::Read);
+	QFile f (fname);
 
-	if (!f)
+	if (!f.open (QIODevice::ReadOnly))
 	{
 		critical (fmt ("Couldn't open temporary file %1 for reading.\n", fname));
 		return;
@@ -314,13 +309,13 @@
 	if (replace)
 		g_win->deleteSelection();
 
-	for (const int colnum : colorsToReplace)
+	for (int colnum : colorsToReplace)
 		g_win->deleteByColor (colnum);
 
 	// Insert the new objects
 	getCurrentDocument()->clearSelection();
 
-	for (LDObject * obj : objs)
+	for (LDObject* obj : objs)
 	{
 		if (!obj->isScemantic())
 		{
--- a/src/gui_actions.cc	Wed Jan 08 13:57:10 2014 +0200
+++ b/src/gui_actions.cc	Wed Jan 08 21:43:46 2014 +0200
@@ -388,11 +388,11 @@
 	if (!fname.length())
 		return;
 
-	File f (fname, File::Read);
+	QFile f (fname);
 
-	if (!f)
+	if (!f.open (QIODevice::ReadOnly))
 	{
-		critical (fmt ("Couldn't open %1 (%2)", fname, strerror (errno)));
+		critical (fmt ("Couldn't open %1 (%2)", fname, f.errorString()));
 		return;
 	}
 
@@ -429,7 +429,7 @@
 
 	if (!file.open (QIODevice::WriteOnly | QIODevice::Text))
 	{
-		critical (fmt ("Unable to open %1 for writing (%2)", fname, strerror (errno)));
+		critical (fmt ("Unable to open %1 for writing (%2)", fname, file.errorString()));
 		return;
 	}
 
--- a/src/ldconfig.cc	Wed Jan 08 13:57:10 2014 +0200
+++ b/src/ldconfig.cc	Wed Jan 08 21:43:46 2014 +0200
@@ -16,6 +16,7 @@
  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <QFile>
 #include "document.h"
 #include "ldconfig.h"
 #include "gui.h"
@@ -41,19 +42,20 @@
 // -----------------------------------------------------------------------------
 void parseLDConfig()
 {
-	File* f = openLDrawFile ("LDConfig.ldr", false);
+	QFile* fp = openLDrawFile ("LDConfig.ldr", false);
 
-	if (!f)
+	if (!fp)
 	{
-		critical (fmt (QObject::tr ("Unable to open LDConfig.ldr for parsing: %1"),
-			strerror (errno)));
+		critical (QObject::tr ("Unable to open LDConfig.ldr for parsing."));
 		return;
 	}
 
 	// Read in the lines
-	for (QString line : *f)
+	while (fp->atEnd() == false)
 	{
-		if (line.length() == 0 || line[0] != '0')
+		QString line = QString::fromUtf8 (fp->readLine());
+
+		if (line.isEmpty() || line[0] != '0')
 			continue; // empty or illogical
 
 		line.remove ('\r');
@@ -111,7 +113,8 @@
 		setColor (code, col);
 	}
 
-	delete f;
+	fp->close();
+	fp->deleteLater();
 }
 
 // =============================================================================
--- a/src/ldtypes.h	Wed Jan 08 13:57:10 2014 +0200
+++ b/src/ldtypes.h	Wed Jan 08 21:43:46 2014 +0200
@@ -71,8 +71,8 @@
 	PROPERTY (public,		bool,			Selected,		BOOL_OPS,	STOCK_WRITE)
 	PROPERTY (public,		LDObject*,		Parent,			NO_OPS,		STOCK_WRITE)
 	PROPERTY (public,		LDDocument*,	File,			NO_OPS,		STOCK_WRITE) // TODO: rename~
-	PROPERTY (private,		int,				ID,				NUM_OPS,	STOCK_WRITE)
-	PROPERTY (public,		int,				Color,			NUM_OPS,	CUSTOM_WRITE)
+	PROPERTY (private,		int,			ID,				NUM_OPS,	STOCK_WRITE)
+	PROPERTY (public,		int,			Color,			NUM_OPS,	CUSTOM_WRITE)
 	PROPERTY (public,		bool,			GLInit,			BOOL_OPS,	STOCK_WRITE)
 
 	public:
--- a/src/main.cc	Wed Jan 08 13:57:10 2014 +0200
+++ b/src/main.cc	Wed Jan 08 21:43:46 2014 +0200
@@ -36,8 +36,6 @@
 QList<LDDocument*> g_loadedFiles;
 ForgeWindow* g_win = null;
 const QApplication* g_app = null;
-File g_file_stdout (stdout, File::Write);
-File g_file_stderr (stderr, File::Write);
 static QString g_versionString, g_fullVersionString;
 
 const Vertex g_origin (0.0f, 0.0f, 0.0f);
@@ -89,7 +87,7 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-void doPrint (File& f, initlist<StringFormatArg> args)
+void doPrint (QFile& f, QList<StringFormatArg> args)
 {
 	QString msg = DoFormat (args);
 	f.write (msg.toUtf8());
@@ -98,7 +96,7 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-void doPrint (FILE* fp, initlist<StringFormatArg> args)
+void doPrint (FILE* fp, QList<StringFormatArg> args)
 {
 	QString msg = DoFormat (args);
 	fwrite (msg.toStdString().c_str(), 1, msg.length(), fp);
--- a/src/primitives.cc	Wed Jan 08 13:57:10 2014 +0200
+++ b/src/primitives.cc	Wed Jan 08 21:43:46 2014 +0200
@@ -59,9 +59,9 @@
 	PrimitiveCategory::loadCategories();
 
 	// Try to load prims.cfg
-	File conf (Config::filepath ("prims.cfg"), File::Read);
+	QFile conf (Config::filepath ("prims.cfg"));
 
-	if (!conf)
+	if (!conf.open (QIODevice::ReadOnly))
 	{
 		// No prims.cfg, build it
 		PrimitiveLister::start();
@@ -69,8 +69,9 @@
 	else
 	{
 		// Read primitives from prims.cfg
-		for (QString line : conf)
+		while (conf.atEnd() == false)
 		{
+			QString line = conf.readLine();
 			int space = line.indexOf (" ");
 
 			if (space == -1)
@@ -129,20 +130,24 @@
 // -----------------------------------------------------------------------------
 void PrimitiveLister::work()
 {
-	int j = min (m_i + 300, m_files.size());
-	log ("PrimitiveLister::work: %1 -> %2\n", m_i, j);
+	int j = min (m_i + 100, m_files.size());
 
 	for (; m_i < j; ++m_i)
 	{
 		QString fname = m_files[m_i];
-		File f (fname, File::Read);
+		QFile f (fname);
+
+		if (f.open (QIODevice::ReadOnly))
+			continue;
+
 		Primitive info;
 		info.name = fname.mid (m_baselen + 1);  // make full path relative
 		info.name.replace ('/', '\\');  // use DOS backslashes, they're expected
 		info.cat = null;
+		QByteArray titledata = f.readLine();
 
-		if (!f.readLine (info.title))
-			info.title = "";
+		if (titledata != QByteArray())
+			info.title = QString::fromUtf8 (titledata);
 
 		info.title = info.title.simplified();
 
@@ -158,12 +163,18 @@
 	if (m_i == m_files.size())
 	{
 		// Done with primitives, now save to a config file
-		File conf (Config::filepath ("prims.cfg"), File::Write);
+		QString path = Config::filepath ("prims.cfg");
+		QFile conf (path);
 
-		for (Primitive& info : m_prims)
-			fprint (conf, "%1 %2\n", info.name, info.title);
+		if (!conf.open (QIODevice::WriteOnly | QIODevice::Text))
+			critical (fmt ("Couldn't write %1: %2", path, conf.errorString()));
+		else
+		{
+			for (Primitive& info : m_prims)
+				fprint (conf, "%1 %2\n", info.name, info.title);
 
-		conf.close();
+			conf.close();
+		}
 
 		g_primitives = m_prims;
 		PrimitiveCategory::populateCategories();
@@ -265,67 +276,71 @@
 		delete cat;
 
 	g_PrimitiveCategories.clear();
-	File f (Config::dirpath() + "primregexps.cfg", File::Read);
+	QString path = Config::dirpath() + "primregexps.cfg";
+
+	if (!QFile::exists (path))
+		path = ":/data/primitive-categories.cfg";
 
-	if (!f)
-		f.open (":/data/primitive-categories.cfg", File::Read);
+	QFile f (path);
 
-	if (!f)
+	if (!f.open (QIODevice::ReadOnly))
 	{
-		critical (QObject::tr ("Failed to open primitive categories!"));
+		critical (fmt (QObject::tr ("Failed to open primitive categories: %1"), f.errorString()));
 		return;
 	}
 
-	if (f)
-	{
-		PrimitiveCategory* cat = null;
+	PrimitiveCategory* cat = null;
 
-		for (QString line : f)
-		{
-			int colon;
+	while (f.atEnd() == false)
+	{
+		QString line = f.readLine();
+		int colon;
+
+		if (line.endsWith ("\n"))
+			line.chop (1);
+
+		if (line.length() == 0 || line[0] == '#')
+			continue;
 
-			if (line.length() == 0 || line[0] == '#')
-				continue;
+		if ((colon = line.indexOf (":")) == -1)
+		{
+			if (cat && cat->isValidToInclude())
+				g_PrimitiveCategories << cat;
 
-			if ((colon = line.indexOf (":")) == -1)
-			{
-				if (cat && cat->isValidToInclude())
-					g_PrimitiveCategories << cat;
+			cat = new PrimitiveCategory (line);
+		}
+		elif (cat != null)
+		{
+			QString cmd = line.left (colon);
+			ERegexType type = EFilenameRegex;
 
-				cat = new PrimitiveCategory (line);
-			}
-			elif (cat != null)
+			if (cmd == "f")
+				type = EFilenameRegex;
+			elif (cmd == "t")
+				type = ETitleRegex;
+			else
 			{
-				QString cmd = line.left (colon);
-				ERegexType type = EFilenameRegex;
+				log (tr ("Warning: unknown command \"%1\" on line \"%2\""), cmd, line);
+				continue;
+			}
 
-				if (cmd == "f")
-					type = EFilenameRegex;
-				elif (cmd == "t")
-					type = ETitleRegex;
-				else
-				{
-					log (tr ("Warning: unknown command \"%1\" on line \"%2\""), cmd, line);
-					continue;
-				}
+			QRegExp regex (line.mid (colon + 1));
+			RegexEntry entry = { regex, type };
+			cat->regexes << entry;
+		}
+		else
+			log ("Warning: Rules given before the first category name");
+	}
 
-				QRegExp regex (line.mid (colon + 1));
-				RegexEntry entry = { regex, type };
-				cat->regexes << entry;
-			}
-			else
-				log ("Warning: Rules given before the first category name");
-		}
-
-		if (cat->isValidToInclude())
-			g_PrimitiveCategories << cat;
-	}
+	if (cat->isValidToInclude())
+		g_PrimitiveCategories << cat;
 
 	// Add a category for unmatched primitives.
 	// Note: if this function is called the second time, g_unmatched has been
 	// deleted at the beginning of the function and is dangling at this point.
 	g_unmatched = new PrimitiveCategory (tr ("Other"));
 	g_PrimitiveCategories << g_unmatched;
+	f.close();
 }
 
 // =============================================================================
--- a/src/types.cc	Wed Jan 08 13:57:10 2014 +0200
+++ b/src/types.cc	Wed Jan 08 21:43:46 2014 +0200
@@ -367,205 +367,6 @@
 
 // =============================================================================
 // -----------------------------------------------------------------------------
-File::File()
-{
-	// Make a null file
-	m_file = null;
-	m_textstream = null;
-}
-
-File::File (QString path, OpenType rtype)
-{
-	m_file = null;
-	m_path = path;
-	open (path, rtype);
-}
-
-File::File (FILE* fp, OpenType rtype)
-{
-	m_file = null;
-	open (fp, rtype);
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-File::~File()
-{
-	if (m_file)
-	{
-		m_file->close();
-		delete m_file;
-
-		if (m_textstream)
-			delete m_textstream;
-	}
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-bool File::open (FILE* fp, OpenType rtype)
-{
-	return open ("", rtype, fp);
-}
-
-bool File::open (QString path, OpenType rtype, FILE* fp)
-{
-	close();
-
-	if (!m_file)
-		m_file = new QFile;
-
-	m_file->setFileName (path);
-
-	bool result;
-
-	QIODevice::OpenMode mode =
-		(rtype == Read) ? QIODevice::ReadOnly :
-		(rtype == Write) ? QIODevice::WriteOnly : QIODevice::Append;
-
-	if (fp)
-		result = m_file->open (fp, mode);
-	else
-		result = m_file->open (mode);
-
-	if (result)
-	{
-		m_textstream = new QTextStream (m_file);
-		m_path = path;
-		return true;
-	}
-
-	delete m_file;
-	m_file = null;
-	return false;
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-File::iterator File::begin()
-{
-	return iterator (this);
-}
-
-File::iterator& File::end()
-{
-	return m_endIterator;
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-void File::write (QString msg)
-{
-	m_file->write (msg.toUtf8(), msg.length());
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-bool File::readLine (QString& line)
-{
-	if (!m_textstream || m_textstream->atEnd())
-		return false;
-
-	line = m_textstream->readLine();
-	return true;
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-bool File::atEnd() const
-{
-	assert (m_textstream != null);
-	return m_textstream->atEnd();
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-bool File::isNull() const
-{
-	return m_file == null;
-}
-
-bool File::operator!() const
-{
-	return isNull();
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-void File::close()
-{
-	if (!m_file)
-		return;
-
-	delete m_file;
-	m_file = null;
-
-	if (m_textstream)
-	{
-		delete m_textstream;
-		m_textstream = null;
-	}
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-bool File::flush()
-{
-	return m_file->flush();
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-File::operator bool() const
-{
-	return !isNull();
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-void File::rewind()
-{
-	m_file->seek (0);
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-File::iterator::iterator (File* f) : m_file (f)
-{
-	operator++();
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-void File::iterator::operator++()
-{
-	m_gotdata = m_file->readLine (m_text);
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-QString File::iterator::operator*()
-{
-	return m_text;
-}
-
-// =============================================================================
-// The prime contestant for the weirdest operator== 2013 award?
-// -----------------------------------------------------------------------------
-bool File::iterator::operator== (File::iterator& other)
-{
-	return (other.m_file == null && !m_gotdata);
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
-bool File::iterator::operator!= (File::iterator& other)
-{
-	return !operator== (other);
-}
-
-// =============================================================================
-// -----------------------------------------------------------------------------
 LDBoundingBox::LDBoundingBox()
 {
 	reset();
--- a/src/types.h	Wed Jan 08 13:57:10 2014 +0200
+++ b/src/types.h	Wed Jan 08 21:43:46 2014 +0200
@@ -248,70 +248,6 @@
 };
 
 // =============================================================================
-// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
-// =============================================================================
-// File
-//
-// A file interface with simple interface and support for range-for-loops.
-// =============================================================================
-class File
-{
-	private:
-		// Iterator class to enable range-for-loop support. Rough hack.. don't use directly!
-		class iterator
-		{
-			public:
-				iterator() : m_file (null) {} // end iterator has m_file == null
-				iterator (File* f);
-				void operator++();
-				QString  operator*();
-				bool operator== (iterator& other);
-				bool operator!= (iterator& other);
-
-			private:
-				File* m_file;
-				QString m_text;
-				bool m_gotdata = false;
-		};
-
-	public:
-		enum OpenType
-		{
-			Read,
-			Write,
-			Append
-		};
-
-		File();
-		File (QString path, File::OpenType rtype);
-		File (FILE* fp, File::OpenType rtype);
-		~File();
-
-		bool         atEnd() const;
-		iterator     begin();
-		void         close();
-		iterator&    end();
-		bool         flush();
-		bool         isNull() const;
-		bool         readLine (QString& line);
-		void         rewind();
-		bool         open (FILE* fp, OpenType rtype);
-		bool         open (QString path, OpenType rtype, FILE* fp = null);
-		void         write (QString msg);
-
-		bool         operator!() const;
-		operator bool() const;
-
-		inline QString getPath() const { return m_path; }
-
-	private:
-		QFile*			m_file;
-		QTextStream*	m_textstream;
-		iterator			m_endIterator;
-		QString				m_path;
-};
-
-// =============================================================================
 // LDBoundingBox
 //
 // The bounding box is the box that encompasses a given set of objects.
@@ -340,8 +276,8 @@
 QString DoFormat (QList<StringFormatArg> args);
 
 // printf replacement
-void doPrint (File& f, initlist<StringFormatArg> args);
-void doPrint (FILE* f, initlist<StringFormatArg> args); // heh
+void doPrint (QFile& f, QList<StringFormatArg> args);
+void doPrint (FILE* fp, QList<StringFormatArg> args);
 
 // log() - universal access to the message log. Defined here so that I don't have
 // to include messagelog.h here and recompile everything every time that file changes.
@@ -354,12 +290,11 @@
 # define log(...) DoLog({ __VA_ARGS__ })
 #else
 QString fmt (const char* fmtstr, ...);
-void fprint (File& f, const char* fmtstr, ...);
+void fprint (QFile& f, const char* fmtstr, ...);
+void fprint (FILE* fp, const char* fmtstr, ...);
 void log (const char* fmtstr, ...);
 #endif
 
-extern File g_file_stdout;
-extern File g_file_stderr;
 extern const Vertex g_origin; // Vertex at (0, 0, 0)
 extern const Matrix g_identity; // Identity matrix
 

mercurial