Input and Output Methods
The previous examples show KeyView taking input from a file (keyview::io::InputFile
) and sending output to a file (keyview::io::OutputFile
). The C++ API allows you to take input from and write output to other data sources by making use of generic types for input and output. For example, the signature of the filter method is:
template <typename Input_Type, typename Output_Type> void filter(Input_Type& input, Output_Type& output);
Some input and output types are defined in Keyview_IO.hpp
. These are InputFile, OutputFile, and InMemoryFile. You can create your own input and output types to read from and write to any data source you like.
To create a custom input type, create a class with read
, seek
, and tell
methods, that reads from your data source. The methods you write must conform to the example signatures in the keyview::InputFile
class defined in Keyview_IO.hpp
. You can then pass instances of this into any KeyView function that takes an InputType
(like Session::filter
or Session::subfiles
).
To create a custom output type, create a class with a write
method that writes to your data source. Your write
method must conform to the example signature in the keyview::OutputFile
class, also defined in Keyview_IO.hpp
. You can then pass instances of this into any KeyView function that takes an OutputType
(like Session::filter
or Subfile::extract
).
A class can be valid as both an InputType
and OutputType
.