Remove final direct uses of Mangle::Stream

actorid
Chris Robinson 13 years ago
parent 2a3ce5ee6d
commit bd68f7bd33

@ -31,7 +31,6 @@
#include <string>
#include <boost/algorithm/string.hpp>
#include <libs/mangle/vfs/servers/ogre_vfs.hpp>
#include "../nif/nif_file.hpp"
#include "../nif/node.hpp"
#include "../nif/data.hpp"

@ -8,41 +8,7 @@
using namespace Terrain;
static class ESMLandStream : public Mangle::Stream
{
public:
ESMLandStream(ESM::Land *l, ESM::ESMReader &r)
{
}
};
bool ESMLandFactory::has(int x, int y)
{
return store.landscapes.has(x,y);
}
LandDataPtr get(int x, int y, LandInfo &info)
{
assert(has(x,y));
// Set up the info
info.grid = LGT_Quadratic;
info.data = LDT_Float;
const float SIZE = 8192; // CHECK
info.xsize = SIZE;
info.ysize = SIZE;
info.numx = 65;
info.numy = 65;
info.xoffset = SIZE*x;
info.yoffset = SIZE*y;
// Get the Land struct from store
ESM::Land* land = store.landscapes.find(x,y);
assert(land->hasData);
// Create a stream for the data and return it.
LandDataPtr ptr(new ESMLandStream(land, reader));
return ptr;
}

@ -32,10 +32,6 @@ namespace Terrain
// True if this factory has any data for the given grid cell.
bool has(int x, int y);
// Return stream to data for this cell. Additional data about the
// landscape is returned through the LandInfo struct.
LandDataPtr get(int x, int y, LandInfo &info);
};
}
#endif

@ -1,8 +1,6 @@
#ifndef TERRAIN_LAND_FACTORY_H
#define TERRAIN_LAND_FACTORY_H
#include <mangle/stream/stream.hpp>
namespace Terrain
{
enum LandInfoGridType
@ -32,12 +30,6 @@ namespace Terrain
float xoffset, yoffset;
};
/* We use normal streams for data. This allows us to just pass (for
example) a file stream as height map input later, with no extra
fuzz.
*/
typedef Mangle::Stream::StreamPtr LandDataPtr;
/*
Factory class that provides streams to land data cells. Each
"cell" has a unique integer coordinate in the plane.
@ -46,10 +38,6 @@ namespace Terrain
{
// True if this factory has any data for the given grid cell.
virtual bool has(int x, int y) = 0;
// Return stream to data for this cell. Additional data about the
// landscape is returned through the LandInfo struct.
virtual LandDataPtr get(int x, int y, LandInfo &info) = 0;
};
}
#endif

@ -1,103 +0,0 @@
#ifndef MANGLE_STREAM_INPUT_H
#define MANGLE_STREAM_INPUT_H
#include <stdlib.h>
#include "../tools/shared_ptr.hpp"
#include <assert.h>
namespace Mangle {
namespace Stream {
/// An abstract interface for a stream data.
class Stream
{
public:
// Feature options. These should be set in the constructor.
/// If true, seek() works
bool isSeekable;
/// If true, tell() works
bool hasPosition;
/// If true, size() works
bool hasSize;
/// If true, write() works. Writing through pointer operations is
/// not (yet) supported.
bool isWritable;
/// If true, read() and eof() works.
bool isReadable;
/// If true, the getPtr() functions work
bool hasPtr;
/// Initialize all bools to false by default, except isReadable.
Stream() :
isSeekable(false), hasPosition(false), hasSize(false),
isWritable(false), isReadable(true), hasPtr(false) {}
/// Virtual destructor
virtual ~Stream() {}
/** Read a given number of bytes from the stream. Returns the actual
number read. If the return value is less than count, then the
stream is empty or an error occured. Only required for readable
streams.
*/
virtual size_t read(void* buf, size_t count) { assert(0); return 0; }
/** Write a given number of bytes from the stream. Semantics is
similar to read(). Only valid if isWritable is true.
The returned value is the number of bytes written. However in
most cases, unlike for read(), a write-count less than requested
usually indicates an error. The implementation should throw such
errors as exceptions rather than expect the caller to handle
them.
Since most implementations do NOT support writing we default to
an assert(0) here.
*/
virtual size_t write(const void *buf, size_t count) { assert(0); return 0; }
/// Flush an output stream. Does nothing for non-writing streams.
virtual void flush() {}
/// Seek to an absolute position in this stream. Not all streams are
/// seekable.
virtual void seek(size_t pos) { assert(0); }
/// Get the current position in the stream. Non-seekable streams are
/// not required to keep track of this.
virtual size_t tell() const { assert(0); return 0; }
/// Return the total size of the stream. For streams hasSize is
/// false, size() should fail in some way, since it is an error to
/// call it in those cases.
virtual size_t size() const { assert(0); return 0; }
/// Returns true if the stream is empty. Required for readable
/// streams.
virtual bool eof() const { assert(0); return 0; }
/// Return a pointer to the entire stream. This function (and the
/// other getPtr() variants below) should only be implemented for
/// memory-based streams where using them would be an optimization.
virtual const void *getPtr() { assert(0); return NULL; }
/// Get a pointer to a memory region of 'size' bytes starting from
/// position 'pos'
virtual const void *getPtr(size_t pos, size_t size) { assert(0); return NULL; }
/// Get a pointer to a memory region of 'size' bytes from the
/// current position. Unlike the two other getPtr variants, this
/// will advance the position past the returned area.
virtual const void *getPtr(size_t size) { assert(0); return NULL; }
};
typedef boost::shared_ptr<Stream> StreamPtr;
}} // namespaces
#endif

@ -1,2 +0,0 @@
*_test
test.file

@ -1,34 +0,0 @@
GCC=g++ -I../ -Wall -Werror
all: ogre_client_test audiere_client_test memory_server_test buffer_filter_test file_server_test slice_filter_test file_write_test iostream_test
I_OGRE=$(shell pkg-config --cflags OGRE)
L_OGRE=$(shell pkg-config --libs OGRE)
L_AUDIERE=-laudiere
ogre_client_test: ogre_client_test.cpp ../stream.hpp ../clients/ogre_datastream.hpp
$(GCC) $< -o $@ $(I_OGRE) $(L_OGRE)
audiere_client_test: audiere_client_test.cpp ../stream.hpp ../clients/audiere_file.hpp ../clients/audiere_file.cpp
$(GCC) $< -o $@ ../clients/audiere_file.cpp $(L_AUDIERE)
iostream_test: iostream_test.cpp ../clients/io_stream.cpp
$(GCC) $^ -o $@
file_server_test: file_server_test.cpp ../stream.hpp ../servers/file_stream.hpp ../servers/std_stream.hpp
$(GCC) $< -o $@
file_write_test: file_write_test.cpp ../stream.hpp ../servers/outfile_stream.hpp ../servers/std_ostream.hpp
$(GCC) $< -o $@
memory_server_test: memory_server_test.cpp ../stream.hpp ../servers/memory_stream.hpp
$(GCC) $< -o $@
buffer_filter_test: buffer_filter_test.cpp ../stream.hpp ../servers/memory_stream.hpp ../filters/buffer_stream.hpp
$(GCC) $< -o $@
slice_filter_test: slice_filter_test.cpp ../stream.hpp ../servers/memory_stream.hpp ../filters/slice_stream.hpp
$(GCC) $< -o $@
clean:
rm *_test

@ -1,34 +0,0 @@
#include "../servers/memory_stream.hpp"
#include "../clients/audiere_file.hpp"
#include <audiere.h>
#include <iostream>
using namespace Mangle::Stream;
using namespace audiere;
using namespace std;
int main()
{
char str[12];
memset(str, 0, 12);
StreamPtr inp(new MemoryStream("hello world", 11));
FilePtr p(new AudiereFile(inp));
cout << "pos=" << p->tell() << endl;
p->read(str, 2);
cout << "2 bytes: " << str << endl;
cout << "pos=" << p->tell() << endl;
p->seek(4, File::BEGIN);
cout << "pos=" << p->tell() << endl;
p->read(str, 3);
cout << "3 bytes: " << str << endl;
p->seek(-1, File::CURRENT);
cout << "pos=" << p->tell() << endl;
p->seek(-4, File::END);
cout << "pos=" << p->tell() << endl;
p->read(str, 4);
cout << "last 4 bytes: " << str << endl;
p->seek(0, File::BEGIN);
p->read(str, 11);
cout << "entire stream: " << str << endl;
return 0;
}

@ -1,41 +0,0 @@
#include <iostream>
#include <string.h>
#include "../filters/buffer_stream.hpp"
using namespace Mangle::Stream;
using namespace std;
int main()
{
StreamPtr orig (new MemoryStream("hello world", 11));
StreamPtr inp (new BufferStream(orig));
cout << "Size: " << inp->size() << endl;
cout << "Pos: " << inp->tell() << "\nSeeking...\n";
inp->seek(3);
cout << "Pos: " << inp->tell() << endl;
char data[12];
memset(data, 0, 12);
cout << "Reading: " << inp->read(data, 4) << endl;
cout << "Four bytes: " << data << endl;
cout << "Eof: " << inp->eof() << endl;
cout << "Pos: " << inp->tell() << "\nSeeking again...\n";
inp->seek(33);
cout << "Pos: " << inp->tell() << endl;
cout << "Eof: " << inp->eof() << "\nSeek to 6\n";
inp->seek(6);
cout << "Eof: " << inp->eof() << endl;
cout << "Pos: " << inp->tell() << endl;
cout << "Over-reading: " << inp->read(data, 200) << endl;
cout << "Result: " << data << endl;
cout << "Eof: " << inp->eof() << endl;
cout << "Pos: " << inp->tell() << endl;
inp->seek(0);
cout << "Finally, reading the entire string: " << inp->read(data,11) << endl;
cout << "Result: " << data << endl;
cout << "Eof: " << inp->eof() << endl;
cout << "Pos: " << inp->tell() << endl;
return 0;
}

@ -1,18 +0,0 @@
#include "../servers/file_stream.hpp"
#include <iostream>
using namespace Mangle::Stream;
using namespace std;
int main()
{
StreamPtr inp(new FileStream("file_server_test.cpp"));
char buf[21];
buf[20] = 0;
cout << "pos=" << inp->tell() << " eof=" << inp->eof() << endl;
inp->read(buf, 20);
cout << "First 20 bytes: " << buf << endl;
cout << "pos=" << inp->tell() << " eof=" << inp->eof() << endl;
return 0;
}

@ -1,41 +0,0 @@
#include "../servers/outfile_stream.hpp"
#include <iostream>
using namespace Mangle::Stream;
using namespace std;
void print(Stream &str)
{
cout << "size=" << str.size()
<< " pos=" << str.tell()
<< " eof=" << str.eof()
<< endl;
}
int main()
{
{
cout << "\nCreating file\n";
OutFileStream out("test.file");
print(out);
out.write("hello",5);
print(out);
}
{
cout << "\nAppending to file\n";
OutFileStream out("test.file", true);
print(out);
out.write(" again\n",7);
print(out);
}
{
cout << "\nOverwriting file\n";
OutFileStream out("test.file");
print(out);
out.write("overwrite!\n",11);
print(out);
}
return 0;
}

@ -1,176 +0,0 @@
#include <iostream>
#include "../clients/io_stream.hpp"
#include "../servers/memory_stream.hpp"
using namespace Mangle::Stream;
using namespace std;
void test1()
{
cout << "Testing ASCII reading from memory:\n";
StreamPtr input(new MemoryStream("hello you world you", 19));
MangleIStream inp(input);
string str;
while(!inp.eof())
{
inp >> str;
cout << "Got: " << str << endl;
}
}
class Dummy : public Stream
{
int count;
public:
Dummy() : count(0)
{
}
size_t read(void *ptr, size_t num)
{
char *p = (char*)ptr;
char *start = p;
for(; (count < 2560) && (p-start < (int)num); count++)
{
*p = count / 10;
p++;
}
return p-start;
}
bool eof() const { return count == 2560; }
};
void test2()
{
cout << "\nTesting binary reading from non-memory:\n";
StreamPtr input(new Dummy);
MangleIStream inp(input);
int x = 0;
while(!inp.eof())
{
unsigned char buf[5];
inp.read((char*)buf,5);
// istream doesn't set eof() until we read _beyond_ the end of
// the stream, so we need an extra check.
if(inp.gcount() == 0) break;
/*
for(int i=0;i<5;i++)
cout << (int)buf[i] << " ";
cout << endl;
*/
assert(buf[4] == buf[0]);
assert(buf[0] == x/2);
x++;
}
cout << " Done\n";
}
struct Dummy2 : Stream
{
Dummy2()
{
isWritable = true;
isReadable = false;
}
size_t write(const void *ptr, size_t num)
{
const char *p = (const char*)ptr;
cout << " Got: ";
for(unsigned i=0;i<num;i++)
cout << *(p++) << " ";
cout << endl;
return num;
}
};
void test3()
{
cout << "\nWriting to dummy stream:\n";
cout << " Pure dummy test:\n";
StreamPtr output(new Dummy2);
output->write("testing", 7);
cout << " Running through MangleOStream:\n";
MangleOStream out(output);
out << "hello";
out << " - are you ok?";
cout << " Flushing:\n";
out.flush();
cout << " Writing a hell of a lot of characters:\n";
for(int i=0; i<127; i++)
out << "xxxxxxxx"; // 127 * 8 = 1016
out << "fffffff"; // +7 = 1023
cout << " Just one more:\n";
out << "y";
cout << " And oooone more:\n";
out << "z";
cout << " Flushing again:\n";
out.flush();
cout << " Writing some more and exiting:\n";
out << "blah bleh blob";
}
struct Dummy3 : Stream
{
int pos;
Dummy3() : pos(0)
{
hasPosition = true;
isSeekable = true;
}
size_t read(void*, size_t num)
{
cout << " Reading " << num << " bytes from " << pos << endl;
pos += num;
return num;
}
void seek(size_t npos) { pos = npos; }
size_t tell() const { return pos; }
};
void test4()
{
cout << "\nTesting seeking;\n";
StreamPtr input(new Dummy3);
cout << " Direct reading:\n";
input->read(0,10);
input->read(0,5);
MangleIStream inp(input);
cout << " Reading from istream:\n";
char buf[20];
inp.read(buf, 20);
inp.read(buf, 20);
inp.read(buf, 20);
cout << " Seeking to 30 and reading again:\n";
inp.seekg(30);
inp.read(buf, 20);
}
int main()
{
test1();
test2();
test3();
test4();
return 0;
}

@ -1,42 +0,0 @@
#include <iostream>
#include <string.h>
#include "../servers/memory_stream.hpp"
using namespace Mangle::Stream;
using namespace std;
int main()
{
Stream* inp = new MemoryStream("hello world\0", 12);
cout << "Size: " << inp->size() << endl;
cout << "Pos: " << inp->tell() << "\nSeeking...\n";
inp->seek(3);
cout << "Pos: " << inp->tell() << endl;
char data[12];
memset(data, 0, 12);
cout << "Reading: " << inp->read(data, 4) << endl;
cout << "Four bytes: " << data << endl;
cout << "Eof: " << inp->eof() << endl;
cout << "Pos: " << inp->tell() << "\nSeeking again...\n";
inp->seek(33);
cout << "Pos: " << inp->tell() << endl;
cout << "Eof: " << inp->eof() << "\nSeek to 6\n";
inp->seek(6);
cout << "Eof: " << inp->eof() << endl;
cout << "Pos: " << inp->tell() << endl;
cout << "Over-reading: " << inp->read(data, 200) << endl;
cout << "Result: " << data << endl;
cout << "Eof: " << inp->eof() << endl;
cout << "Pos: " << inp->tell() << endl;
inp->seek(0);
cout << "Finally, reading the entire string: " << inp->read(data,11) << endl;
cout << "Result: " << data << endl;
cout << "Eof: " << inp->eof() << endl;
cout << "Pos: " << inp->tell() << endl;
cout << "Entire stream from pointer: " << (char*)inp->getPtr() << endl;
return 0;
}

@ -1,22 +0,0 @@
#include "../servers/memory_stream.hpp"
#include "../clients/ogre_datastream.hpp"
#include <iostream>
using namespace Mangle::Stream;
using namespace Ogre;
using namespace std;
int main()
{
StreamPtr inp(new MemoryStream("hello world", 11));
DataStreamPtr p(new Mangle2OgreStream("hello", inp));
cout << "Name: " << p->getName() << endl;
cout << "As string: " << p->getAsString() << endl;
cout << "pos=" << p->tell() << " eof=" << p->eof() << endl;
p->seek(0);
cout << "pos=" << p->tell() << " eof=" << p->eof() << endl;
p->skip(5);
p->skip(-2);
cout << "pos=" << p->tell() << " eof=" << p->eof() << endl;
return 0;
}

@ -1,9 +0,0 @@
pos=0
2 bytes: he
pos=2
pos=4
3 bytes: o w
pos=6
pos=7
last 4 bytes: orld
entire stream: hello world

@ -1,22 +0,0 @@
Size: 11
Pos: 0
Seeking...
Pos: 3
Reading: 4
Four bytes: lo w
Eof: 0
Pos: 7
Seeking again...
Pos: 11
Eof: 1
Seek to 6
Eof: 0
Pos: 6
Over-reading: 5
Result: world
Eof: 1
Pos: 11
Finally, reading the entire string: 11
Result: hello world
Eof: 1
Pos: 11

@ -1,3 +0,0 @@
pos=0 eof=0
First 20 bytes: #include "../servers
pos=20 eof=0

@ -1,12 +0,0 @@
Creating file
size=0 pos=0 eof=0
size=5 pos=5 eof=0
Appending to file
size=5 pos=5 eof=0
size=12 pos=12 eof=0
Overwriting file
size=0 pos=0 eof=0
size=11 pos=11 eof=0

@ -1,32 +0,0 @@
Testing ASCII reading from memory:
Got: hello
Got: you
Got: world
Got: you
Testing binary reading from non-memory:
Done
Writing to dummy stream:
Pure dummy test:
Got: t e s t i n g
Running through MangleOStream:
Flushing:
Got: h e l l o - a r e y o u o k ?
Writing a hell of a lot of characters:
Just one more:
And oooone more:
Got: x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x f f f f f f f y
Flushing again:
Got: z
Writing some more and exiting:
Got: b l a h b l e h b l o b
Testing seeking;
Direct reading:
Reading 10 bytes from 0
Reading 5 bytes from 10
Reading from istream:
Reading 1024 bytes from 15
Seeking to 30 and reading again:
Reading 1024 bytes from 30

@ -1,23 +0,0 @@
Size: 12
Pos: 0
Seeking...
Pos: 3
Reading: 4
Four bytes: lo w
Eof: 0
Pos: 7
Seeking again...
Pos: 12
Eof: 1
Seek to 6
Eof: 0
Pos: 6
Over-reading: 6
Result: world
Eof: 1
Pos: 12
Finally, reading the entire string: 11
Result: hello world
Eof: 0
Pos: 11
Entire stream from pointer: hello world

@ -1,5 +0,0 @@
Name: hello
As string: hello world
pos=11 eof=1
pos=0 eof=0
pos=3 eof=0

@ -1,36 +0,0 @@
Slice 1:
--------
Size: 6
Pos: 0
Seeking...
Reading 6 bytes
Result: hello
Pos: 6
Eof: 1
Seeking:
Pos: 2
Eof: 0
Reading 4 bytes
Result: llo
Pos: 6
Eof: 1
Entire stream as pointer: hello
Slice 2:
--------
Size: 6
Pos: 0
Seeking...
Reading 6 bytes
Result: world
Pos: 6
Eof: 1
Seeking:
Pos: 2
Eof: 0
Reading 4 bytes
Result: rld
Pos: 6
Eof: 1
Entire stream as pointer: world

@ -1,42 +0,0 @@
#include <iostream>
#include <string.h>
#include "../filters/slice_stream.hpp"
#include "../servers/memory_stream.hpp"
using namespace Mangle::Stream;
using namespace std;
void test(StreamPtr inp)
{
cout << "Size: " << inp->size() << endl;
cout << "Pos: " << inp->tell() << "\nSeeking...\n";
char data[6];
memset(data, 0, 6);
cout << "Reading " << inp->read(data, 6) << " bytes\n";
cout << "Result: " << data << endl;
cout << "Pos: " << inp->tell() << endl;
cout << "Eof: " << inp->eof() << endl;
inp->seek(2);
cout << "Seeking:\nPos: " << inp->tell() << endl;
cout << "Eof: " << inp->eof() << endl;
cout << "Reading " << inp->read(data, 6) << " bytes\n";
cout << "Result: " << data << endl;
cout << "Pos: " << inp->tell() << endl;
cout << "Eof: " << inp->eof() << endl;
cout << "Entire stream as pointer: " << (char*)inp->getPtr() << endl;
}
int main()
{
StreamPtr orig (new MemoryStream("hello\0world\0", 12));
StreamPtr slice1 (new SliceStream(orig,0,6));
StreamPtr slice2 (new SliceStream(orig,6,6));
cout << "\nSlice 1:\n--------\n";
test(slice1);
cout << "\nSlice 2:\n--------\n";
test(slice2);
return 0;
}

@ -1,18 +0,0 @@
#!/bin/bash
make || exit
mkdir -p output
PROGS=*_test
for a in $PROGS; do
if [ -f "output/$a.out" ]; then
echo "Running $a:"
./$a | diff output/$a.out -
else
echo "Creating $a.out"
./$a > "output/$a.out"
git add "output/$a.out"
fi
done
Loading…
Cancel
Save