9de5adf39c7790921944dc8be7d2dce622365437
[fms.git] / include / option.h
1 #ifndef _option_\r
2 #define _option_\r
3 \r
4 #include "db/sqlite3db.h"\r
5 \r
6 #include <sstream>\r
7 #include "threadwrapper/singleton.h"\r
8 \r
9 //just a wrapper around the database for the options table\r
10 class Option:public Singleton<Option>\r
11 {\r
12 public:\r
13         const bool Get(const std::string &option, std::string &value);\r
14         const bool GetInt(const std::string &option, int &value);\r
15         template<class T>\r
16         void Set(const std::string &option, const T &value);\r
17 private:\r
18 };\r
19 \r
20 template<class T>\r
21 void Option::Set(const std::string &option, const T &value)\r
22 {\r
23         std::ostringstream valuestr;\r
24         valuestr << value;\r
25 \r
26         std::string tempval;\r
27         if(Get(option,tempval)==true)\r
28         {\r
29                 SQLite3DB::Statement st=SQLite3DB::DB::Instance()->Prepare("UPDATE tblOption SET OptionValue=? WHERE Option=?;");\r
30                 st.Bind(0,valuestr.str());\r
31                 st.Bind(1,option);\r
32                 st.Step();\r
33         }\r
34         else\r
35         {\r
36                 SQLite3DB::Statement st=SQLite3DB::DB::Instance()->Prepare("INSERT INTO tblOption(Option,OptionValue) VALUES(?,?);");\r
37                 st.Bind(0,option);\r
38                 st.Bind(1,valuestr.str());\r
39                 st.Step();\r
40         }\r
41 }\r
42 \r
43 #endif  // _option_\r