Trading System API  3.0
Library for Simulating and Deploying Trading and Investment Strategies
tsa::fast::table Class Reference

Represents a database table in fast::database. More...

#include <TSADBTable.h>

Inheritance diagram for tsa::fast::table:
tsa::out_stream_adaptor tsa::appendable tsa::object tsa::component

Classes

class  iterator
 Table iterator. Supports forward iteration only. More...
 

Public Member Functions

virtual ~table (void)
 Destructor. Calls Commit() and Close().
 
void close (void)
 Releases the internal database connection is_init() will return false after this call. This operation cannot be undone! Do not re-use the object after invoking this member.
 
virtual void cmp__finalize (void) override
 Override this member in any derived class. It will be invoked when the strategy is finalized. Use it to deallocate memory or close any streams.
 
bool is_init (void) const
 Returns true if the object is initialized. This member returns false after close() is invoked. More...
 
const std::stringname (void) const
 Returns the name of the table to which self is connected. More...
 
virtual void osa__append (const date_time &, std::vector< variant > &) override
 Implement this member in any derived class and to append a new record and time_stamp. More...
 
virtual void osa__prepare_stream (const std::string &source_name, const tsa::column_defs &) override
 Implement this member in any derived class. This member is called before any records are passed. Use it for initialization purposes, such as creating a new table in a series_base. More...
 
- Public Member Functions inherited from tsa::out_stream_adaptor
virtual ~out_stream_adaptor (void)
 Destructor.
 
- Public Member Functions inherited from tsa::component
virtual void cmp__evaluate_bar (const date_time &)
 
virtual void cmp__post_evaluate_bar (const date_time &)
 
bool is_registered_with_strategy (void) const
 
void register_with_strategy (strategy *)
 
- Public Member Functions inherited from tsa::object
 object (void)
 Constructor.
 
virtual ~object (void)
 Destructor.
 
const char * class_name (void) const
 Returns the class name as returned by the 'Real Time Type Information' (RTTI) mechanism. More...
 
bool has_same_class_as (const object &other) const
 Returns true if self has the same type as other object. More...
 

Row Information

const std::stringcolumn_name (size_t position) const
 Returns the name of the column at given position. More...
 
size_t column_number (const std::string &column_name) const
 Returns the ordinal position of the column with given column_name. More...
 
virtual size_t column_count (void) const
 Returns the number of columns in the table. The returned number does NOT include the timestamp column which is implicit to all series tables. More...
 
type_t column_type (size_t position) const
 Returns the type of the column at given position. More...
 
size_t column_field_length (size_t column_position) const
 Returns the column field length. This is relevant only for character string fields. More...
 
const std::stringcolumn_defs__name (void) const
 
const class tsa::column_defs columns (void) const
 Returns the corresponding column_defs object.
 

Record Operations

iterator end_iterator
 
iterator seek (const date_time &target_timestamp)
 Positions the iterator on the record with the given target_timestamp. Note that if the target_timestamp is within the table range, but no record with the target_timestamp exists, than the cursor will be positioned on the record with a timestamp that is immediately lower than the requested target_timestamp. More...
 
iterator seek (size_t record_position)
 Positions the iterator on the record at the given position, where the record with the lowest timestamp is at position 0. More...
 
iterator begin (void)
 Returns an iterator to the beginning of the table. Will be equal to end() if the table is empty. More...
 
const iteratorend (void)
 Returns an iterator past the end of the table, as is common for STL containers. This way the current iterator can be compared to the iterator returned by end() during a loop. More...
 
virtual class record record (void)
 
virtual void append (const class record &record, append_flag_type flag=error_on_duplicate_timestamp)
 Appends the given record to the table. Series tables do not allow duplicate timestamps. By passing append_flag. More...
 
void push_back (const class record &rec, append_flag_type flag=error_on_duplicate_timestamp)
 
size_t size (void) const
 Returns the number of records in the table. More...
 
bool empty (void) const
 Returns true if the table contains no records. More...
 
const date_timefirst_timestamp (void) const
 Returns the timestamp of the first record in the table. More...
 
const date_timelast_timestamp (void) const
 Returns the timestamp of the last record in the table. More...
 
const date_timetimestamp (void) const
 Returns the timestamp of the record on which the cursor is positioned. More...
 
void commit (void)
 Flushes unsaved data to disk. Do NOT call this member after every 'append' operation in a bulk operation for performance reasons! Commit is called automatically when the object is destroyed. More...
 
void read (class record &rec) const
 Reads a table record into the record instance rec. Call this member after a successful seek(), or access a record via an iterator. More...
 
void clear ()
 Deletes all records in the table.
 
void truncate (size_t new_size)
 Truncates the table to new_size. Any records deleted are deleted from the 'back' of the table. More...
 
void truncate (const date_time &new_highest_timestamp)
 Truncates the 'back' of the table. The timestamp of the last record will be smaller or equal to new_highest_timestamp. More...
 

Printing

void print_timestamp (bool _b)
 
void print_fp_precision (size_t _n)
 
void print_limit (size_t _n)
 
void print_range (const date_time &_start, const date_time &_end)
 
void print (std::ostream &stream)
 
void printv (std::ostream &stream)
 
void html (const os::path &dir, const std::string &alt_name="")
 
void csv (std::ostream &)
 

Detailed Description

Represents a database table in fast::database.

See also
out_stream_adaptor
appendable

Member Function Documentation

void tsa::fast::table::append ( const class record record,
append_flag_type  flag = error_on_duplicate_timestamp 
)
virtual

Appends the given record to the table. Series tables do not allow duplicate timestamps. By passing append_flag.

Parameters
recordThe record.
flagThe flag.

Implements tsa::appendable.

table::iterator tsa::fast::table::begin ( void  )

Returns an iterator to the beginning of the table. Will be equal to end() if the table is empty.

Returns
An iterator.
size_t tsa::fast::table::column_count ( void  ) const
virtual

Returns the number of columns in the table. The returned number does NOT include the timestamp column which is implicit to all series tables.

Returns
A size_t.

Implements tsa::appendable.

size_t tsa::fast::table::column_field_length ( size_t  column_position) const

Returns the column field length. This is relevant only for character string fields.

Parameters
column_positionThe column position.
Returns
A size_t.
const std::string & tsa::fast::table::column_name ( size_t  position) const

Returns the name of the column at given position.

Parameters
positionThe column position.
Returns
A std::string&
size_t tsa::fast::table::column_number ( const std::string column_name) const

Returns the ordinal position of the column with given column_name.

Parameters
column_nameThe column name.
Returns
A size_t.
type_t tsa::fast::table::column_type ( size_t  position) const

Returns the type of the column at given position.

Parameters
positionThe column position.
Returns
A type_t.
void tsa::fast::table::commit ( void  )

Flushes unsaved data to disk. Do NOT call this member after every 'append' operation in a bulk operation for performance reasons! Commit is called automatically when the object is destroyed.

The Commit() function is called automatically when a TableWriter object goes out of scope, and writes various caches and the current record page to disk.

Call this before calling any function that could inadvertently terminate the process, but not after every 'append' operation, as this would cause serious performance problems!

bool tsa::fast::table::empty ( void  ) const

Returns true if the table contains no records.

Returns
bool.
const table::iterator & tsa::fast::table::end ( void  )

Returns an iterator past the end of the table, as is common for STL containers. This way the current iterator can be compared to the iterator returned by end() during a loop.

Table t = db.table(...)
auto i = t.begin()
while(i != t.end(){
//...
}

.

Returns
An iterator&
const date_time & tsa::fast::table::first_timestamp ( void  ) const

Returns the timestamp of the first record in the table.

Returns
A date_time&
bool tsa::fast::table::is_init ( void  ) const

Returns true if the object is initialized. This member returns false after close() is invoked.

Returns
bool
const date_time & tsa::fast::table::last_timestamp ( void  ) const

Returns the timestamp of the last record in the table.

Returns
A date_time&
const std::string & tsa::fast::table::name ( void  ) const

Returns the name of the table to which self is connected.

Returns
A std::string&
void tsa::fast::table::osa__append ( const date_time time_stamp,
std::vector< variant > &  record 
)
overridevirtual

Implement this member in any derived class and to append a new record and time_stamp.

Parameters
time_stampThe time stamp.
[in,out]recordThe record.

Implements tsa::out_stream_adaptor.

void tsa::fast::table::osa__prepare_stream ( const std::string stream_name,
const tsa::column_defs field_list 
)
overridevirtual

Implement this member in any derived class. This member is called before any records are passed. Use it for initialization purposes, such as creating a new table in a series_base.

Parameters
stream_nameName of the stream.
field_listList of fields.

Implements tsa::out_stream_adaptor.

void tsa::fast::table::read ( class record rec) const

Reads a table record into the record instance rec. Call this member after a successful seek(), or access a record via an iterator.

Parameters
[in,out]recThe record to read.
table::iterator tsa::fast::table::seek ( const date_time target_timestamp)

Positions the iterator on the record with the given target_timestamp. Note that if the target_timestamp is within the table range, but no record with the target_timestamp exists, than the cursor will be positioned on the record with a timestamp that is immediately lower than the requested target_timestamp.

Parameters
target_timestampTarget timestamp.
Returns
An iterator.
table::iterator tsa::fast::table::seek ( size_t  record_position)

Positions the iterator on the record at the given position, where the record with the lowest timestamp is at position 0.

Parameters
record_positionThe record position.
Returns
An iterator.
size_t tsa::fast::table::size ( void  ) const

Returns the number of records in the table.

Returns
A size_t.
const date_time & tsa::fast::table::timestamp ( void  ) const

Returns the timestamp of the record on which the cursor is positioned.

Returns
A date_time&
void tsa::fast::table::truncate ( size_t  new_size)

Truncates the table to new_size. Any records deleted are deleted from the 'back' of the table.

Parameters
new_sizeSize of table after truncate operation (assuming original table is larger or equal)
void tsa::fast::table::truncate ( const date_time _tNewEndTime)

Truncates the 'back' of the table. The timestamp of the last record will be smaller or equal to new_highest_timestamp.

Parameters
new_highest_timestampThe new highest timestamp.

trucates the table so that newEndTime will the be last record time. If no record exists with given time, the next earliest existing record time will be used instead