1 /**
2 *  Copyright Mikael H�gdahl - triyana@users.sourceforge.net
3 *
4 *  This source is distributed under the terms of the Q Public License version 1.0,
5 *  created by Trolltech (www.trolltech.com).
6 */
7 
8 #ifndef DBFactory_h
9 #define DBFactory_h
10 
11 #include <MHString.h>
12 #include <MHVector.h>
13 #include <Resource.h>
14 
15 class Account;
16 class Security;
17 class Set;
18 class SetItem;
19 class MHString;
20 class MHVector;
21 
22 
23 
24 /**
25 *  DBFactory creates data vectors
26 */
27 class DBFactory {
28 public:
29     static void             Clear ();
ClearAccount()30     static void             ClearAccount() {aaAccount->Erase();}
ClearGuard()31     static void             ClearGuard() {aaGuard->Erase();}
ClearPref()32     static void             ClearPref() {aaPref->Erase();}
33     static void             ClearPrice ();
ClearSecurity()34     static void             ClearSecurity() {aaSecurity->Erase();}
ClearSet()35     static void             ClearSet() {aaSet->Erase();}
36 
Database()37     static const char*      Database () {return aaPath->Get();}
38     static void             Export (const char* fileName, bool account, bool transactions, bool set, bool security, bool price, bool guard, bool Pref);
39     static int              GetPrefIntValue (const char* key, int min, int max, int def);
40     static int              GetPrefIntValue (const char* key, int view, int min, int max, int def);
41     static const char*      GetPrefStringValue (const char* key, const char* def = "");
42     static int              GetUniqueID();
GetWorkSpaceName()43     static const char*      GetWorkSpaceName () {if (DBFactory::aaWorkSpace == 0) DBFactory::SetWorkSpace (STRING(DEFAULT_WORKSPACE)); return aaWorkSpace->Get();}
44     static MHVector*        LoadAccount();
LoadClosedPrice(Security * security)45     static MHVector*        LoadClosedPrice (Security* security) {return loadPrice(security, true);}
46     static MHVector*        LoadGuard();
47     static MHVector*        LoadPref();
48     static void             LoadPortfolio (Account* account, MHVector* out);
LoadPrice(Security * security)49     static MHVector*        LoadPrice (Security* security) {return loadPrice(security, false);}
50     static void             LoadRawPrice (Security* set, MHVector* out);
51     static MHVector*        LoadSecurity();
52     static MHVector*        LoadSet();
53     static void             LoadSetItem (Set* set, MHVector* out);
SetCacheSize(int t)54     static void             SetCacheSize (int t) {ClearPrice(); aaCacheSize = t;}
SetCacheTimeout(int t)55     static void             SetCacheTimeout (int t) {ClearPrice(); aaCacheTimeout = t;}
56     static void             SetPrefIntValue (const char* key, int min, int max, int def, int val);
57     static void             SetPrefIntValue (const char* key, int view, int min, int max, int def, int val);
58     static void             SetPrefStringValue (const char* key, const char* val);
59     static void             SetWorkSpace (const char* file);
Slash()60     static const char*      Slash () {return "/";}
61     static void             Start (const char* database);
62     static void             Stop ();
63     static void             WriteLog (const char *Message, ...);
64 
65 private:
66     enum {
67                             CACHE_SIZE    = 100,
68                             CACHE_TIMEOUT = 300,
69     };
70 
71     static char             aaPathSep;
72     static int              aaCacheSize;
73     static int              aaCacheTimeout;
74     static int              aaPriceAccess[CACHE_SIZE];
75     static MHString*        aaLogName;
76     static MHString*        aaPath;
77     static MHString*        aaWorkSpace;
78     static MHVector*        aaAccount;
79     static MHVector*        aaClosed[CACHE_SIZE];
80     static MHVector*        aaGuard;
81     static MHVector*        aaPref;
82     static MHVector*        aaPrice[CACHE_SIZE];
83     static MHVector*        aaSecurity;
84     static MHVector*        aaSet;
85     static Security*        aaPriceName[CACHE_SIZE];
86 
87     static MHVector*        loadPrice (Security* security, bool closed);
88 };
89 
90 #endif
91