ROOT_Application  2.0
C++ Core modules and GUIStock
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StockManager.h
Go to the documentation of this file.
1 
10 #ifndef STOCKMANAGER_H_
11 #define STOCKMANAGER_H_
12 
13 // included already, but looks strange do not include
14 #include <vector>
15 #include <iostream>
16 
17 // This includes is equivalent, Stock needed by some(one) controller
18 // convenient for GUI include, but more dependencies
19 // or set in an independent header APIStock.h to use by client
20 //#include "Stock.h"
21 class Stock;
22 class ListDataStockBase;
23 // contains Indicator and TimeScale
24 #include "../utils/FullName.h"
25 #include "../utils/Utils.h"
26 
27 #include "StockException.h"
28 
29 // forward declaration
30 class TCPServer;
31 class SMSubject;
32 
42 class StockManager {
43 
44  private:
47  typedef std::vector<Stock *>::iterator it_stock;
48  typedef std::vector<Stock *>::const_iterator cit_stock;
50 
54  static bool status_sm;
57 
58  // no a bad idea to set the path here, could change from GUI (test, real data..) ??
59  // should see for use of global UTILS now
61  static std::string fpath;
62 
64  static TCPServer *ftcp;
68 
70  std::vector< Stock * > vec_stock;
71 
74  ~StockManager();
76  StockManager( const StockManager& ); // {};
77  StockManager& operator=(const StockManager&); // {};
78 
82  void InsertVec_Stock ( Stock * );
84  it_stock GetItStock ( const std::string& namestock );
86  cit_stock GetItStock ( const std::string& namestock ) const;
88 
89  public:
93  // Need to be static (or use a static variable inside the function)
94  static StockManager* getInstance( std::string new_path="." );
96  // Need to be static
97  static void killInstance();
98 
99  //this one do not need to be static, called by sm->GetStatus(), one object has already been created
101  bool GetStatus() const { return status_sm;}
102  //bool GetStatusServer() const { return ftcp;}
103 
104  //for test, because of solved bug
105  std::string GetPath() const { return fpath;}
107  void SetPath(std::string new_path) {StockManager::fpath = new_path;}
109 
111  // to delete gui_main_controller should do this, if script can control as well
113 
114  bool ActivateServer();
115  bool DesactivateServer();
116  TCPServer * GetServer() const { return ftcp; }
117  void SetServer( TCPServer *tcp ) { ftcp=tcp; }
119 
121 
124  // make it public again, called by GUI
126  Stock* Find( const std::string & namestock) const;
127 
135  ListDataStockBase* GetListData ( const std::string& fullname ) const throw(StockException);
137 
151  // no reference for namestock, test "CAC40" need to cast from const char*
152  Stock* Load ( const std::string namestock, const ETime& tmscl, const Indicator& indic,
153  std::vector< int > param = std::vector<int>(),
155  throw(StockException);
156 
157 
164  // could use status, but necessary to check
165  int AddStock ( Stock * ); // throw (StockException);
166 
171  void DeleteStock ( const std::string namestock );
175  void DeleteListData( const std::string& fname );
182  void DeleteAllListDataFromFrame ( const std::string& frame_name );
189  void DeleteAllListDataFromTimeScale ( const std::string& namestock, const ETime& tmscl);
191  //maybe add a Update / UpdateAllTimescale wrapper later...
192 
203  void SendDatadCSV( const std::string& message ) throw(StockException);
205 
209  void PrintMap();
210 };
211 
212 #endif /* STOCK_MANAGER_H_ */
Singleton class, stores all loaded stocks.
Definition: StockManager.h:42
TCPServer * GetServer() const
Definition: StockManager.h:116
"Clever" enumeration of the ListDataStock type : StockCSV, Volume, EMA, BOLL,...
Definition: Indicator.h:29
bool GetStatus() const
Indicates if the singleton has been initialized or is still valide.
Definition: StockManager.h:101
void SetServer(TCPServer *tcp)
Definition: StockManager.h:117
StockManager()
Constructor and destructor private, called by getInstance.
Definition: StockManager.h:73
Stock * Load(const std::string namestock, const ETime &tmscl, const Indicator &indic, std::vector< int > param=std::vector< int >(), Utils::firstlast_dates dates=Utils::get_fldate_default())
Load a specific ListDataStock.
Base Exception for Stock and StockManager, all src_cpp code.
void DeleteAllListDataFromTimeScale(const std::string &namestock, const ETime &tmscl)
Delete all listdata of a stock for a timescale.
static StockManager * getInstance(std::string new_path=".")
Get a singleton instance.
ListDataStockBase * GetListData(const std::string &fullname) const
Retrieve an instance of a ListDataStock.
SMSubject * GetSubject()
Get the subject instance.
Definition: StockManager.h:196
void SetPath(std::string new_path)
set path during init, may be changed later also
Definition: StockManager.h:107
void DeleteStock(const std::string namestock)
Delete a stock and all its content.
Main class to deal with one stock.
Definition: Stock.h:56
bool ActivateServer()
Activate the server, by default null in constructor.
static TCPServer * ftcp
owns a TCPServer, but inverse is true as well.
Definition: StockManager.h:64
static bool status_sm
static boolean status
Definition: StockManager.h:54
ETime
Enumeration for the different time representation, from instantaneous (INST) to year(YEAR) ...
Definition: TimeScale.h:48
static SMSubject * fsubject
owns a subject/observable for the observer pattern
Definition: StockManager.h:66
it_stock GetItStock(const std::string &namestock)
Return iterator on the element.
StockManager & operator=(const StockManager &)
void SendDatadCSV(const std::string &message)
Extract info from the message coming from TCPServer, update the Lists and notify observers (GUIMainCo...
std::string GetPath() const
Definition: StockManager.h:105
Use with RealTime to receive messages from python ServerPortfolio.
Definition: TCPServer.h:122
Stock * Find(const std::string &namestock) const
Retrieve an instance of a stock.
Exception to be used within stock_cpp.
std::vector< Stock * >::iterator it_stock
Definition: StockManager.h:47
std::vector< Stock * >::const_iterator cit_stock
Definition: StockManager.h:48
Abstract base class for the ListDataStock, for storing base pointers in vectors.
Definition: ListDataStock.h:50
bool DesactivateServer()
static void killInstance()
Delete the instance and allocated ressources.
static SUPPRESS_NOT_USED_WARN firstlast_dates get_fldate_default()
need to be static for using default argument in a function
Definition: Utils.h:60
static StockManager * fstockmanager
static instance
Definition: StockManager.h:56
static std::string fpath
path of the data, set during singleton initialization
Definition: StockManager.h:61
void DeleteAllListDataFromFrame(const std::string &frame_name)
Delete all data of a frame_name,i.e, CAC40_DAY just easy to use from GUI, just call DeleteAllListData...
general structure for dates in csv files
Definition: Utils.h:54
int AddStock(Stock *)
Add a stock to the stockmanager.
void PrintMap()
Print an user-friendly view of the StockManger content.
void DeleteListData(const std::string &fname)
Delete a specific ListDataStcok, just wrappers to Stock.
Derive from Subject class.
Definition: SMSubject.h:24
void InsertVec_Stock(Stock *)
Insert a vector.
std::vector< Stock * > vec_stock
vector of loaded Stock
Definition: StockManager.h:70