Definition at line 15 of file Environ.h.
Public Member Functions | |
virtual | ~Environ () |
Free all remain messages for watchers. | |
void | store (const Path &file) |
Save params. | |
void | setParam (const std::string &name, const std::string &value) |
Set param. | |
void | setParam (const std::string &name, long value) |
Store this integer value like string param. | |
std::string | getParam (const std::string &name, const std::string &implicit="") const |
Return value. | |
int | getAsInt (const std::string &name, int implicit=0) const |
Returns number value. | |
bool | getAsBool (const std::string &name, bool implicit=false) const |
Returns boolean value. | |
void | addWatcher (const std::string &name, BaseMsg *msg) |
Multiple watcher can watch param change. | |
void | removeWatchers (const std::string &listenerName) |
Removes all registered watchers for given listener. | |
std::string | toString () const |
std::string | getHelpInfo () const |
|
Free all remain messages for watchers.
Definition at line 23 of file Environ.cpp. 00024 { 00025 t_watchers::iterator end = m_watchers.end(); 00026 for (t_watchers::iterator i = m_watchers.begin(); i != end; ++i) { 00027 delete i->second; 00028 } 00029 }
|
|
Multiple watcher can watch param change.
Definition at line 192 of file Environ.cpp. 00193 { 00194 m_watchers.insert(std::pair<std::string,BaseMsg*>(name, msg)); 00195 LOG_DEBUG(ExInfo("add watcher") 00196 .addInfo("param", name) 00197 .addInfo("msg", msg->toString())); 00198 }
|
|
Returns boolean value. Recognizes 1/0, true/false, on/off, yes/no.
Definition at line 159 of file Environ.cpp. 00161 { 00162 bool result = false; 00163 std::string value = getParam(name); 00164 if (value == "1" || value == "true" || value == "on" || value == "yes") { 00165 result = true; 00166 } 00167 else if (value == "0" || value == "false" || value == "off" || 00168 value == "no") 00169 { 00170 result = false; 00171 } 00172 else { 00173 if (value != "") { 00174 //TODO: don't print this every time 00175 LOG_WARNING(ExInfo("cannot recognize boolean value") 00176 .addInfo("property", name) 00177 .addInfo("value", value) 00178 .addInfo("default", implicit) 00179 .addInfo("hint", "use 1/0, true/false, on/off, yes/no")); 00180 } 00181 result = implicit; 00182 } 00183 return result; 00184 }
|
|
Returns number value. Implicit value is zero.
Definition at line 132 of file Environ.cpp. 00134 { 00135 std::string value = getParam(name); 00136 bool ok; 00137 int result = StringTool::readInt(value.c_str(), &ok); 00138 if (!ok) { 00139 if (value != "") { 00140 LOG_WARNING(ExInfo("cannot recognize numeric value") 00141 .addInfo("property", name) 00142 .addInfo("value", value) 00143 .addInfo("default", implicit)); 00144 } 00145 result = implicit; 00146 } 00147 return result; 00148 }
|
|
Definition at line 228 of file Environ.cpp. 00229 { 00230 std::string help; 00231 t_values::const_iterator end = m_values.end(); 00232 for (t_values::const_iterator i = m_values.begin(); i != end; ++i) { 00233 help += i->first + "='" + i->second + "'\n"; 00234 } 00235 return help; 00236 }
|
|
Return value. Implicit value is "".
Definition at line 111 of file Environ.cpp. 00113 { 00114 std::string result = implicit; 00115 00116 t_values::const_iterator it = m_values.find(name); 00117 if (m_values.end() != it) { 00118 result = it->second; 00119 } 00120 return result; 00121 }
|
|
Removes all registered watchers for given listener.
Definition at line 204 of file Environ.cpp. 00205 { 00206 t_watchers::iterator end = m_watchers.end(); 00207 for (t_watchers::iterator i = m_watchers.begin(); i != end; /*empty*/) { 00208 t_watchers::iterator cur = i++; 00209 if (cur->second->getListenerName() == listenerName) { 00210 delete cur->second; 00211 m_watchers.erase(cur); 00212 } 00213 } 00214 }
|
|
Store this integer value like string param.
Definition at line 97 of file Environ.cpp. 00098 { 00099 setParam(name, StringTool::toString(value)); 00100 }
|
|
Set param. Notice watchers. When watcher is not available, it will be removed.
Definition at line 65 of file Environ.cpp. 00066 { 00067 if (m_values[name] != value) { 00068 m_values[name] = value; 00069 LOG_DEBUG(ExInfo("setParam") 00070 .addInfo("param", name) 00071 .addInfo("value", value)); 00072 00073 t_watchers::iterator it = m_watchers.find(name); 00074 if (m_watchers.end() != it) { 00075 t_watchers::size_type count = m_watchers.count(name); 00076 for (t_watchers::size_type i = 0; i < count; ++i) { 00077 t_watchers::iterator cur_it = it++; 00078 try { 00079 cur_it->second->sendClone(); 00080 } 00081 catch (NameException &e) { 00082 LOG_WARNING(e.info()); 00083 delete cur_it->second; 00084 m_watchers.erase(cur_it); 00085 } 00086 } 00087 } 00088 } 00089 }
|
|
Save params.
Definition at line 36 of file Environ.cpp. 00037 { 00038 FILE *config = fopen(file.getNative().c_str(), "w"); 00039 if (config) { 00040 fputs("-- this file is automatically generated\n", config); 00041 00042 t_values::iterator end = m_values.end(); 00043 for (t_values::iterator i = m_values.begin(); i != end; ++i) { 00044 fprintf(config, "setParam(\"%s\", \"%s\")\n", 00045 i->first.c_str(), i->second.c_str()); 00046 } 00047 00048 fclose(config); 00049 } 00050 else { 00051 LOG_WARNING(ExInfo("cannot save config") 00052 .addInfo("file", file.getNative())); 00053 } 00054 }
|
|
Definition at line 217 of file Environ.cpp. 00218 { 00219 ExInfo info("environ"); 00220 t_values::const_iterator end = m_values.end(); 00221 for (t_values::const_iterator i = m_values.begin(); i != end; ++i) { 00222 info.addInfo(i->first, i->second); 00223 } 00224 return info.info(); 00225 }
|