mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-09 03:39:14 +00:00
de5a07ee71
git-svn-id: https://openmw.svn.sourceforge.net/svnroot/openmw/trunk@138 ea6a568a-9f4f-0410-981a-c910a81bb256
72 lines
1.6 KiB
D
72 lines
1.6 KiB
D
/*
|
|
OpenMW - The completely unofficial reimplementation of Morrowind
|
|
Copyright (C) 2009 Nicolay Korslund
|
|
WWW: http://openmw.sourceforge.net/
|
|
|
|
This file (archive.d) is part of the OpenMW package.
|
|
|
|
OpenMW is distributed as free software: you can redistribute it
|
|
and/or modify it under the terms of the GNU General Public License
|
|
version 3, as published by the Free Software Foundation.
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
version 3 along with this program. If not, see
|
|
http://www.gnu.org/licenses/ .
|
|
|
|
*/
|
|
|
|
module terrain.myfile;
|
|
|
|
import std.stream;
|
|
import std.stdio;
|
|
|
|
// Add a couple of helper functions to the file stream
|
|
class MyFile : File
|
|
{
|
|
this(string filename, FileMode mode = FileMode.In)
|
|
{
|
|
super(filename, mode);
|
|
}
|
|
|
|
void fill(T)(ref T t)
|
|
{
|
|
readExact(&t, T.sizeof);
|
|
}
|
|
|
|
void dump(T)(ref T t)
|
|
{
|
|
writeExact(&t, T.sizeof);
|
|
}
|
|
|
|
void fillArray(T)(T[] t)
|
|
{
|
|
readExact(t.ptr, t.length*T.sizeof);
|
|
}
|
|
|
|
void dumpArray(T)(T[] t)
|
|
{
|
|
writeExact(t.ptr, t.length*T.sizeof);
|
|
}
|
|
|
|
void readArray(T)(ref T[] arr)
|
|
{
|
|
int size;
|
|
read(size);
|
|
assert(size < 1024*1024 && size > 0);
|
|
arr = new T[size];
|
|
fillArray!(T)(arr);
|
|
}
|
|
|
|
void writeArray(T)(T[] t)
|
|
{
|
|
int size = t.length;
|
|
write(size);
|
|
dumpArray!(T)(t);
|
|
}
|
|
}
|