ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Data Structures | Public Member Functions | Protected Attributes | Private Member Functions
ListDataStockBase Class Referenceabstract

Abstract base class for the ListDataStock, for storing base pointers in vectors. More...

#include <ListDataStock.h>

Inheritance diagram for ListDataStockBase:
Inheritance graph
[legend]
Collaboration diagram for ListDataStockBase:
Collaboration graph
[legend]

Data Structures

class  visitor_get_array_allocate
 
class  visitor_get_array_set_value
 
class  visitor_type_array
 

Public Types

typedef boost::variant for Put/GetCArray
typedef boost::variant< float
**, double **, int ** > 
var_types
 
typedef boost::variant< float
***, double ***, int *** > 
var_types2
 

Public Member Functions

virtual void PrintData (const unsigned int verbose=0) const =0
 Nice formatting output on console. More...
 
Constructors and destructor
 ListDataStockBase ()
 Default constructor, set empty names, timescale ETime::not_a_time, dates are zero. More...
 
 ListDataStockBase (std::string iname, ETime itmscl, Utils::firstlast_dates idates=Utils::get_fldate_default())
 Constructor sets name, timescale and optionaly dates. More...
 
virtual ~ListDataStockBase ()
 Destructor. More...
 
Getters / Setters of private members of the base class
std::string GetName () const
 
virtual std::string GetFullName () const
 
virtual ETime GetTimeScale () const
 
virtual void SetTimeScale (const ETime new_tmscl)
 
void SetName (const std::string iname)
 
virtual void SetFullName (std::string fname)
 
virtual Utils::firstlast_dates GetDates () const
 Return the structure Utils::firstlast_dates of the private data member, not from the data. More...
 
time_t GetFirstDate () const
 Get first date from the private data member dates. More...
 
time_t GetLastDate () const
 Get last date from the private data member dates. More...
 
virtual void SetDates (const time_t first, const time_t last)
 Set dates, 2 arguments. More...
 
virtual void SetDates (const Utils::firstlast_dates &new_date)
 Set dates with a structure Utils::firstlast_dates. More...
 
virtual void SetDates ()=0
 Set the correct first/last dates from the DataStock in the vector. More...
 
Wrappers to the internal std::vector
virtual unsigned int GetSize () const =0
 Return the size of the vector. More...
 
virtual unsigned int Capacity () const =0
 Return the capacity of the vector. More...
 
virtual void Reserve (const unsigned int new_size)=0
 Reserve new_size elements. More...
 
virtual void Clear ()=0
 Clear the vector and reinitialize data members to default values. More...
 
virtual void Swap ()=0
 Reduce the capacity of the internal vector to fit its size. More...
 
Get a copy of the internal vector, in the order given by chrono
virtual void GetVectorData (std::vector< DataCSV > &, const EPChrono) const
 
virtual void GetVectorData (std::vector< SimpleData > &, const EPChrono) const
 
virtual void GetVectorData (std::vector< MultiData > &, const EPChrono) const
 
Functions related to the policy of the list
virtual std::string policy () const =0
 Return a string of the chronology policy. More...
 
virtual EPChrono bpolicy () const =0
 Return policy as an enumeration type EPChrono, CHRONO / NO_CHRONO. More...
 
virtual void Order (const EPChrono chrono)=0
 Function to reverse the internal vector in its original policy. More...
 
virtual time_t LastUpdate () const =0
 Get the date of the last data (always chronological meaning) More...
 
virtual time_t GetFirstTime () const =0
 Get the date of the first data (always chronological meaning) More...
 
Access to the DataStock elements
virtual DataStockoperator[] (const unsigned int offset)=0
 Access nth element, do not check for the policy chronology. More...
 
virtual const DataStockChronologicAt (const unsigned int offset) const =0
 Get the nth element in a chronological order. More...
 
virtual const DataStockNoChronologicAt (const unsigned int offset) const =0
 Get nth element in a non chronological order. More...
 
Update of the list
virtual void AddData (DataStock &)=0
 Add a copy of the DataStock into the ListDataStock. More...
 
virtual int AddToList (const ListDataStockBase *)=0
 Append all data from a new list ( coming from an Update or ReadCSV normally ) to an existing list. More...
 
virtual void Replace (const ListDataStockBase *)=0
 Replace all DataStock's of the list with ldata_in.data, without checking for update. More...
 
Transform to/from C-Array
virtual unsigned int GetCArray (var_types arraydata_c, const EPChrono b_order, const unsigned int no=0) const =0
 Extract the data into a one dimensional C-array. More...
 
virtual unsigned int GetCArray (var_types2 arraydata_c, const EPChrono b_order, std::initializer_list< unsigned int > list_no) const =0
 Overload version with an initilizer_list, fill a 2 dimensional C-array. More...
 
virtual int PutCArray (const ListDataStockBase &ldata_date, const unsigned int nb_data, const unsigned size_indic, var_types arraydata_c, const unsigned int offset_begin, const unsigned int offset_end=0, const EPChrono b_chrono=EPChrono::CHRONO, bool full_array=false)=0
 Fill a ListDataStock<T> from a 2 dimensional C-array. More...
 

Protected Attributes

std::string name
 name stores the indicator label with the parameters, it corresponds to its ShortName More...
 
ETime tmscl
 TimeScale of the List. More...
 
Utils::firstlast_dates dates
 Store the first and last dates of the list
Redondant with dates from DataStock, added first for reading header of files, selecting a range..
but not easy to keep synchronized and not sure it is really necessary. More...
 
std::string fullname
 fullname seems necessary (convenient) for GUI, never set by constructors More...
 

Private Member Functions

 ListDataStockBase (const ListDataStockBase &src)
 Delete copy constructor. More...
 
ListDataStockBaseoperator= (const ListDataStockBase &rhs)
 Delete assignment operator. More...
 

Detailed Description

Abstract base class for the ListDataStock, for storing base pointers in vectors.

Store:

Definition at line 50 of file ListDataStock.h.

Member Typedef Documentation

typedef boost::variant<float**, double**, int**> ListDataStockBase::var_types

Definition at line 256 of file ListDataStock.h.

typedef boost::variant<float***, double***, int***> ListDataStockBase::var_types2

Definition at line 257 of file ListDataStock.h.

Constructor & Destructor Documentation

ListDataStockBase::ListDataStockBase ( )
inline

Default constructor, set empty names, timescale ETime::not_a_time, dates are zero.

Definition at line 56 of file ListDataStock.h.

ListDataStockBase::ListDataStockBase ( std::string  iname,
ETime  itmscl,
Utils::firstlast_dates  idates = Utils::get_fldate_default () 
)
inline

Constructor sets name, timescale and optionaly dates.

fullname is left empty

Definition at line 67 of file ListDataStock.h.

virtual ListDataStockBase::~ListDataStockBase ( )
inlinevirtual

Destructor.

Definition at line 71 of file ListDataStock.h.

ListDataStockBase::ListDataStockBase ( const ListDataStockBase src)
private

Delete copy constructor.

Member Function Documentation

virtual void ListDataStockBase::AddData ( DataStock )
pure virtual

Add a copy of the DataStock into the ListDataStock.

The policy is not checked here, always insert to the end of the vector(with a push_back())
Dates are not updated
Correct order can later be changed in calling Order( EPChrono chrono_data )

Todo:

maybe insert first, insert last option, order or chronology ? add order best, but inefficient to insert first every time

should use T in derived class, does not make sense otherwise. More flexible ? certainly can use GetX

Parameters
data: DataStock to insert

Implemented in ListDataStock< T, PolicyChronologic >.

Referenced by Stock::ReadCSV(), and StockManager::SendDatadCSV().

Here is the caller graph for this function:

virtual int ListDataStockBase::AddToList ( const ListDataStockBase )
pure virtual

Append all data from a new list ( coming from an Update or ReadCSV normally ) to an existing list.

Effect expected:

  • FirstDates are equal : replace all data, reset the dates, return 0.
  • First date of new == last date of old : check if need to replace the last data of old
  • Continue for update, adding only the new data, check by assert first date of new > last date of last
Precondition
valid dates for the input new_list.
Postcondition
new_list is not modified, it should always be deleted by the calling function. Dates are correctly updated by this function.
Parameters
new_listlist to append
Returns
status : 0 if correct (even if no update), 1 error: if input is nullptr or its size is 0

Implemented in ListDataStock< T, PolicyChronologic >.

Referenced by Stock::AddListDataToMap().

Here is the caller graph for this function:

virtual EPChrono ListDataStockBase::bpolicy ( ) const
pure virtual

Return policy as an enumeration type EPChrono, CHRONO / NO_CHRONO.

Implemented in ListDataStock< T, PolicyChronologic >.

virtual unsigned int ListDataStockBase::Capacity ( ) const
pure virtual

Return the capacity of the vector.

Implemented in ListDataStock< T, PolicyChronologic >.

virtual const DataStock& ListDataStockBase::ChronologicAt ( const unsigned int  offset) const
pure virtual

Get the nth element in a chronological order.

Because the full DataStock object is stored (not a pointer or a base class),
it returns a reference to the exact type (SimpleData, MultiData, DataCSV).

Attention
Do not perform bound-check
It is a reference, it is only valid until the internal vector is not reallocated

ChronologicAt :

  • 0 return the first in time
  • size()-1 return the last in time
Parameters
offsetnth element [0,GetSize()-1]
Returns
a reference to a object derived from DataStock

Implemented in ListDataStock< T, PolicyChronologic >.

Referenced by ListDataStock< T, PolicyChronologic >::AddToList(), ListDataStock< T, PolicyChronologic >::PutCArray(), THistPainterStock::SetLabelXAxis(), and Stock::WriteCSV().

Here is the caller graph for this function:

virtual void ListDataStockBase::Clear ( )
pure virtual

Clear the vector and reinitialize data members to default values.

Call std::vector.clear(), size is set to 0 but capacity is not modified
Reset name and fullname to "" timescale is set to ETime::not_a_time

Implemented in ListDataStock< T, PolicyChronologic >.

virtual unsigned int ListDataStockBase::GetCArray ( var_types  arraydata_c,
const EPChrono  b_order,
const unsigned int  no = 0 
) const
pure virtual

Extract the data into a one dimensional C-array.

Extract only the data, as float or double, not the dates.
The C-array is allocated inside the function and filled in the order given by b_order
With type of DataStock containing more than one data, the user can specify which one to extract.

Precondition
the 1D C-array must not be allocated, only declared
Postcondition
The C-array must be deleted (delete []) by the caller after use

Example to create a single dimensional array with the close values:

float * array;
unsigned int size = list_datacsv.GetCArray2 ( &array, EPChrono::NO_CHRONO, 3 );
// need to deallocate later on
delete[] array

Example to create and fill a multi-dimensional array with CLOSE and Volume:

double ** array2 = new double*[nb_indice];
// creates and fill first indice, CLOSE. Give explicitly the address of the first indice of the array
list_datacsv.GetCArray ( &(array2[0]), EPChrono::CHRONO, as_uint(EDS::ECSV::CLOSE) );
// creates and fill second indice, Volume. Give explicitly the address of the second indice of the array
list_volume.GetCArray ( &(array2[1]), EPChrono::CHRONO );
// later on
for ( unsigned int i = 0; i < nb_indice; ++i )
delete[] array2[i];
delete[] array2;

This second example shows that any combination of data could be append into a c-array.
Then this array could be used to fill a ListDataStock<MultiData> for instance

Note
The second example could not be done with the overloaded method accepting a list initializer
(data must come from the same list, and the array cannot be extended later on)
Parameters
arraydata_cpointer on a one dimensional array
b_orderif the data must be in a chronological or not chronological order
noindicates which field to extract. It is possible to use the enumaration EDS::ECSV
Returns
size of the allocated array

Implemented in ListDataStock< T, PolicyChronologic >.

Referenced by TAlibAPI::Compute().

Here is the caller graph for this function:

virtual unsigned int ListDataStockBase::GetCArray ( var_types2  arraydata_c,
const EPChrono  b_order,
std::initializer_list< unsigned int >  list_no 
) const
pure virtual

Overload version with an initilizer_list, fill a 2 dimensional C-array.

Allocates and fills a 2-dimensional array

Precondition
the C-array should not be allocated, only defined as float** or double **
Postcondition
the C-array has to be deallocated

Example of usage:

// must be only declared, all allocation inside the function
float **array_out;
// will allocate array_out[ size_allocated ][ nb_data ], here 2
size_allocated = list_csv.GetCArray( &array_out, EPChrono::CHRONO, {as_uint(EDS::ECSV::OPEN), as_uint(EDS::ECSV::CLOSE)} );
//later must deallocate
for ( unsigned int i = 0; i < size_allocated; ++i )
delete[] array_out[i];
delete[] array_out;
Parameters
arraydata_cpointer on a 2 dimensional array
b_orderif the data must be in a chronological or non-chronological order
listof data to extract, e.g., {0,2,3} or {ECSV::OPEN, ECVS::CLOSE}
Returns
first size of the allocated array, can be used for deletion

Implemented in ListDataStock< T, PolicyChronologic >.

virtual Utils::firstlast_dates ListDataStockBase::GetDates ( ) const
inlinevirtual

Return the structure Utils::firstlast_dates of the private data member, not from the data.

Definition at line 87 of file ListDataStock.h.

References dates.

Referenced by Stock::WriteCSV().

Here is the caller graph for this function:

time_t ListDataStockBase::GetFirstDate ( ) const
inline

Get first date from the private data member dates.

Definition at line 89 of file ListDataStock.h.

References dates, and Utils::firstlast_dates::first.

Referenced by ListDataStock< T, PolicyChronologic >::AddToList().

Here is the caller graph for this function:

virtual time_t ListDataStockBase::GetFirstTime ( ) const
pure virtual

Get the date of the first data (always chronological meaning)

Implemented in ListDataStock< T, PolicyChronologic >.

Referenced by ListDataStock< T, PolicyChronologic >::AddToList(), and Stock::SaveCSV().

Here is the caller graph for this function:

virtual std::string ListDataStockBase::GetFullName ( ) const
inlinevirtual

Definition at line 79 of file ListDataStock.h.

References fullname.

Referenced by Stock::AddListDataToMap().

Here is the caller graph for this function:

time_t ListDataStockBase::GetLastDate ( ) const
inline

Get last date from the private data member dates.

Definition at line 91 of file ListDataStock.h.

References dates, and Utils::firstlast_dates::last.

Referenced by ListDataStock< T, PolicyChronologic >::AddToList().

Here is the caller graph for this function:

std::string ListDataStockBase::GetName ( ) const
inline
virtual unsigned int ListDataStockBase::GetSize ( ) const
pure virtual
virtual ETime ListDataStockBase::GetTimeScale ( ) const
inlinevirtual
virtual void ListDataStockBase::GetVectorData ( std::vector< DataCSV > &  ,
const EPChrono   
) const
inlinevirtual

Definition at line 133 of file ListDataStock.h.

Referenced by ListDataStock< T, PolicyChronologic >::AddToList(), and ListDataStock< T, PolicyChronologic >::Replace().

Here is the caller graph for this function:

virtual void ListDataStockBase::GetVectorData ( std::vector< SimpleData > &  ,
const EPChrono   
) const
inlinevirtual

Definition at line 134 of file ListDataStock.h.

virtual void ListDataStockBase::GetVectorData ( std::vector< MultiData > &  ,
const EPChrono   
) const
inlinevirtual

Definition at line 135 of file ListDataStock.h.

virtual time_t ListDataStockBase::LastUpdate ( ) const
pure virtual

Get the date of the last data (always chronological meaning)

Implemented in ListDataStock< T, PolicyChronologic >.

Referenced by ListDataStock< T, PolicyChronologic >::AddToList(), Stock::SaveCSV(), and Stock::UpdateCSVFromFile().

Here is the caller graph for this function:

virtual const DataStock& ListDataStockBase::NoChronologicAt ( const unsigned int  offset) const
pure virtual

Get nth element in a non chronological order.

Because the full DataStock object is stored (not a pointer or a base class),
it returns a reference to the exact type (SimpleData, MultiData, DataCSV).

Attention
Do not perform bound-check
It is a reference, it is only valid until the internal vector is not reallocated
Parameters
offsetnth element [0,GetSize()-1]
Returns
a reference to a object derived from DataStock

Implemented in ListDataStock< T, PolicyChronologic >.

Referenced by ListDataStock< T, PolicyChronologic >::PutCArray(), ListObjectStock< T >::SetObjectStock(), PStockLine::SetObjectStock(), CollectionObjectStock::SetObjectStock(), and Stock::WriteCSV().

Here is the caller graph for this function:

ListDataStockBase& ListDataStockBase::operator= ( const ListDataStockBase rhs)
private

Delete assignment operator.

virtual DataStock& ListDataStockBase::operator[] ( const unsigned int  offset)
pure virtual

Access nth element, do not check for the policy chronology.

Implemented in ListDataStock< T, PolicyChronologic >.

virtual void ListDataStockBase::Order ( const EPChrono  chrono)
pure virtual

Function to reverse the internal vector in its original policy.

Need to know the order the data have been added (order_data) using AddData (AddToList should be correct now) Then the call to Order( order_data ), will modify the internal vector order to respect the policy of the list.
If the order is already correct, nothing will be done (known at compile-time).
It allows to use any convenient order in a specific algorithm, and correct only at the end.
Even if the list is created outside the function which implements the algorithm.

Default true from TAlib, indicates if order is chronologic or not

Parameters
b_chronologic, indicates if the data have been inserted chronologicaly or not

Implemented in ListDataStock< T, PolicyChronologic >.

Referenced by Stock::ReadCSV().

Here is the caller graph for this function:

virtual std::string ListDataStockBase::policy ( ) const
pure virtual

Return a string of the chronology policy.

Implemented in ListDataStock< T, PolicyChronologic >.

virtual void ListDataStockBase::PrintData ( const unsigned int  verbose = 0) const
pure virtual

Nice formatting output on console.

verbose :

  • 0 Print first and last data, with header
  • 1 Print all data, no header
Parameters
verbose: add more information, value = 0 (default) or 1

Implemented in ListDataStock< T, PolicyChronologic >.

Referenced by ControllerIndicatorTHStock::AddData().

Here is the caller graph for this function:

virtual int ListDataStockBase::PutCArray ( const ListDataStockBase ldata_date,
const unsigned int  nb_data,
const unsigned  size_indic,
var_types  arraydata_c,
const unsigned int  offset_begin,
const unsigned int  offset_end = 0,
const EPChrono  b_chrono = EPChrono::CHRONO,
bool  full_array = false 
)
pure virtual

Fill a ListDataStock<T> from a 2 dimensional C-array.

Insert all the data of the C-array into the list.
If the indicator has multiple values (MACD), all data are inserted at once with a ListDataStock<MultiData>.
The ldata_date parameter is necessary to set the dates after a computation,
Normally, it is the same List used as input for the computation (allow correct offsets)
Because some indicators may be shorter than the input, e.g. a moving average of X data, TALib uses the concept of offsets.
When putting the data into a List, it should be specified a offset_begin of X.

The algorithm is independent of the policy order of ldata_date or this.
The only important parameter is the order of the c-array: last parameter b_chrono.

Precondition
c-array, a pointer to a 2 dimensional array ?? should work with one dimensional (size_indic 1) ?
For length of c-array nb_data_c must be correct: larger or equal than nb_data == ldata_date - offset_begin - offset_end, (assert, maybe nb_data < later)
For width of c_array size_indic should be valid (c_array at least large enough)
Postcondition
Size of the output is nb_data == ldata_date.size()- offset_begin- offset_end (assert, may be relaxed)
Dates as data members are updated
TimeScale of the output is set according to ldata_date (warning if wrong in input)
Name is left unchanged

Maybe later, a shift for size_indic: extract only relevant columns

Parameters
ldata_datea list which will be used to set the correct dates
nb_datathe number of time data to include, should be smaller or equal to the nb_data_c
size_indicnumber of values for each data, e.g. for MACD = 3
arraydata_cc-array[size_indic][nb_data_c] as input with nb_data_c == nb_data at the moment
offset_beginoffset with the beginning of ldata_date (considered chronological)
offset_endoffset with the end of ldata_date (consider chronological)
b_chronoEPChrono enumeration, indicates in which order the data are stored in the C-array
full_arrayboolean true : a full c-array is used, or false : offset(s) are not present
Returns
status not used yet

Implemented in ListDataStock< T, PolicyChronologic >.

virtual void ListDataStockBase::Replace ( const ListDataStockBase )
pure virtual

Replace all DataStock's of the list with ldata_in.data, without checking for update.

Copy explicitly the data of new_list into this and set the new dates.
=> Pointers to this are still valid.
Insert data respecting the policy of this.
Used by TAlib indicators, always replace the listdata by default

Postcondition
new_list should always be deleted after a replace
Dates in data members are correctly updated

to see later, avoid this expensive copy, try more real update

Parameters
ldata_inlist with new DataStock

Implemented in ListDataStock< T, PolicyChronologic >.

Referenced by Stock::AddListDataToMap().

Here is the caller graph for this function:

virtual void ListDataStockBase::Reserve ( const unsigned int  new_size)
pure virtual

Reserve new_size elements.

Allocate enough memory to store new_size objects without reallocating memory

Parameters
new_sizeof the vector

Implemented in ListDataStock< T, PolicyChronologic >.

virtual void ListDataStockBase::SetDates ( const time_t  first,
const time_t  last 
)
inlinevirtual

Set dates, 2 arguments.

Reimplemented in ListDataStock< T, PolicyChronologic >.

Definition at line 93 of file ListDataStock.h.

References dates, Utils::firstlast_dates::first, and Utils::firstlast_dates::last.

Referenced by Stock::ReadCSV(), and StockManager::SendDatadCSV().

Here is the caller graph for this function:

virtual void ListDataStockBase::SetDates ( const Utils::firstlast_dates new_date)
inlinevirtual

Set dates with a structure Utils::firstlast_dates.

Definition at line 96 of file ListDataStock.h.

References dates.

virtual void ListDataStockBase::SetDates ( )
pure virtual

Set the correct first/last dates from the DataStock in the vector.

to call only after loading the data

Implemented in ListDataStock< T, PolicyChronologic >.

Referenced by ListDataStock< T, PolicyChronologic >::SetDates().

Here is the caller graph for this function:

virtual void ListDataStockBase::SetFullName ( std::string  fname)
inlinevirtual

Definition at line 83 of file ListDataStock.h.

References fullname.

Referenced by Stock::SetLDataFullName().

Here is the caller graph for this function:

void ListDataStockBase::SetName ( const std::string  iname)
inline

Definition at line 82 of file ListDataStock.h.

References name.

Referenced by ListDataStock_Utils::TransformTimeScale().

Here is the caller graph for this function:

virtual void ListDataStockBase::SetTimeScale ( const ETime  new_tmscl)
inlinevirtual

Definition at line 81 of file ListDataStock.h.

References tmscl.

Referenced by ListDataStock_Utils::TransformTimeScale().

Here is the caller graph for this function:

virtual void ListDataStockBase::Swap ( )
pure virtual

Reduce the capacity of the internal vector to fit its size.

Implemented in ListDataStock< T, PolicyChronologic >.

Field Documentation

Utils::firstlast_dates ListDataStockBase::dates
protected

Store the first and last dates of the list
Redondant with dates from DataStock, added first for reading header of files, selecting a range..
but not easy to keep synchronized and not sure it is really necessary.

Definition at line 422 of file ListDataStock.h.

Referenced by GetDates(), GetFirstDate(), GetLastDate(), SetDates(), and ListDataStock< T, PolicyChronologic >::SetDates().

std::string ListDataStockBase::fullname
protected

fullname seems necessary (convenient) for GUI, never set by constructors

Definition at line 425 of file ListDataStock.h.

Referenced by GetFullName(), and SetFullName().

std::string ListDataStockBase::name
protected

name stores the indicator label with the parameters, it corresponds to its ShortName

Definition at line 396 of file ListDataStock.h.

Referenced by GetName(), and SetName().

ETime ListDataStockBase::tmscl
protected

TimeScale of the List.

Definition at line 404 of file ListDataStock.h.

Referenced by GetTimeScale(), and SetTimeScale().


The documentation for this class was generated from the following file: