[pdal] Cloneable streams

Michael P. Gerlek mpg at flaxen.com
Mon Mar 26 19:52:01 EDT 2012


Thinking out loud....


The las::Writer constructor takes a filename (via an Option string) or a std::stream.

The las::Reader constructor takes a filename -- but not a stream! This is because the Reader stage wants to be read-only: the file I/O is actually done by the Iterator, so the iterator has to call mystage->getFilename() and do the open() itself.

Ideally, each reader and writer stage would support at least two canonical forms: a string (or Option object) for simple usage and a stream pointer for interoperability with other systems.

But when you now add the need for the NITF reader to give the LAS reader a "subset" of the full file, things get even more fun: since we can't pass streams to Readers directly, we have to pass a filename and a length + offset... which means the iterator in turn has to get smarter and know about this new kind of stream creation mechanism that does offsets...  ick.


In addition to a ctor that takes an Option set, how about Readers and Writers also have a ctor that takes a StreamFactory object?

	class StreamFactory
	{
	public:
		std::stream* create() = 0;
	}

When you create a Reader, you give it a Factory so it can make streams without having to know about the creation mechanism. We would supply a few derived classes for daily usage, with ctors like this:

	PassthruStreamFactory(std::istream& stream);
	FilenameStreamFactory(std::string);
	CurlStreamFactory(std::string url);
	...

and so on. The iterator would be able to use this factory to make new streams at will (so we can have parallel iterators), and the class could even take care of doing the cleanups of open streams in its dtor (by keeping a mutable and mutex-locked list of open streams or whatever).

[I already made a StreamManager class a while back, but this StreamFactory is a more general concept.]

-mpg




More information about the pdal mailing list