TrajectoryReader module

Module contents

template<typename TrajectoryT>
class TrajectoryReader : public tracktable::GenericReader<TrajectoryT>

Read trajectories from files.

This reader wraps the following pipeline:

  • Read lines from a text file

  • Skip any lines that begin with a designated comment character (‘#’ by default)

  • Tokenize each line using specified delimiters (whitespace by default)

  • Create a trajectory (user-specified type) from each tokenized line

  • Return the resulting points via a C++ iterator

You will use set_input() to supply an input stream, set_comment_character() to configure which lines to skip, set_field_delimiter() to specify how to turn lines into fields.

Public Functions

TrajectoryReader()
TrajectoryReader(std::istream &infile)
TrajectoryReader(TrajectoryReader const &other)
TrajectoryReader &operator=(TrajectoryReader const &other)
virtual ~TrajectoryReader()
bool operator==(TrajectoryReader const &other) const
bool operator!=(TrajectoryReader const &other) const
void set_default_configuration()

Default reader configuration.

If you are reading BasePoints, this sets coordinates 0 to d-1 (D is the point’s dimension) using columns 0 to d-1.

If you are reading TrajectoryPoints, column 0 is the object ID, column 1 is the timestamp, and columns 2 through D+1 (inclusive) are the coordinates.

These are the default settings. You can override any or all of them after you instantiate the reader.

void set_comment_character(string_type const &comment)

Specify comment character for skipping lines.

A line is a comment if and only if its first non-whitespace character is the comment character (‘#’ by default). We will skip such lines entirely. We do not handle inline or trailing comments: a line will either be included in its entirety or skipped completely.

Parameters
  • [in] comment: Single character

string_type comment_character() const

Retrieve current value of comment character.

This function invalidates any outstanding iterators.

Return

Current value of comment character

void set_null_value(string_type const &_null_value)

Specify string value to be interpreted as null.

Parameters
  • [in] _null_value: String to interpret as null

string_type null_value() const

Get string value for nulls.

Return

Current string that will be interpreted as null

void set_input(std::istream &_input)

Supply input stream from delimited text source.

We read our input from C++ std::istreams. The stream you supply will be traversed exactly once.

Parameters
  • [in] _input: Stream from which we will read points

std::istream &input() const

Retrieve the current input stream.

BUG: We currently have no way to indicate whether the stream is valid.

Return

Stream being used for input.

void set_warnings_enabled(bool onoff)

Enable/disable warnings during parsing.

We may run into type mismatches and bad casts while we’re parsing headers and data. This flag determines whether or not warnings will be printed.

Parameters
  • [in] onoff: Warnings are on / off

bool warnings_enabled() const

Check whether warnings are enablde.

Return

Whether or not warnings are on

void set_field_delimiter(string_type const &delimiters)

Set one or more characters as field delimiters.

Each character in the argument to this function will be treated as a potential field delimiter. If you supply ",|" as your delimiter then both the comma and the exclamation point will be used to tokenize field.

This function invalidates any outstanding iterators.

Parameters
  • [in] delimiters: String containing all desired delimiter characters

string_type field_delimiter() const

Retrieve the current set of delimiter characters.

Return

String containing all delimiters

void set_timestamp_format(string_type const &format)
string_type timestamp_format() const

Private Types

typedef TrajectoryT trajectory_type
typedef trajectory_type::point_type point_type
typedef tracktable::LineReader line_reader_type
typedef tracktable::SkipCommentsReader<line_reader_type::iterator> skip_comments_reader_type
typedef tracktable::StringTokenizingReader<skip_comments_reader_type::iterator> string_tokenizer_type
typedef boost::shared_ptr<trajectory_type> trajectory_shared_ptr_type
typedef string_vector_type::const_iterator token_iter_type
typedef std::pair<token_iter_type, token_iter_type> token_range_type
typedef std::vector<token_range_type> token_range_vector_type
typedef PointFromTokensReader<point_type, token_range_vector_type::iterator> point_reader_type

Private Functions

trajectory_shared_ptr_type next_item()
trajectory_shared_ptr_type parse_trajectory(string_vector_type const &tokens)
void populate_trajectory_points(token_iter_type token_begin, token_iter_type token_end, std::size_t num_points, trajectory_shared_ptr_type trajectory)
void populate_trajectory_points_from_token_ranges(token_range_vector_type::iterator input_range_begin, token_range_vector_type::iterator input_range_end, trajectory_shared_ptr_type trajectory)

Private Members

line_reader_type LineReader
point_reader_type PointReader
skip_comments_reader_type SkipCommentsReader
string_tokenizer_type StringTokenizer
string_type TimestampFormat
string_tokenizer_type::iterator TokenizedInputBegin
string_tokenizer_type::iterator TokenizedInputEnd
bool WarningsEnabled
io::detail::TrajectoryHeader ParseTrajectoryHeader