All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DBStatementCatalog.h
Go to the documentation of this file.
1 /*
2  * DBStatementCatalog.h
3  *
4  * This file is part of the HausmiSEP project
5  *
6  * Copyright (C) 2012, 2013 Marco Alvarado (malvcr@gmail.com)
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef DBSTATEMENTCATALOG_H_
23 #define DBSTATEMENTCATALOG_H_
24 
25 #include <map>
26 #include <string>
27 #include <HSEP/Dictionary.h>
28 
29 using namespace std;
30 using namespace HSEP;
31 
32 namespace HSEPData {
33 
45 
46  string aInvalidString;
47  string aPath;
48  StringDictionary aCatalog;
49  bool aValid;
50 
58  DBStatementCatalog(string pPath) {
59  aInvalidString = "Invalid";
60  aPath = pPath;
61  aCatalog.clear();
62  aValid = false;
63  } // DBStatementCatalog constructor
64 
66  }
67 
68  bool load();
69 
70  public:
72 
77  static void init(string pPath) {
78  aInstance = new DBStatementCatalog(pPath);
79  aInstance->load();
80  }
81 
85  static void destroy() {
86  if (nullptr != aInstance) {
87  delete aInstance;
88  }
89  }
90 
98  static string& getStatementRef(string pStatementName) {
99  if (aInstance->aValid) {
100  return aInstance->aCatalog.ref(pStatementName);
101  }
102  else {
103  return aInstance->aInvalidString;
104  }
105  } // getStatement
106 
110  static void reload() {
111  if (aInstance->aValid) {
112  aInstance->aCatalog.clear();
113  aInstance->aValid = aInstance->load();
114  }
115  } // reload
116 
117  }; // DBStatementCatalog class
118 
119 } // HSEPData namespace
120 
121 #endif /* DBSTATEMENTCATALOG_H_ */