📄 ncbireg.hpp
字号:
/// Get integer value of specified parameter name. /// /// Like "GetString()", plus convert the value into integer. /// @param err_action /// What to do if error encountered in converting parameter value. /// @sa /// GetString() int GetInt(const string& section, const string& name, int default_value, TFlags flags = 0, EErrAction err_action = eThrow) const; /// Get boolean value of specified parameter name. /// /// Like "GetString()", plus convert the value into boolean. /// @param err_action /// What to do if error encountered in converting parameter value. /// @sa /// GetString() bool GetBool(const string& section, const string& name, bool default_value, TFlags flags = 0, EErrAction err_action = eThrow) const; /// Get double value of specified parameter name. /// /// Like "GetString()", plus convert the value into double. /// @param err_action /// What to do if error encountered in converting parameter value. /// @sa /// GetString() double GetDouble(const string& section, const string& name, double default_value, TFlags flags = 0, EErrAction err_action = eThrow) const; /// Set the configuration parameter value. /// /// Unset the parameter if specified "value" is empty. /// /// @param value /// Value that the parameter is set to. /// @param flags /// To control search. /// Valid flags := { ePersistent, eNoOverride, eTruncate } /// If there was already an entry with the same <section,name> key: /// if "eNoOverride" flag is set then do not override old value /// and return FALSE; else override the old value and return TRUE. /// If "ePersistent" flag is set then store the entry as persistent; /// else store it as transient. /// If "eTruncate" flag is set then truncate the leading and trailing /// spaces -- " \r\t\v" (NOTE: '\n' is not considered a space!). /// @param comment /// Optional comment string describing parameter. /// @return /// TRUE if specified parameter is set; FALSE otherwise. bool Set(const string& section, const string& name, const string& value, TFlags flags = 0, const string& comment = kEmptyStr); /// Set comment "comment" for the registry entry "section:name". /// /// @param comment /// Comment string value. /// Set to kEmptyStr to delete the comment. /// @param section /// Section name. /// If "section" is empty string, then set as the registry comment. /// @param name /// Parameter name. /// If "name" is empty string, then set as the "section" comment. /// @return /// FALSE if "section" and/or "name" do not exist in registry. bool SetComment(const string& comment, const string& section = kEmptyStr, const string& name = kEmptyStr); /// Get comment of the registry entry "section:name". /// /// @param section /// Section name. /// If passed empty string, then get the registry comment. /// @param name /// Parameter name. /// If empty string, then get the "section" comment. /// @return /// Comment string. If not found, return an empty string. const string& GetComment(const string& section = kEmptyStr, const string& name = kEmptyStr) const; /// Enumerate section names. /// /// Write all section names to the "sections" list. /// Previous contents of the list are erased. void EnumerateSections(list<string>* sections) const; /// Enumerate parameter names for a specfiied section. /// /// Write all parameter names for specified "section" to the "entries" /// list. Previous contents of the list are erased. void EnumerateEntries(const string& section, list<string>* entries) const;private: /// Hold values for Registry entry. struct TRegEntry { string persistent; ///< Non-transient value string transient; ///< Transient value string comment; ///< Entry's comment string }; /// Define Registry section as a map of entry parameter names /// and the parameter values. typedef map<string, TRegEntry, PNocase> TRegSection; /// Define Registry as a map of section names and section /// values (TRegSection). typedef map<string, TRegSection, PNocase> TRegistry; TRegistry m_Registry; ///< Internal representation of registry. string m_Comment; ///< All-registry comment mutable bool m_Modified; ///< Persistent value(s) changed mutable bool m_Written; ///< Method Write() was called at least once /// Helper method to set registry entry value and comment string. void x_SetValue(TRegEntry& entry, const string& value, TFlags flags, const string& comment); /// Helper method to check if the registry contains only transient entries /// and comments. bool x_IsAllTransient(void) const; /// Private copy constructor to prohibit default intitialization. CNcbiRegistry(const CNcbiRegistry&); /// Private assignment operator to prohibit default assignment. CNcbiRegistry& operator= (const CNcbiRegistry&);};END_NCBI_SCOPE/* @} *//* * =========================================================================== * $Log: ncbireg.hpp,v $ * Revision 1000.0 2003/10/29 15:05:14 gouriano * PRODUCTION: IMPORTED [ORIGINAL] Dev-tree R1.32 * * Revision 1.32 2003/10/20 21:55:05 vakatov * CNcbiRegistry::GetComment() -- make it "const" * * Revision 1.31 2003/08/18 18:44:07 siyan * Minor comment changes. * * Revision 1.30 2003/08/14 12:25:28 siyan * Made previous documentation changes consistent. * Best not to mix the ///< style with @param style for parameter documentation * as Doxygen may not always render this correctly. * * Revision 1.29 2003/08/12 19:00:39 vakatov * Fixed comments and code layout * * Revision 1.27 2003/07/21 18:42:38 siyan * Documentation changes. * * Revision 1.26 2003/04/07 19:40:03 ivanov * Rollback to R1.24 * * Revision 1.25 2003/04/07 16:08:41 ivanov * Added more thread-safety to CNcbiRegistry:: methods -- mutex protection. * Get() and GetComment() returns "string", not "string&". * * Revision 1.24 2003/04/01 14:20:28 siyan * Added doxygen support * * Revision 1.23 2003/02/28 19:24:42 vakatov * Get rid of redundant "const" in the return type of GetInt/Bool/Double() * * Revision 1.22 2003/02/24 19:54:51 gouriano * use template-based exceptions instead of errno and parse exceptions * * Revision 1.21 2003/01/17 20:46:28 vakatov * Fixed/improved description of "EErrAction" * * Revision 1.20 2003/01/17 20:26:59 kuznets * CNcbiRegistry added ErrPost error action * * Revision 1.19 2003/01/17 17:31:20 vakatov * CNcbiRegistry::GetString() to return "string", not "string&" -- for safety * * Revision 1.18 2002/12/30 23:23:06 vakatov * + GetString(), GetInt(), GetBool(), GetDouble() -- with defaults, * conversions and error handling control (to extend Get()'s functionality). * * Revision 1.17 2002/12/18 22:53:21 dicuccio * Added export specifier for building DLLs in windows. Added global list of * all such specifiers in mswin_exports.hpp, included through ncbistl.hpp * * Revision 1.16 2002/04/11 20:39:18 ivanov * CVS log moved to end of the file * * Revision 1.15 2001/09/11 00:46:56 vakatov * Fixes to R1.14: * Renamed HasChanged() to Modified(), refined and extended its functionality * Made Write() be "const" again * * Revision 1.14 2001/09/10 16:35:02 ivanov * Added method HasChanged() * * Revision 1.13 2001/06/22 21:50:20 ivanov * Added (with Denis Vakatov) ability for read/write the registry file * with comments. Also added functions GetComment() and SetComment(). * * Revision 1.12 2001/05/17 14:54:01 lavr * Typos corrected * * Revision 1.11 2001/04/09 17:39:20 grichenk * CNcbiRegistry::Get() return type reverted to "const string&" * * Revision 1.10 2001/04/06 15:46:29 grichenk * Added thread-safety to CNcbiRegistry:: methods * * Revision 1.9 1999/09/02 21:53:23 vakatov * Allow '-' and '.' in the section/entry name * * Revision 1.8 1999/07/07 14:17:05 vakatov * CNcbiRegistry:: made the section and entry names be case-insensitive * * Revision 1.7 1999/07/06 15:26:31 vakatov * CNcbiRegistry:: * - allow multi-line values * - allow values starting and ending with space symbols * - introduced EFlags/TFlags for optional parameters in the class * member functions -- rather than former numerous boolean parameters * * Revision 1.6 1998/12/28 17:56:28 vakatov * New CVS and development tree structure for the NCBI C++ projects * * Revision 1.5 1998/12/10 22:59:46 vakatov * CNcbiRegistry:: API is ready(and by-and-large tested) * =========================================================================== */#endif /* CORELIB___NCBIREG__HPP */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -