41 #ifdef DEBUG_DATASTOCK
42 std::cout <<
"Entry reconstruct_stream_operator " << std::endl;
66 strcat( buf_to_ret, buf_date );
67 strcat( buf_to_ret,
",");
68 strcat( buf_to_ret, buf_rest);
70 strcat(buf_to_ret,
",!");
72 size_t len = strlen(buf_to_ret);
74 #ifdef DEBUG_DATASTOCK
75 std::cout <<
"buf_ret: " << buf_to_ret << std::endl;
76 std::cout <<
"return buf_ret length " << len << std::endl;
85 #ifdef DEBUG_DATASTOCK
86 std::cout <<
"DataStock default constructor" << std::endl;
91 #ifdef DEBUG_DATASTOCK
92 std::cout <<
"DataStock constructor with date" << std::endl;
101 #ifdef DEBUG_DATASTOCK
102 std::cout <<
"Copy Constructor Base date: " << rhs.
date << std::endl;
109 #ifdef DEBUG_DATASTOCK
110 std::cout <<
"Move Copy Constructor Base date: " << rhs.date << std::endl;
120 #ifdef DEBUG_DATASTOCK
121 std::cout <<
"DataStock Base Normal assignment " << std::endl;
123 if (
this == &rhs ) {
134 #ifdef DEBUG_DATASTOCK
135 std::cout <<
"DataStock Base Move assignment " << std::endl;
137 if (
this == &rhs ) {
154 struct tm *tmp_tm=localtime(&date);
175 #ifdef DEBUG_DATASTOCK
176 std::cout <<
"DataStock::helper_operator_write_base" << std::endl;
188 #ifdef DEBUG_DATASTOCK
189 std::cout <<
"DataStock::helper_operator_read_base" << std::endl;
200 if ( ios.peek() != 44 )
226 #ifdef DEBUG_DATASTOCK
227 std::cout <<
"Constructor default SimpleData" << std::endl;
232 #ifdef DEBUG_DATASTOCK
233 std::cout <<
"Constructor SimpleData with value" << std::endl;
238 #ifdef DEBUG_DATASTOCK
239 std::cout <<
"Constructor SimpleData default date and value" << std::endl;
250 #ifdef DEBUG_DATASTOCK
251 std::cout <<
"Copy Constructor SimpleData" << std::endl;
261 #ifdef DEBUG_DATASTOCK
262 std::cout <<
"Move Copy Constructor SimpleData" << std::endl;
273 #ifdef DEBUG_DATASTOCK
274 std::cout <<
"SimpleData Normal assignment " << std::endl;
277 if (
this == &rhs ) {
290 #ifdef DEBUG_DATASTOCK
291 std::cout <<
"SimpleData Move assignment " << std::endl;
294 if (
this == &rhs ) {
308 std::vector<type_value_data> vec_value;
309 vec_value.push_back(
value );
315 assert( vec.size() == 1 );
323 SetValue( Utils::fromString<type_value_data>(linecsv[1]) );
330 std::cout <<
"Entry SimpleData::HasChanged" << std::endl;
332 std::cout <<
"Date of the old data " <<
GetDate() << std::endl;
333 std::cout <<
"Date of the old data " <<
GetDateString() << std::endl;
334 std::cout <<
" value old " <<
GetValue() << std::endl;
336 std::cout <<
"Date of the new data " << data_to_check.
GetDate() << std::endl;
337 std::cout <<
"Date of the new data " << data_to_check.
GetDateString() << std::endl;
339 std::cout <<
"new value " <<
static_cast<const SimpleData &
>(data_to_check).
GetValue() << std::endl;
355 std::cout <<
" SimpleData value differ, return true " << std::endl;
366 std::ostringstream tmp_os;
368 if ( verbose == 1 ) {
369 std::cout <<
"PrintData SimpleData " << std::endl;
370 std::cout << std::setw(25) <<
"date" << std::setw(
FDS::WCOL+1) <<
"value" << std::endl;
377 std::cout <<
" " << tmp_os.str() << std::endl;
379 std::cout << tmp_os.str() << std::endl;
399 #ifdef DEBUG_DATASTOCK
400 std::cout <<
"Constructor default MultiData" << std::endl;
413 #ifdef DEBUG_DATASTOCK
414 std::cout <<
"Constructor MultiData with size: " << nbdata << std::endl;
425 #ifdef DEBUG_DATASTOCK
426 std::cout <<
"Constructor MultiData date and values " << std::endl;
435 #ifdef DEBUG_DATASTOCK
436 std::cout <<
"Copy Constructor MultiData" << std::endl;
447 #ifdef DEBUG_DATASTOCK
448 std::cout <<
"Move Copy Constructor MultiData" << std::endl;
463 #ifdef DEBUG_DATASTOCK
464 std::cout <<
"MultiData Normal assignement " << std::endl;
467 if (
this == &rhs ) {
486 #ifdef DEBUG_DATASTOCK
487 std::cout <<
"MultiData Move assignment " << std::endl;
490 if (
this == &rhs ) {
507 std::vector<type_value_data>::const_iterator it;
510 if ( (*it) > max ) max = (*it);
519 std::vector<type_value_data>::const_iterator it;
521 if ( (*it) < min ) min = (*it);
537 assert (
nb_data == vec.size() );
538 assert ( vec.size() ==
values.size() );
547 assert (
nb_data == dynamic_cast<const MultiData &>(data_to_check).
nb_data );
549 assert ( nb_data == data_to_check.
GetValues().size() );
554 std::cout <<
" MultiData at least one value differ, return true " << std::endl;
564 assert( (
nb_data + 1) == linecsv.size() );
567 std::vector<type_value_data> tmp_values;
573 for (
auto v= linecsv.begin()+1; v != linecsv.end(); ++v ) {
574 tmp_values.push_back( Utils::fromString<type_value_data>(*v) );
585 std::ostringstream tmp_os;
587 if ( verbose == 1 ) {
588 std::cout <<
"PrintData MultiData " << std::endl;
589 std::cout << std::setw(25) <<
"date" << std::setw(
FDS::WCOL+1) <<
"values" << std::endl;
597 std::cout <<
" " << tmp_os.str() << std::endl;
599 std::cout << tmp_os.str() << std::endl;
606 for (
unsigned int i=0; i<
nb_data; ++i) {
613 std::vector<type_value_data> vec_values;
617 for (
unsigned int i=0; i<
nb_data; ++i) {
628 #ifdef DEBUG_DATASTOCK
629 std::cout <<
"Constructor default DataCSV" << std::endl;
635 DataStock(d), open(iopen),high(ihigh),low(ilow),close(iclose) {
636 #ifdef DEBUG_DATASTOCK
637 std::cout <<
"Constructor DataCSV with 5 arguements " << std::endl;
647 #ifdef DEBUG_DATASTOCK
648 std::cout <<
"copy constructor DataCSV " << std::endl;
660 #ifdef DEBUG_DATASTOCK
661 std::cout <<
"Move Copy Constructor DataCSV" << std::endl;
679 #ifdef DEBUG_DATASTOCK
680 std::cout <<
"DataCSV Normal assignement " << std::endl;
683 if (
this == &rhs ) {
699 #ifdef DEBUG_DATASTOCK
700 std::cout <<
"DataCSV Move assignment " << std::endl;
703 if (
this == &rhs ) {
728 low = std::numeric_limits<type_value_data>::max();
729 high = std::numeric_limits<type_value_data>::min();
773 std::vector<type_value_data> vec_value;
774 vec_value.push_back(
open );
775 vec_value.push_back(
high );
776 vec_value.push_back(
low );
777 vec_value.push_back(
close );
785 std::cout <<
"Extractline DataCSV" << std::endl;
795 tmp_open = Utils::fromString<type_value_data> ( linecsv[1] );
796 tmp_high = Utils::fromString<type_value_data> ( linecsv[2] );
797 tmp_low = Utils::fromString<type_value_data> ( linecsv[3] );
798 tmp_close = Utils::fromString<type_value_data>( linecsv[4] );
800 SetData( tmp_date, tmp_open, tmp_high, tmp_low, tmp_close);
812 std::cout <<
"\n\t Entry DataCSV::HasChanged " << std::endl;
814 std::cout <<
"Date of the old data " <<
GetDateString() << std::endl;
815 std::cout <<
"old Close " <<
GetClose() << std::endl;
818 std::cout <<
"Date of the new data " << data_to_check.
GetDateString() << std::endl;
819 std::cout <<
"new Close " << ((
DataCSV &)data_to_check).GetClose() << std::endl;
826 std::cout <<
" date differ so it is a new data, return replace_last false" << std::endl;
830 std::cout <<
"Same date, check Close " << std::endl;
834 std::cout <<
" Close differ, real update of the candle, return true " << std::endl;
837 std::cout <<
" Close identical, mean that is the beginning of a new value, return false " << std::endl;
864 std::ostringstream tmp_os;
866 if ( verbose == 1 ) {
867 std::cout <<
"PrintData DataCSV"<< std::endl;
868 std::cout << std::setw(25) <<
"date" << std::setw(
FDS::WCOL+1) <<
"open" <<
870 std::setw(
FDS::WCOL+1) <<
"close " << std::endl;
878 std::cout <<
" " << tmp_os.str() << std::endl;
880 std::cout << tmp_os.str() << std::endl;
896 std::vector<type_value_data> vec_values;
897 vec_values.reserve(4);
900 for (
unsigned int i=0; i< 4; ++i) {
912 return ( ( lhs.
date == rhs.
date ) &&
918 return ( ( lhs.
date == rhs.
date ) &&
924 return ( ( lhs.
date == rhs.
date ) &&
939 if ( os.tellp() == 0 || os.tellp() == -1 )
955 if ( ( (ios.rdstate() & std::iostream::eofbit ) != 0 ) ||
956 ( (ios.rdstate() & std::iostream::failbit) != 0 ) ) {
957 std::cout <<
"DataStock eofbit or fail nothing more to read from the stream, set fail " << std::endl;
958 ios.setstate ( std::iostream::failbit);
965 ios.setstate ( std::iostream::failbit);
976 if ( ios.eof() || (ios.peek() ==
'!') ) {
977 ios.setstate ( std::iostream::eofbit);
986 ios.write( buf_ret, len_buf );
992 std::ostringstream stream;
994 stream << line_csv << obj;
995 line_csv = stream.str();
1001 std::stringstream ss(line_csv);
1005 if ( ss.eof() ==
true && ss.fail() == false )
1009 line_csv = ss.str();
Generalisation of SimpleData, contains a vector of type_value_data values.
std::iostream & operator>>(std::iostream &ios, DataStock &obj)
SimpleData()
Default constructor, set value to 0.
virtual void SetData(const time_t d, const std::vector< type_value_data > &vec)
Set a full Data : date + value(s) in a vector.
void helper_operator_write_base(std::ostream &os) const
Helper function for operator>> for writing date to output.
std::ostream & operator<<(std::ostream &os, const DataStock &obj)
virtual void ExtractCSVLine(std::vector< std::string > &linecsv)
Extract date and data from a split string.
type_value_data GetValue() const
Get the unique value.
type_value_data GetClose() const
DataStock()
Default constructor set date to 0.
void SetDate(const time_t d)
Modify the date.
const int BUFFER_DATE
Contains the date, exactly 19 characters + terminal (terminal not really crucial) ...
double fromStreamToDouble(std::iostream &stream, char delim)
Read the next character of a stream as a double.
virtual void ExtractCSVLine(std::vector< std::string > &linecsv)
Extract date and data from a split string.
const unsigned int nb_data
Number of data stored in the vector.
const int BUFFER_STREAM
Maximum size buffer intermediate for stream.
virtual bool HasChanged(const DataStock &data_to_check) const
Check if data are different.
void SetData(const time_t d, const std::vector< type_value_data > &vec)
Set a full Data : date + value(s) in a vector.
double type_value_data
Type of the floating values to be stored, can be set to float or double before compilation.
DataCSV()
Default constructor, set date and all values to 0.
void SetValue(const type_value_data ivalue)
Set the unique value.
void PrintData(const unsigned int verbose=0) const
User friendly output on screen.
void PrintData(const unsigned int verbose=0) const
User friendly output on screen.
void SetValues(std::vector< type_value_data > &vec)
Set only values, do not modify the date.
virtual void helper_operator_read(std::iostream &ios)
void PrintData(const unsigned int verbose=0) const
User friendly output on screen.
DataStock & operator=(const DataStock &rhs)
Normal assignment.
DataCSV & operator=(const DataCSV &rhs)
Normal assignment.
void Reset()
Set high and low values respectively to the minimum and maximum possible values for the type...
virtual void helper_operator_write(std::ostream &os) const
Data type to describe Japanese candlesticks : open, high, low and close values.
Classes for data to be stored in ListDataStock.
const time_t ERROR_StrToTime
Error code returned by StringToTime_t if the string cannot be parsed correctly Must be a time_t...
virtual std::vector< type_value_data > GetValues() const
Return the values in a vector, always 4 values: open, high, low, close.
virtual void helper_operator_write(std::ostream &os) const
virtual std::vector< type_value_data > GetValues() const
Return the value(s) in a vector.
virtual std::vector< type_value_data > GetValues() const =0
Return the value(s) in a vector.
virtual void AdditionData(const DataCSV &new_data)
With an other candlestick.
int helper_operator_read_base(std::iostream &ios)
Helper function for operator<< for reading date from input streams.
bool operator==(const SimpleData &lhs, const SimpleData &rhs)
std::string Time_tToString(const time_t &time, const bool b_hour)
Return a string representing the date All times are expressed in the localtime.
virtual void SetValues(std::vector< type_value_data > &vec)
Set the values with the same order.
std::vector< type_value_data > values
Vector for storing values.
virtual void helper_operator_read(std::iostream &ios)
virtual void helper_operator_read(std::iostream &ios)=0
time_t StringToTime_t(const std::string &str_date)
Return the time_t from a string .
virtual void helper_operator_write(std::ostream &os) const =0
virtual std::vector< type_value_data > GetValues() const
Return the value(s) in a vector.
type_value_data GetOpen() const
const int WCOL
Witdh of the values with setw.
const int PRECISION
Precison of floating numbers.
Derive class which contains only one value of type type_value_data (float or double).
virtual bool HasChanged(const DataStock &data_to_check) const
Check if data are different.
virtual void helper_operator_write(std::ostream &os) const
MultiData()
Default constructor, set number of data to 1 and a default value of 0.
virtual bool HasChanged(const DataStock &data_to_check) const
Check if data are different.
SimpleData & operator=(const SimpleData &rhs)
Normal assignment.
type_value_data GetLow() const
time_t GetDate() const
Get the date data member.
type_value_data GetHigh() const
MultiData & operator=(const MultiData &rhs)
Normal assignment.
std::string GetDateString(const bool bhours=true) const
Return the date in a string format: "YEAR-MOnth-DAy HH:MM:SS" (2014-11-10 13::25::00) ...
size_t reconstruct_stream_operator(std::iostream &is, char *buf_to_ret)
Reconstruct a stream in skipping the values already consumed This is used by friend operator>> ( iost...
virtual void helper_operator_read(std::iostream &ios)
virtual void ExtractCSVLine(std::vector< std::string > &linecsv)
Extract the data from a splitted string.
time_t date
All data have a date associated.
virtual type_value_data GetMinimum() const
Get the minimum value.
virtual type_value_data GetMaximum() const
Get the maximum value.
virtual void SetValues(std::vector< type_value_data > &vec)
Set only values, do not modify the date.
Abstract base class for all Data to be stored in ListDataStock.