ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DataStock.h
Go to the documentation of this file.
1 
13 #ifndef DATASTOCK_H_
14 #define DATASTOCK_H_
15 
16 #include <ctime>
17 #include <string>
18 #include <iostream>
19 #include <sstream>
20 #include <vector>
21 #include "../utils/Utils.h"
22 
23 
24 // to do: GetValues both for std::vector both float and double (easy for unit_test)
25 // want to overload SetData(most common use) or oblige user to use type_value_data ??
26 // did not modify
27 
28 // note: more efficient than stringstream
29 // http://live.boost.org/doc/libs/1_42_0/doc/html/interprocess/streams.html
30 
31 // if use noexcept, swap with move ? swap( A, B) only, makes sense
32 // http://stackoverflow.com/questions/6416385/move-semantics-custom-swap-function-obsolete
33 
34 // ok, ObjectStock has been cleaned ! Only SetObjectStock function(internal no interface) need type_value_data and transform into intern => double
35 // it is needed only to get the values there, so no need to extend GetValues
36 // For SetValues uni-test it is only to set the object, not for algo PutCArray/GetCArray (to check)
37 
38 // to delete comments when sure
39 // many changes done to compile, to check later:
40 // - list_data_stock_Carray.cpp, problem with set up of SetData (changed of 4-6 tmp_vec with type_value_data)
41 // Not a problem if it is to setup the DataStock, and not to deal with PutCArray/GetCarray
42 // - ObjectStock.cxx Many float and double used ( need to consider which one must be changed )
43 // SetObjectStock(2 changes), extract from ListData, need typedef. SetValues(4 changes)
44 // Many other related.
45 // - AbstractStock.h redeclare the typedef directly, need to see if intermediate(global) file is better (typedef.h) for instance !!
46 
49 typedef double type_value_data;
50 //typedef float type_value_data;
51 
56 namespace EDS {
58  enum class ECSV : unsigned int { OPEN=0, HIGH, LOW, CLOSE };
60  // template must be in header
61  template <typename ECSV>
62  unsigned int as_uint(const ECSV value) {
63  return static_cast<unsigned int>(value); }
64 }
65 
69 namespace BDS {
77  const int BUFFER_STREAM = 256;
79  const int BUFFER_DATE = 20;
80  //}@
81 } // end group_operator
83 
90 class DataStock {
91 
92 protected:
97  time_t date;
98 
99 public:
103  DataStock();
105  DataStock(time_t d);
107  DataStock (const DataStock & rhs);
109  DataStock (DataStock && rhs);
111  virtual ~DataStock() {}
113 
115  //{@
117  DataStock& operator=( const DataStock& rhs );
119  DataStock& operator=( DataStock&& rhs);
120  //}@
121 
126  time_t GetDate() const {return date;}
130  void SetDate(const time_t d) { date = d; }
137  std::string GetDateString( const bool bhours = true ) const;
144  // used by Transform_*, need WEEK infos, used by Stock
145  // \todo to make in Utils but only when tests will written
146  struct tm GetDateTm() const;
148 
152  // used by PutCArray, (GetCArray ??)
153  virtual void SetData( const time_t d, const std::vector<type_value_data> & vec ) =0;
154  // GetData ? date + value(s), not useful ?
156  virtual std::vector<type_value_data> GetValues() const =0;
157  // SetValues useful.., at least some symmetry...
159  virtual void SetValues( std::vector<type_value_data> & ) =0;
160 
162  // could return a reference to avoid a copy ?? simple value not needed
163  virtual type_value_data GetMaximum() const =0;
165  virtual type_value_data GetMinimum() const =0;
178  virtual bool HasChanged( const DataStock & data_to_check ) const =0;
184  virtual void ExtractCSVLine(std::vector<std::string> &vec) =0;
185 
194  virtual void PrintData( const unsigned int verbose = 0 ) const =0;
196 
226  friend std::ostream& operator<<(std::ostream& os, const DataStock& obj);
227 
258 #ifndef __CINT__
259  friend std::iostream& operator>>(std::iostream& ios, DataStock& obj);
260 #endif
261 
275  friend std::string& operator<<(std::string &line_csv, const DataStock& obj);
276 
288  friend std::string& operator>>(std::string &line_csv, DataStock& obj);
290 
293  virtual void helper_operator_write(std::ostream &os) const =0;
294 #ifndef __CINT__
295  virtual void helper_operator_read(std::iostream &ios) =0;
296 #endif
297 
298 
299 protected:
306  // page 1329, base class should be an helper function, no need of public friends
307  // good, easier to add parameter for b_hour or get error in parsing date
308 #ifndef __CINT__
309  int helper_operator_read_base(std::iostream& ios);
310 #endif
311 
316  // can test with if (os.rdbuf() == std::cout.rdbuf() ), not for all
317  // or tellp return always -1
318  void helper_operator_write_base(std::ostream& os) const;
319  // miss operator ==, for use with base needed ?? not really
320  //end of group_operator
322 };
323 
325 
330  // 32bits, float, better for volume than MultiData(24 empty, 28 with one value?)
331  // sizeof(SimpleData) = 12 = 4 (time_t) + 4(float), miss 4 ??
332  //
333  // 64bits, double
334  // sizeof(SimpleData) = 24
335 class SimpleData: public DataStock {
336 
337 private:
339 
340 public:
342  SimpleData();
344  SimpleData( type_value_data ivalue );
346  SimpleData( time_t d, type_value_data ivalue );
348  SimpleData( unsigned int /*nb*/ );
350  SimpleData( const SimpleData & rhs );
352  SimpleData( SimpleData && rhs );
354  virtual ~SimpleData() {}
355 
359  SimpleData& operator=( const SimpleData& rhs );
363 
366  virtual void SetData(const time_t d, const std::vector<type_value_data> & vec) {date=d;value=vec[0];}
367  // here for sure cannot return a ref on vector, because created
368  virtual std::vector<type_value_data> GetValues() const;
369  // brief Set the value (only one), do not modify the date.
370  // vec should have a size of 1, test by assert\n
371  // For SimpleData, SetValue can be used
372  //
373  virtual void SetValues( std::vector<type_value_data> & vec);
375  virtual type_value_data GetMaximum() const {return value;}
377  virtual type_value_data GetMinimum() const {return value;}
378  virtual bool HasChanged( const DataStock & data_to_check ) const;
383  virtual void ExtractCSVLine(std::vector<std::string> & linecsv);
384  void PrintData( const unsigned int verbose = 0) const;
386 
389  //void Reset() // needed ?, not anymore
391  type_value_data GetValue() const {return value;}
393  void SetValue(const type_value_data ivalue) {value=ivalue;}
395  void SetData( const time_t d, const type_value_data ivalue ) {date = d; value = ivalue;}
397 
398  // Book says must be friend to get implicit conversion... not really needed here ?
400  friend bool operator==( const SimpleData & lhs, const SimpleData & rhs );
401 
402 protected :
408  virtual void helper_operator_write(std::ostream &os) const;
409 #ifndef __CINT__
410  virtual void helper_operator_read(std::iostream &ios);
411 #endif
412 
413  // end group_operator
414 
415 };
416 
418 
427  // 32 bits, float
428  //sizeof(MutliData without data) = 24 = 4(nb_data) + 4(time_t) + 4 (unsigned int) + 1 pointers vec(12)
429  // == 12 (no space for vtable pointer)
430  // 64bits, double
431  // sizeof(MultiData) = 48
432 class MultiData: public DataStock {
433 
434 private:
437  const unsigned int nb_data;
438  // always sizeof(12) (asus 32bits), only a ref. To compare with std::array
440  std::vector<type_value_data> values;
441 
442 public:
444  MultiData();
446  MultiData( unsigned int nbdata );
448  MultiData(time_t d, std::vector<type_value_data> ivalues);
450  MultiData( const MultiData & rhs );
452  MultiData( MultiData&& rhs );
453  virtual ~MultiData() {};
454 
460  MultiData& operator=( const MultiData& rhs );
462  MultiData& operator=( MultiData&& rhs);
464 
467  void SetData(const time_t d, const std::vector<type_value_data> & vec) {date=d;values=vec;}
468  virtual std::vector<type_value_data> GetValues() const;
469  void SetValues( std::vector<type_value_data> & vec);
470  virtual type_value_data GetMaximum() const;
471  virtual type_value_data GetMinimum() const;
472  virtual bool HasChanged( const DataStock & data_to_check ) const;
473  virtual void ExtractCSVLine(std::vector<std::string> & linecsv);
474  void PrintData( const unsigned int verbose = 0 ) const;
476 
477  friend bool operator==( const MultiData & lhs, const MultiData & rhs );
478 
479 protected :
484  virtual void helper_operator_write(std::ostream &os) const;
485 #ifndef __CINT__
486  virtual void helper_operator_read(std::iostream &ios);
487 #endif
488 
489  //end group_operator
490 };
491 
493 
497  // on 32-bits, float
498  // sizeof(DataCSV) = 24 != 16(4 for a float)+ time_t(4) + ?? 1 pointer vtable (4)
499  //
500  // 64bits, double
501  // sizeof(DataCSV) = 48
502 class DataCSV: public DataStock {
503 
504 private:
509 
510 public:
511 
513  DataCSV();
515  DataCSV(time_t d, type_value_data iopen, type_value_data ihigh,
516  type_value_data ilow, type_value_data iclose);
518  DataCSV( unsigned int /*nb*/ );
520  DataCSV(const DataCSV & rhs);
522  DataCSV( DataCSV && rhs );
524  virtual ~DataCSV() {}
525 
529  DataCSV& operator=( const DataCSV& rhs );
531  DataCSV& operator=( DataCSV&& rhs);
533 
536  virtual void SetData( const time_t d, const std::vector<type_value_data> & vec);
538  virtual std::vector<type_value_data> GetValues() const;
540  virtual void SetValues ( std::vector<type_value_data> & vec );
541  virtual type_value_data GetMaximum() const {return GetHigh();}
542  virtual type_value_data GetMinimum() const {return GetLow();}
543  virtual bool HasChanged( const DataStock & data_to_check ) const;
544  virtual void ExtractCSVLine(std::vector<std::string> & linecsv);
545  void PrintData( const unsigned int verbose = 0 ) const;
547 
552  type_value_data GetOpen() const {return open;}
553  type_value_data GetHigh() const {return high;}
554  type_value_data GetLow() const {return low;}
555  type_value_data GetClose() const {return close;}
556  void SetOpen( type_value_data iopen) { open=iopen; }
557  void SetClose( type_value_data iclose) { close=iclose; }
558  void SetHigh( type_value_data ihigh) { high=ihigh; }
559  void SetLow( type_value_data ilow) { low=ilow; }
563  void Reset();
565  void SetValues(const type_value_data iopen, const type_value_data ihigh ,
566  const type_value_data ilow, const type_value_data iclose);
568  void SetData(const time_t d ,const type_value_data iopen, const type_value_data ihigh,
569  const type_value_data ilow, const type_value_data iclose);
571  // could update Open or Close at the same time, but will be dependent of the order of the algo
572  // change name UpdateLowHigh, MergeCandle
580  virtual void AdditionData( const DataCSV & new_data );
582  virtual void AdditionData ( const SimpleData & new_data );
584 
586  friend bool operator==( const DataCSV & lhs, const DataCSV & rhs );
587 
588 protected :
593  virtual void helper_operator_write(std::ostream &os) const;
594 #ifndef __CINT__
595  virtual void helper_operator_read(std::iostream &ios);
596 #endif
597 
598  // end group_operator
599 };
600 
601 #endif /* DATASTOCK_H_ */
Generalisation of SimpleData, contains a vector of type_value_data values.
Definition: DataStock.h:432
SimpleData()
Default constructor, set value to 0.
Definition: DataStock.cpp:225
virtual void SetData(const time_t d, const std::vector< type_value_data > &vec)
Set a full Data : date + value(s) in a vector.
Definition: DataStock.cpp:754
void helper_operator_write_base(std::ostream &os) const
Helper function for operator>> for writing date to output.
Definition: DataStock.cpp:173
type_value_data high
Definition: DataStock.h:507
virtual void ExtractCSVLine(std::vector< std::string > &linecsv)
Extract date and data from a split string.
Definition: DataStock.cpp:562
type_value_data GetValue() const
Get the unique value.
Definition: DataStock.h:391
virtual type_value_data GetMinimum() const
Get the minimum value, only one value in this class.
Definition: DataStock.h:377
type_value_data GetClose() const
Definition: DataStock.h:555
virtual type_value_data GetMaximum() const
Get the maximum value.
Definition: DataStock.h:541
virtual void ExtractCSVLine(std::vector< std::string > &vec)=0
Extract date and data from a split string.
ECSV
Convenient enumeration for DataCSV, convertible to unsigned int for a general use in algorithms...
Definition: DataStock.h:58
virtual type_value_data GetMaximum() const
Get the maximum value, only one value in this class.
Definition: DataStock.h:375
DataStock()
Default constructor set date to 0.
Definition: DataStock.cpp:84
void SetDate(const time_t d)
Modify the date.
Definition: DataStock.h:130
virtual ~DataStock()
Destructor.
Definition: DataStock.h:111
const int BUFFER_DATE
Contains the date, exactly 19 characters + terminal (terminal not really crucial) ...
Definition: DataStock.h:79
virtual void ExtractCSVLine(std::vector< std::string > &linecsv)
Extract date and data from a split string.
Definition: DataStock.cpp:782
const unsigned int nb_data
Number of data stored in the vector.
Definition: DataStock.h:437
virtual void SetData(const time_t d, const std::vector< type_value_data > &vec)=0
Set a full Data : date + value(s) in a vector.
const int BUFFER_STREAM
Maximum size buffer intermediate for stream.
Definition: DataStock.h:77
virtual bool HasChanged(const DataStock &data_to_check) const
Check if data are different.
Definition: DataStock.cpp:544
void SetData(const time_t d, const std::vector< type_value_data > &vec)
Set a full Data : date + value(s) in a vector.
Definition: DataStock.h:467
unsigned int as_uint(const ECSV value)
function to provide a cast of ECSV to unsigned int
Definition: DataStock.h:62
double type_value_data
Type of the floating values to be stored, can be set to float or double before compilation.
Definition: DataStock.h:49
DataCSV()
Default constructor, set date and all values to 0.
Definition: DataStock.cpp:626
void SetHigh(type_value_data ihigh)
Definition: DataStock.h:558
friend std::ostream & operator<<(std::ostream &os, const DataStock &obj)
Fill ostream ( ostringstream ) with text data .
Definition: DataStock.cpp:936
void SetValue(const type_value_data ivalue)
Set the unique value.
Definition: DataStock.h:393
void PrintData(const unsigned int verbose=0) const
User friendly output on screen.
Definition: DataStock.cpp:861
void PrintData(const unsigned int verbose=0) const
User friendly output on screen.
Definition: DataStock.cpp:363
void SetValues(std::vector< type_value_data > &vec)
Set only values, do not modify the date.
Definition: DataStock.cpp:534
virtual void helper_operator_read(std::iostream &ios)
Definition: DataStock.cpp:389
void PrintData(const unsigned int verbose=0) const
User friendly output on screen.
Definition: DataStock.cpp:582
DataStock & operator=(const DataStock &rhs)
Normal assignment.
Definition: DataStock.cpp:118
virtual bool HasChanged(const DataStock &data_to_check) const =0
Check if data are different.
virtual type_value_data GetMaximum() const =0
Get the maximum value.
DataCSV & operator=(const DataCSV &rhs)
Normal assignment.
Definition: DataStock.cpp:677
void Reset()
Set high and low values respectively to the minimum and maximum possible values for the type...
Definition: DataStock.cpp:724
type_value_data close
Definition: DataStock.h:507
virtual void helper_operator_write(std::ostream &os) const
Definition: DataStock.cpp:384
Data type to describe Japanese candlesticks : open, high, low and close values.
Definition: DataStock.h:502
virtual ~DataCSV()
Destructor.
Definition: DataStock.h:524
type_value_data low
Definition: DataStock.h:507
virtual void SetValues(std::vector< type_value_data > &)=0
Set only values, do not modify the date.
virtual std::vector< type_value_data > GetValues() const
Return the values in a vector, always 4 values: open, high, low, close.
Definition: DataStock.cpp:771
virtual void helper_operator_write(std::ostream &os) const
Definition: DataStock.cpp:604
virtual std::vector< type_value_data > GetValues() const
Return the value(s) in a vector.
Definition: DataStock.cpp:306
virtual type_value_data GetMinimum() const =0
Get the minimum value.
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.
Definition: DataStock.cpp:843
int helper_operator_read_base(std::iostream &ios)
Helper function for operator<< for reading date from input streams.
Definition: DataStock.cpp:186
virtual void SetValues(std::vector< type_value_data > &vec)
Set the values with the same order.
Definition: DataStock.cpp:763
friend bool operator==(const MultiData &lhs, const MultiData &rhs)
Definition: DataStock.cpp:916
std::vector< type_value_data > values
Vector for storing values.
Definition: DataStock.h:440
virtual void helper_operator_read(std::iostream &ios)
Definition: DataStock.cpp:611
void SetOpen(type_value_data iopen)
Definition: DataStock.h:556
virtual void SetData(const time_t d, const std::vector< type_value_data > &vec)
Set a full Data : date + value(s) in a vector.
Definition: DataStock.h:366
virtual void helper_operator_read(std::iostream &ios)=0
void SetData(const time_t d, const type_value_data ivalue)
Set the date and value.
Definition: DataStock.h:395
void SetLow(type_value_data ilow)
Definition: DataStock.h:559
friend std::iostream & operator>>(std::iostream &ios, DataStock &obj)
Set a DataStock(s) with data from a iostream( e.g.,stringstream ) .
Definition: DataStock.cpp:948
virtual ~MultiData()
Definition: DataStock.h:453
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.
Definition: DataStock.cpp:529
type_value_data GetOpen() const
Definition: DataStock.h:552
virtual void PrintData(const unsigned int verbose=0) const =0
User friendly output on screen.
void SetClose(type_value_data iclose)
Definition: DataStock.h:557
struct tm GetDateTm() const
Get a tm structure of the date.
Definition: DataStock.cpp:151
Derive class which contains only one value of type type_value_data (float or double).
Definition: DataStock.h:335
virtual bool HasChanged(const DataStock &data_to_check) const
Check if data are different.
Definition: DataStock.cpp:809
virtual void helper_operator_write(std::ostream &os) const
Definition: DataStock.cpp:885
MultiData()
Default constructor, set number of data to 1 and a default value of 0.
Definition: DataStock.cpp:398
virtual bool HasChanged(const DataStock &data_to_check) const
Check if data are different.
Definition: DataStock.cpp:327
virtual ~SimpleData()
Destructor.
Definition: DataStock.h:354
SimpleData & operator=(const SimpleData &rhs)
Normal assignment.
Definition: DataStock.cpp:271
type_value_data GetLow() const
Definition: DataStock.h:554
time_t GetDate() const
Get the date data member.
Definition: DataStock.h:126
type_value_data GetHigh() const
Definition: DataStock.h:553
MultiData & operator=(const MultiData &rhs)
Normal assignment.
Definition: DataStock.cpp:461
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) ...
Definition: DataStock.cpp:164
virtual void helper_operator_read(std::iostream &ios)
Definition: DataStock.cpp:894
virtual void ExtractCSVLine(std::vector< std::string > &linecsv)
Extract the data from a splitted string.
Definition: DataStock.cpp:320
type_value_data open
Definition: DataStock.h:507
virtual type_value_data GetMinimum() const
Get the minimum value.
Definition: DataStock.h:542
friend bool operator==(const DataCSV &lhs, const DataCSV &rhs)
Compare all fields, date and values.
Definition: DataStock.cpp:922
time_t date
All data have a date associated.
Definition: DataStock.h:97
virtual type_value_data GetMinimum() const
Get the minimum value.
Definition: DataStock.cpp:516
virtual type_value_data GetMaximum() const
Get the maximum value.
Definition: DataStock.cpp:504
friend bool operator==(const SimpleData &lhs, const SimpleData &rhs)
Compare date and value.
Definition: DataStock.cpp:910
virtual void SetValues(std::vector< type_value_data > &vec)
Set only values, do not modify the date.
Definition: DataStock.cpp:313
type_value_data value
Definition: DataStock.h:338
Abstract base class for all Data to be stored in ListDataStock.
Definition: DataStock.h:90