[Kst] kst2 datasource API comments

Barth Netterfield netterfield at astro.utoronto.ca
Fri Mar 19 22:13:36 CET 2010


On Friday 19 March 2010 10:09:08  Peter Kümmel wrote:
> Attached a patch which shows a solution:
> We use the same templated interface (SourceInterface) for all Primitives.
> (The template is needed to pass/get custom parameters. See Vector::Param)
> 
> This interface must be implemented by the concrete data sources. Primitives
> not supported simply return a dummy impl (not shown in th patch, see
> AsciiSource)
> 
> This way DataSource becomes very simple: all the special functions for all
> the primitives reduces to one function which returns a interface, eg
> SourceInterface<Vector>. The runtime overhead is minimal.
> 
> Using the interface shows DataVector: instead of
>     rc = _file->readField(_v + _numSamples, _field, new_f0, (new_nf -
> NF)/Skip, Skip, &lastRead); we have
>     rc = _file->vector().read(_field, info );
> and the construction of the parameter object
>    Vector::Param info = {_v + _numSamples,new_f0, (new_nf - NF)/Skip, Skip,
> &lastRead};
> 
> Adding more metainfo to all primitives is simply extending the SourceData
> template, or we use meta Info type.
> 
> To read primitive-special values we could do it the same way like when
> calling read(), we have to add in the primitve type a small structure/clas
> which will be used by the template, eg with 'T::Info info(const QString&
> field)'.
> 
> What do you think? Should I start to port such a design?

Seems good.  Definitely more C++y.

This automatically means that datasources can add meta-data to scalars and 
strings.... right?

I like the default dummy interfaces for un-needed primitives.

For each primitive, there are a lot of 'optional' methods.  For examples, for 
vectors - the only ones required are read() and frameCount().  The rest just 
add additional features that not all data sources need support, though they 
need to exist and return a default value (empty list, 0, etc).  Will default 
dummies be provided for these in the base interface class?

I think frameCount only has meaning for vectors.  Will it be part of the 
template base class (SourceInterface)?

 
> +  interf_vector = new AsciiSourceImpl;
> +  interf_matrix = new DummyMatrixSourceImpl;

do you mean, imagining that asciisource can provide vectors and strings, but 
not matrixs or scalars:

+  interf_vector = new AsciiSourceVectorImpl;
+  interf_string = new AsciiSourceStringImpl;
+  interf_matrix = new DummyMatrixSourceImpl;
+  interf_scalar = new DummyMatrixSourceImpl;


So: to implement a new data source you implement the datasource, which handles 
the file opening and (maybe) validation, and then an interface for each of the 
primitives that you want the data source to be able to support.  Correct?

If I understand it, I think I like it.

cbn


More information about the Kst mailing list