⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 settings_set.hpp

📁 ncbi源码
💻 HPP
字号:
/* * =========================================================================== * PRODUCTION $Log: settings_set.hpp,v $ * PRODUCTION Revision 1000.2  2004/04/12 18:11:56  gouriano * PRODUCTION PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.9 * PRODUCTION * =========================================================================== */#ifndef GUI_CONFIG____SETTINGSSET_HPP#define GUI_CONFIG____SETTINGSSET_HPP/* $Id: settings_set.hpp,v 1000.2 2004/04/12 18:11:56 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: *   CSettingsSet is an adapter of the PluginConfigCache.  It is meant to be *   used as a base class for individual plugins' configuration classes. *   It constrains our access to the ConfigCache to a particular type. *   *   Preference/Settings classes that inherit from this need to provide: *    1) a map of default key/value pairs,  *    2) a type name *    3) methods LoadCurrentSettings and SaveCurrentSettings *      which convert between the derived class's data and key/value *      pairs.  They would call this classes Set/Get methods. *   *   It seems that modifications of the global ConfigCache would only happen *   from a user interface event. Hence we shouldn't have to worry about  *   locking.  But if this is not true, perhaps there should be a mutex *   in this class to keep multiple threads from colliding data.  * */#include <gui/config/PluginConfigCache.hpp>#include <corelib/ncbiobj.hpp>#include <corelib/ncbistr.hpp>#include <string>#include <map>BEGIN_NCBI_SCOPE/// IFactoryDefaultSettings/// abstract base class for all Factory Default Settings classes that provide/// key/value string pair defaults for descedants of CSettingsSet.class NCBI_GUICONFIG_EXPORT IFactoryDefaultSettings{public:    virtual ~IFactoryDefaultSettings() {}    virtual string   Get(const string& key) const = 0;};/// Exceptions thrown by CSettings Set and Factory default classes should derive from this.class CConfigException : public CException{public:    /// Error types that subsystem can generate.    enum EErrCode {        eNoDefaultValue,         ///< the Factory Default class does not recognize this key.        eConfigPanel,            ///< a problem with a configuration panel.        eThemeUnknownSet        ///< a ThemeSet was asked for a CSettingSet it doesn own.    };    /// Translate from the error code value to its string representation.       virtual const char* GetErrCodeString(void) const    {        switch (GetErrCode()) {        case eNoDefaultValue: return "No default value.";        case eConfigPanel:  return "configuration panel error.";        case eThemeUnknownSet: return "theme does not handle this type.";        default:     return CException::GetErrCodeString();        }    }        // Standard exception boilerplate code.        NCBI_EXCEPTION_DEFAULT(CConfigException, CException);}; /// CFactoryDefaultSettings: simple class to provide/// a fixed set of default settings.class NCBI_GUICONFIG_EXPORT CFactoryDefaultSettings    : public IFactoryDefaultSettings{public:    typedef map<string, string> TFDInput;    CFactoryDefaultSettings() {}    CFactoryDefaultSettings(const TFDInput& kvs) : m_vals(kvs)    { }    virtual ~CFactoryDefaultSettings() {}        string   Get(const string& key) const;private:    TFDInput m_vals;};/// this is a pure virtual classclass NCBI_GUICONFIG_EXPORT CSettingsSet : public CObject{public:    // constructor    CSettingsSet(objects::CPluginConfigCache* config_cache,                  const string& type,                 const AutoPtr<IFactoryDefaultSettings>& fds,                  const string& typedesc = "",                 const string& delim = "|");    virtual ~CSettingsSet();    enum ELoadValueSource {        eLoad_Current,      ///< Get values from the current PCV (current style),                             ///< if not there look in Factory Defaults.        eLoad_FactDefs      ///< Only get values from the Factory Defaults.    };        /// convert between current settings and the PluginConfigCache.    virtual bool    LoadCurrentSettings(ELoadValueSource src) = 0;    virtual bool    SaveCurrentSettings(void) = 0;        const string&   GetType(void) const;    const string&   GetCurrentStyleName(void) const;    void            SetCurrentStyleName(const string& new_style);    bool            CurrentSettingsModified(void) const;    void            CurrentSettingsModified(bool modified);            const string&   GetTypeDescription(void) const;    void            SetTypeDescription(const string&);        /**         Methods to edit our list of valid styles.         These do not change the current style, except DeleteStyle().             */        /// use to set up menu to chose between saved sets/styles.    list<string>    GetStyleNames(void) const;    /// these all return the name of the style just added.    /// on failure they will return empty strings.    string          AddStyle(void);    string          DuplicateStyle(const string& style);    string          RenameStyle(const string& old_style, const string& new_style);    bool            CanRenameStyle(const string& style);    // returns true on success, false on failure.    bool            DeleteStyle(const string& style);    objects::CPluginConfigCache&    SetConfigCache(void);    protected:    /// what is the delimiter character between parts of a multi-part key?    const string&   GetKeyDelimiter() const;        /// Access values in the current settings PCV and Factory defaults.    string          Get(const string& key, ELoadValueSource src) const;    /// Set values in the current settings PCV.    void            Set(const string& key, const string& value);    /// Set values in the current settings, include-type PCV.    void            Set(const string& typekey, const string& key, const string& value);    /// Delete a key/value in the current settings.    /// returns true if the key was found and deleted, false if not.    bool            Delete(const string& key);        unsigned int    GetArraySize(const string& array_key, ELoadValueSource src) const;    string          GetArrayItem(const string& array_key, unsigned int i, const string& item_key, ELoadValueSource src) const;    void            SetArraySize(const string& array_key, unsigned int i);    void            SetArrayItem(const string& array_key, unsigned int i, const string& item_key, const string& value);    string          ArrayHeaderKey(const string& array_key) const;    string          ArrayItemKey(const string& array_key, unsigned int i, const string& item_key) const;        objects::CPluginConfigValues&   SetCurrentSavedSet(void);    static const string     sm_StartupStyleName;        private:        AutoPtr<IFactoryDefaultSettings>         m_FactoryDefault;    CRef<objects::CPluginConfigCache>        m_ConfigCache; // CAN be null    const string    m_Type;             ///> key used in PCC.    string          m_TypeDescription;  ///> used for display and menus.    const string    m_KeyDelim;    bool            m_CurrentSetModified;    string          m_CurrentStyleName;    CRef<objects::CPluginConfigValues>  m_CurrentSavedSet; // CAN be null};END_NCBI_SCOPE/** ===========================================================================** $Log: settings_set.hpp,v $* Revision 1000.2  2004/04/12 18:11:56  gouriano* PRODUCTION: UPGRADED [CATCHUP_003] Dev-tree R1.9** Revision 1.9  2004/02/04 16:48:59  rsmith* add theme_set exception type.** Revision 1.8  2004/02/02 18:43:26  rsmith* add description to CSettingsSet, constructor and descendants.** Revision 1.7  2003/12/29 14:32:15  rsmith* Get always returns string not string&. Get always throws exceptions.* Add Config exception class.* Add Array methods.** Revision 1.6  2003/11/21 12:48:32  rsmith* Add ability to delete entries by key.** Revision 1.5  2003/10/28 19:02:55  dicuccio* Added export specifiers.  Changed ctor param from CRef<> to raw pointer** Revision 1.4  2003/10/24 16:09:25  rsmith* add doxygen comments and GetKeyDelimiter** Revision 1.3  2003/10/17 19:42:55  rsmith* make an abstract interface for factory defaults, and hence store them as a pointer in CSettingsSet.** Revision 1.2  2003/10/10 19:35:31  dicuccio* Added export specifiers** Revision 1.1  2003/10/10 17:41:43  rsmith* moved from gui/core to gui/config** Revision 1.1  2003/09/26 18:13:16  rsmith* plugin configuration data and dialogs.*** ===========================================================================*/#endif // GUI_CONFIG____SETTINGSSET_HPP

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -