00001 // OSB library ********************************************* -*- C++ -*- 00006 /* 00007 AUTHOR(S): Lilian Qin Lan (lan) 00008 00009 RCS information 00010 $Name: OSB_060808 $ 00011 $Revision: 1.21 $ 00012 00013 License 00014 OSB rating and billing library for communication networks 00015 Copyright (C) 2004, 2005, 2006 OSB systems 00016 00017 This file may be distributed and/or modify under the terms of the 00018 GNU General Public License (GPL) as published by the Free Software 00019 Foundation which is provided in the file LICENSE.GPL included in the 00020 packaging of this file. 00021 00022 The file is distributed in the hope that it will be useful, but WITHOUT 00023 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00024 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00025 for more details. 00026 00027 Holders of a OSB Commercial License may use this file under the terms 00028 and conditions of this commercial license. 00029 */ 00030 #ifndef _SETTING_H_ 00031 #define _SETTING_H_ 00032 00033 // ********************************************************************* 00034 // included header files 00035 // + standard includes 00036 #include <string> 00037 #include <fstream> 00038 #include <vector> 00039 00040 // + local headers 00041 #include "osbid.h" 00042 00043 // ********************************************************************* 00044 // namespace extensions 00045 namespace OSB_LIB { 00046 00047 // ********************************************************************* 00048 // global function declarations 00050 typedef std::vector<std::string> Directories; 00051 00052 // ************************************************************************ 00053 // class definitions 00064 class Setting { 00065 public: 00066 enum RetValue { 00067 rvSuccess = 0, 00068 rvDirReadOnly = 1, 00069 rvFileReadOnly = 2 00070 }; 00072 explicit Setting( 00073 const std::string& module 00074 ) : moduleName_(module) {} 00075 00077 00078 00079 const std::string& moduleName() const { return moduleName_; } 00080 00082 const std::string& userName() const { return userName_; } 00083 00085 const std::string& password() const { return password_; } 00086 00088 const std::string& database() const { return database_; } 00089 00092 const std::string& path() const; 00094 00096 00097 00098 void setModuleName(const std::string& mn) { moduleName_ = mn; } 00100 void setUserName(const std::string& un) { userName_ = un; } 00102 void setPassword(const std::string& pw) { password_ = pw; } 00104 void setDatabase(const std::string& db) { database_ = db; } 00106 00107 00119 RetValue getWritePath(const std::string & path); 00120 00130 void writeSetting(); 00131 00141 void delSetting(); 00142 00157 void readSetting(); 00158 00165 void showDir(std::ostream& os) const; 00166 00173 void setDir(Directories& dirs); 00174 00175 private: 00176 std::string moduleName_; 00177 std::string userName_; 00178 std::string password_; 00179 std::string database_; 00180 00181 00182 std::string path_; 00185 static const std::string fileName_; 00186 00194 int checkModule(std::fstream& f); // 0 for not found 00195 00202 void replaceLine(std::fstream& f, int line); 00203 00210 void removeLine(std::fstream& f, int line); 00211 00218 void append(std::fstream& f) const; 00219 }; 00220 } 00221 00222 #endif // #ifndef _SETTING_H_