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

Defines the columnar structure of a table. Each column has a name, data type and field size. Instances of this class may also be used to describe the field structure in records. More...

#include <TSADataDef.h>

Inheritance diagram for tsa::column_defs:
tsa::object

Public Member Functions

 column_defs (void)
 Constructor.
 
 column_defs (column_defs &&)
 Constructor.
 
 column_defs (const std::string &column_definition_string)
 Constructor. Initializes self according to column_definition_string.
 
 column_defs (const char *column_definition_string)
 Constructor. Initializes self according to column_definition_string.
 
 column_defs (const column_defs &)
 Copy constructor.
 
void add_column (type_t column_type, const std::string &column_name, size_t length=1)
 Adds a column to self. Using this member it is possible to add columns individually without using a column-definition-string. More...
 
void clear ()
 Clears the object. defined() will return false, and size() will return 0.
 
size_t column_count (void) const
 Returns the number of columns in self.
 
bool column_exists (const std::string column_name) const
 Returns true if a column with given name exists.
 
size_t column_field_length (size_t position) const
 Returns the length, in bytes, of the column field at given ordinal position. Note that this value is only relevant for fields of type string. More...
 
size_t column_field_length (const std::string &column_name) const
 Returns the length of the field with given column_name. Note that this value is only relevant for fields of type string. More...
 
const std::stringcolumn_name (size_t position) const
 Returns the name of the field at given ordinal position.
 
size_t column_number (const std::string column_name) const
 Returns the index of the column with given name.
 
type_t column_type (size_t position) const
 Returns the type of the column at given ordinal position.
 
type_t column_type (const std::string &field_name) const
 Returns the type of the column with given column_name. More...
 
bool defined (void) const
 Returns true if self is not empty (has column information).
 
void from_string (const std::string &column_definition_string)
 Initializes self according to column_definition_string. More...
 
bool has_pointer_field (void) const
 Returns true if self contains a column that is pointer type such as: type_t::void_ptr or type_t::object_ptr. More...
 
bool is_equal (const column_defs &other)
 Returns true if self is equal, in every way, to other.
 
void operator= (const column_defs &other)
 Assignment operator.
 
void remove_column (const std::string &column_name)
 Removes the column with given column_name.
 
size_t size (void) const
 Returns the number of columns in self.
 
std::string to_string (void) const
 Returns self as a column-definition-string.
 
- 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...
 

Detailed Description

Defines the columnar structure of a table. Each column has a name, data type and field size. Instances of this class may also be used to describe the field structure in records.

Note that the column structure of tables must not describe a record timestamp column. Since TS-API is built specifically for working with timeseries, a timestamp column is implicit to every tables.

The fields types are limited to the types declared by tsa::type_t with the exception of type_t::void_ptr. Supported types and corresponding type characters are :

  • float32 ('f' or 'F')
  • uint32 ('u' or 'U')
  • int32 ('i' or 'I')
  • int64 ('l' or 'L')
  • float64 ('d' or 'D')
  • boolean ('b' or 'B')
  • datetime ('t' or 'T')
  • date ('a' or 'A')
  • string. ('s' or 'S')

Objects of this type can be initialized by a data-definition-string. This string must provide a comma separated list of column names. Each column name must be complemented by a colon and a character corresponding to the column type. For example:

column_defs cdef = "open:D,high:D,low:D,close:D";

initializes the object with 4 fields of type float64 (double). float64 is the default type if no type information is given. So writing:

column_defs cdef = "open,high,low,close";

would have the same effect as the line above.

String Fields

When declaring a string field, it is necessary to add the maximum number of characters a string can have in addition to the type such as:

column_defs cdef = "symbol:S:10,exchange:S:20";

.

See also
object

Member Function Documentation

void tsa::column_defs::add_column ( type_t  column_type,
const std::string column_name,
size_t  length = 1 
)

Adds a column to self. Using this member it is possible to add columns individually without using a column-definition-string.

Parameters
column_typeType of the column.
column_nameName of the column.
lengthThe length of the fiels (max number of characters in string fields).
size_t tsa::column_defs::column_field_length ( size_t  position) const

Returns the length, in bytes, of the column field at given ordinal position. Note that this value is only relevant for fields of type string.

Parameters
positionZero-based index of the column.
Returns
A size_t.
size_t tsa::column_defs::column_field_length ( const std::string column_name) const

Returns the length of the field with given column_name. Note that this value is only relevant for fields of type string.

Parameters
column_nameName of the column.
Returns
A size_t.
type_t tsa::column_defs::column_type ( const std::string field_name) const

Returns the type of the column with given column_name.

Parameters
field_nameName of the field.
Returns
A type_t.
void tsa::column_defs::from_string ( const std::string column_definition_string)

Initializes self according to column_definition_string.

See the class description for more information about the column_definition_string.

Parameters
column_definition_stringString that defined column names, types and field size.
bool tsa::column_defs::has_pointer_field ( void  ) const

Returns true if self contains a column that is pointer type such as: type_t::void_ptr or type_t::object_ptr.

Returns
bool.