abe1a586a87174cf4cd8f2d609f334b0304ea5a0
[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 <zthread/Singleton.h>\r
8 \r
9 //just a wrapper around the database for the options table\r
10 class Option:public ZThread::Singleton<Option>\r
11 {\r
12 public:\r
13         const bool Get(const std::string &option, std::string &value);\r
14         template<class T>\r
15         void Set(const std::string &option, const T &value);\r
16 private:\r
17 };\r
18 \r
19 template<class T>\r
20 void Option::Set(const std::string &option, const T &value)\r
21 {\r
22         std::ostringstream valuestr;\r
23         valuestr << value;\r
24 \r
25         std::string tempval;\r
26         if(Get(option,tempval)==true)\r
27         {\r
28                 SQLite3DB::Statement st=SQLite3DB::DB::instance()->Prepare("UPDATE tblOption SET OptionValue=? WHERE Option=?;");\r
29                 st.Bind(0,valuestr.str());\r
30                 st.Bind(1,option);\r
31                 st.Step();\r
32         }\r
33         else\r
34         {\r
35                 SQLite3DB::Statement st=SQLite3DB::DB::instance()->Prepare("INSERT INTO tblOption(Option,OptionValue) VALUES(?,?);");\r
36                 st.Bind(0,option);\r
37                 st.Bind(1,valuestr.str());\r
38                 st.Step();\r
39         }\r
40 }\r
41 \r
42 #endif  // _option_\r