📄 keyvalue.hpp
字号:
/* * =========================================================================== * PRODUCTION $Log: KeyValue.hpp,v $ * PRODUCTION Revision 1000.2 2004/06/01 19:46:10 gouriano * PRODUCTION PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.5 * PRODUCTION * =========================================================================== *//* $Id: KeyValue.hpp,v 1000.2 2004/06/01 19:46:10 gouriano Exp $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's official duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * =========================================================================== * * Author: Robert G. Smith * * File Description: * CKeyValue represents a key/value pair, where the key is a string * and the value can be a string or a recursive list of key/value pairs. * Values can be retrieved and stored with compound keys (e.g. "view.grapic.color.gene") * to get at deeper levels. * * Remark: * This code was originally generated by application DATATOOL * using specifications from the data definition file * 'plugin.asn'. */#ifndef GUI_PLUGIN_KEYVALUE_HPP#define GUI_PLUGIN_KEYVALUE_HPP// generated includes#include <gui/gui.hpp>#include <gui/config/KeyValue_.hpp>#include <algorithm>// generated classesBEGIN_NCBI_SCOPEBEGIN_objects_SCOPE // namespace ncbi::objects::class NCBI_GUICONFIG_EXPORT CKeyValue : public CKeyValue_Base{ typedef CKeyValue_Base Tparent;public: // constructor CKeyValue(void); explicit CKeyValue(const string& key); CKeyValue(const string& key, const string& value); // destructor ~CKeyValue(void); // comparator. bool KeyMatches(const string& label) const; // Merge an other key value object into this one. // the other one's values take precedence. CKeyValue& Merge(const CKeyValue& other); /* Find particular values by key. An exception is throw if key not found or if a string is required and the value at that point is a list of key-value pairs. No copying of data is done. All of these assume that this val contains keyvals, not str, and throw if that is not true. */ // Search one level. const CKeyValue& GetKeyvalueByKey1(const string & key) const; // search multiple levels with keys like: "label1.label2.label3" const CKeyValue& GetKeyvalueByKey(const string& key, const string& delim = "|") const; const string& GetStringByKey(const string& key, const string& delim = "|") const; // implementation: Search a list of key/value pairs for a key. // return an iterator. static TVal::TKeyvals::const_iterator s_FindKeyvalueByKey(const string& key, const TVal::TKeyvals& keyvals); static TVal::TKeyvals::iterator s_FindKeyvalueByKey(const string& key, TVal::TKeyvals& keyvals); /// Return a list of all the keys in this KeyValue. /// use delim to separate parts of a hierachical key /// and append the keys to key_prefix & delim. typedef list< string > TKeyList; void GetAllKeys(TKeyList& key_list, const string& key_prefix, const string& delim ) const; // Set methods // implementation: Search a list for a key, add the key if not found. // Return the found/added key-value. // prevents duplicate keys in lists static CKeyValue& s_AddKey(const string & key, TVal::TKeyvals& keyvals); // search and add multiple levels with keys like: "k1.k2.k3" CKeyValue& AddKey(const string& key, const string& delim = "|"); CKeyValue& AddKeyString(const string& key, const string& value, const string& delim = "|"); // delete the keyval within this CKeyValue that has a particular key. // return true if key exists, false otherwise. bool DelKeyval(const string& key, const string& delim = "|"); private: // Prohibit copy constructor and assignment operator CKeyValue(const CKeyValue& value); CKeyValue& operator=(const CKeyValue& value);};//// simple functor to check if a key-value pair matches a given keystruct SKeyMatches{ SKeyMatches(const string& key) : m_Key(key) {} bool operator() (const CRef<CKeyValue>& kv) const { return kv->KeyMatches(m_Key); }private: const string& m_Key;};/////////////////// CKeyValue inline methods// constructorinlineCKeyValue::CKeyValue(void){}inlinebool CKeyValue::KeyMatches(const string& label) const{ if (CanGetKey()) { return (GetKey() == label); } return false;}// accessor methods.inlineCKeyValue::TVal::TKeyvals::const_iterator CKeyValue::s_FindKeyvalueByKey(const string& key, const CKeyValue::TVal::TKeyvals& keyvals){ _ASSERT (!key.empty()); return find_if(keyvals.begin(), keyvals.end(),SKeyMatches(key));}inlineCKeyValue::TVal::TKeyvals::iterator CKeyValue::s_FindKeyvalueByKey(const string & key, CKeyValue::TVal::TKeyvals& keyvals){ _ASSERT (!key.empty()); return find_if(keyvals.begin(), keyvals.end(),SKeyMatches(key));}inlineconst string& CKeyValue::GetStringByKey(const string & key, const string& delim) const{ return GetKeyvalueByKey(key, delim).GetVal().GetStr();}// mutator (Set) methodsinline CKeyValue& CKeyValue::AddKeyString(const string& key, const string& val, const string& delim){ CKeyValue& kv = AddKey(key, delim); kv.SetVal().SetStr(val); return kv;}/////////////////// end of CKeyValue inline methodsEND_objects_SCOPE // namespace ncbi::objects::END_NCBI_SCOPE/** ===========================================================================** $Log: KeyValue.hpp,v $* Revision 1000.2 2004/06/01 19:46:10 gouriano* PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.5** Revision 1.5 2004/05/03 12:39:54 dicuccio* Added #include for gui/gui.hpp** Revision 1.4 2004/04/20 14:06:19 rsmith* add GetAllKeys method.** Revision 1.3 2003/11/21 12:48:32 rsmith* Add ability to delete entries by key.** Revision 1.2 2003/10/10 19:35:31 dicuccio* Added export specifiers** Revision 1.1 2003/10/10 17:41:23 rsmith* moved from gui/plugin to gui/config** Revision 1.7 2003/08/19 18:09:04 rsmith* add delim argument to AddKey and AddKeyString.** Revision 1.6 2003/08/13 20:37:06 rsmith* get rid of include of find_if.hpp** Revision 1.5 2003/08/13 20:18:10 rsmith* Get rid of FindIf, go back to find_if with suitable functor.** Revision 1.4 2003/08/06 13:10:06 dicuccio* Replaced std::find_if() with FindIf() - work-around for MSVC's broken STL* implementation (no const_mem_fun1_t<>)** Revision 1.3 2003/08/06 12:24:49 ucko* +<algorithm> for find_if** Revision 1.2 2003/08/05 19:01:34 rsmith* change members used in mem_fun to satisfy certain compilers.** Revision 1.1 2003/08/05 17:37:38 rsmith* Classes to allow saving of plugins configuration values as ASN.1.*** ===========================================================================*/#endif // GUI_PLUGIN_KEYVALUE_HPP/* Original file checksum: lines: 93, chars: 2362, CRC32: 223d218c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -