00001
00002
00003
00004 #ifndef WBINIFILE_H
00005 #define WBINIFILE_H
00006
00007 #include <windows.h>
00008 #include <string>
00009 #include <boost/lexical_cast.hpp>
00010
00011
00012
00013 class WBIniFile
00014 {
00015 public:
00016
00017 static void setFileName(const std::string& fn);
00018
00019 static std::string getString(const std::string& section, const std::string& key);
00020
00021
00022 static std::string getString(const std::string& section, const std::string& key, const std::string& defValue);
00023
00024 static void setString(const std::string& section, const std::string& key, const std::string& value);
00025
00026
00027
00028 template <class T>
00029 static T getValue(const std::string& section, const std::string& key){
00030
00031 std::istringstream ss(getString(section, key));
00032 T value;
00033 if (ss >> value){
00034 return value;
00035 }else{
00036 onError("INIファイルの値が変です。\n"+fileName+"\nセクション:"+section+" キー:"+key);
00037 return T();
00038 }
00039 }
00040
00041
00042
00043 template <class T>
00044 static T getValue(const std::string& section, const std::string& key, const T& defValue){
00045
00046 std::string str= getString(section, key);
00047 if (str=="") return defValue;
00048 std::istringstream ss(str);
00049 T value;
00050 if (ss >> value){
00051 return value;
00052 }else{
00053 onError("INIファイルの値が変です。\n"+fileName+"\nセクション:"+section+" キー:"+key);
00054 return T();
00055 }
00056 }
00057
00058
00059 template <class T>
00060 static void setValue(const std::string& section, const std::string& key, const T& value){
00061 std::ostringstream ss;
00062 ss << value;
00063 setString(section, key, ss.str());
00064 }
00065
00066 private:
00067 static std::string fileName;
00068
00069
00070 static void onError(const std::string& message);
00071
00072 };
00073
00074 #endif
00075