VirtualBox

儲存庫 vbox 的更動 66610


忽略:
時間撮記:
2017-4-19 下午01:58:10 (8 年 以前)
作者:
vboxsync
訊息:

FE/Qt: Settings Cache templates cleanup/rework.

位置:
trunk/src/VBox/Frontends/VirtualBox/src/settings
檔案:
修改 2 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDefs.cpp

    r62493 r66610  
    55
    66/*
    7  * Copyright (C) 2011-2016 Oracle Corporation
     7 * Copyright (C) 2011-2017 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDefs.h

    r65690 r66610  
    55
    66/*
    7  * Copyright (C) 2011-2016 Oracle Corporation
     7 * Copyright (C) 2011-2017 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020
    2121/* Qt includes: */
     22#include <QMap>
     23#include <QPair>
    2224#include <QString>
    23 #include <QPair>
    24 #include <QMap>
    2525
    2626/* COM includes: */
    2727#include "COMEnums.h"
     28
    2829
    2930/** Settings configuration namespace. */
     
    4950}
    5051
    51 /* Template to operate settings cache item: */
     52
     53/** Template organizing settings object cache: */
    5254template <class CacheData> class UISettingsCache
    5355{
    5456public:
    5557
    56     /* Creates empty cache item: */
     58    /** Constructs empty object cache. */
    5759    UISettingsCache() { m_value = qMakePair(CacheData(), CacheData()); }
    5860
     61    /** Destructs cache object. */
    5962    virtual ~UISettingsCache() { /* Makes MSC happy */ }
    6063
    61     /* Returns the NON-modifiable REFERENCE to the initial cached data: */
    62     const CacheData& base() const { return m_value.first; }
    63     /* Returns the NON-modifiable REFERENCE to the current cached data: */
    64     const CacheData& data() const { return m_value.second; }
    65     /* Returns the modifiable REFERENCE to the current cached data: */
     64    /** Returns the NON-modifiable REFERENCE to the initial cached data. */
     65    const CacheData &base() const { return m_value.first; }
     66    /** Returns the NON-modifiable REFERENCE to the current cached data. */
     67    const CacheData &data() const { return m_value.second; }
     68    /** Returns the modifiable REFERENCE to the current cached data. */
    6669    CacheData &data() { return m_value.second; }
    6770
    68     /* We assume that old cache item was removed if
    69      * initial data was set but current data was NOT set.
    70      * Returns 'true' if that cache item was removed: */
     71    /** Returns whether the cached object was removed.
     72      * We assume that cached object was removed if
     73      * initial data was set but current data was NOT set. */
    7174    virtual bool wasRemoved() const { return base() != CacheData() && data() == CacheData(); }
    7275
    73     /* We assume that new cache item was created if
    74      * initial data was NOT set but current data was set.
    75      * Returns 'true' if that cache item was created: */
     76    /** Returns whether the cached object was created.
     77      * We assume that cached object was created if
     78      * initial data was NOT set but current data was set. */
    7679    virtual bool wasCreated() const { return base() == CacheData() && data() != CacheData(); }
    7780
    78     /* We assume that old cache item was updated if
    79      * current and initial data were both set and not equal to each other.
    80      * Returns 'true' if that cache item was updated: */
     81    /** Returns whether the cached object was updated.
     82      * We assume that cached object was updated if
     83      * current and initial data were both set and not equal to each other. */
    8184    virtual bool wasUpdated() const { return base() != CacheData() && data() != CacheData() && data() != base(); }
    8285
    83     /* We assume that old cache item was actually changed if
    84      * 1. this item was removed or
    85      * 2. this item was created or
    86      * 3. this item was updated.
    87      * Returns 'true' if that cache item was actually changed: */
     86    /** Returns whether the cached object was changed.
     87      * We assume that cached object was changed if
     88      * it was 1. removed, 2. created or 3. updated. */
    8889    virtual bool wasChanged() const { return wasRemoved() || wasCreated() || wasUpdated(); }
    8990
    90     /* Set initial cache item data: */
     91    /** Defines initial cached object data. */
    9192    void cacheInitialData(const CacheData &initialData) { m_value.first = initialData; }
    92     /* Set current cache item data: */
     93    /** Defines current cached object data: */
    9394    void cacheCurrentData(const CacheData &currentData) { m_value.second = currentData; }
    9495
    95     /* Reset the initial and the current data to be both empty: */
     96    /** Resets the initial and the current object data to be both empty. */
    9697    void clear() { m_value.first = CacheData(); m_value.second = CacheData(); }
    9798
    9899private:
    99100
    100     /* Data: */
     101    /** Holds the cached object data. */
    101102    QPair<CacheData, CacheData> m_value;
    102103};
    103104
    104 /* Template to operate settings cache item with children: */
     105
     106/** Template organizing settings object cache with children. */
    105107template <class ParentCacheData, class ChildCacheData> class UISettingsCachePool : public UISettingsCache<ParentCacheData>
    106108{
    107109public:
    108110
    109     /* Typedefs: */
     111    /** Children map. */
    110112    typedef QMap<QString, ChildCacheData> UISettingsCacheChildMap;
     113    /** Children map iterator. */
    111114    typedef QMapIterator<QString, ChildCacheData> UISettingsCacheChildIterator;
    112115
    113     /* Creates empty cache item: */
     116    /** Constructs empty object cache. */
    114117    UISettingsCachePool() : UISettingsCache<ParentCacheData>() {}
    115118
    116     /* Returns the modifiable REFERENCE to the particular child cached data.
    117      * If child with such key or index is NOT present,
    118      * both those methods will create the new one to return: */
     119    /** Returns children count. */
     120    int childCount() const { return m_children.size(); }
     121    /** Returns the modifiable REFERENCE to the child cached data. */
    119122    ChildCacheData& child(const QString &strChildKey) { return m_children[strChildKey]; }
     123    /** Wraps method above to return the modifiable REFERENCE to the child cached data. */
    120124    ChildCacheData& child(int iIndex) { return child(indexToKey(iIndex)); }
    121 
    122     /* Returns the NON-modifiable COPY to the particular child cached data.
    123      * If child with such key or index is NOT present,
    124      * both those methods will create the new one to return: */
     125    /** Returns the NON-modifiable COPY to the child cached data. */
    125126    const ChildCacheData child(const QString &strChildKey) const { return m_children[strChildKey]; }
     127    /** Wraps method above to return the NON-modifiable COPY to the child cached data. */
    126128    const ChildCacheData child(int iIndex) const { return child(indexToKey(iIndex)); }
    127129
    128     /* Children count: */
    129     int childCount() const { return m_children.size(); }
    130 
    131     /* We assume that old cache item was updated if
    132      * current and initial data were both set and not equal to each other.
    133      * Takes into account all the children.
    134      * Returns 'true' if that cache item was updated: */
     130    /** Returns whether the cache was updated.
     131      * We assume that cache object was updated if current and
     132      * initial data were both set and not equal to each other.
     133      * Takes into account all the children. */
    135134    bool wasUpdated() const
    136135    {
    137         /* First of all, cache item is considered to be updated if parent data was updated: */
     136        /* First of all, cache object is considered to be updated if parent data was updated: */
    138137        bool fWasUpdated = UISettingsCache<ParentCacheData>::wasUpdated();
    139         /* If parent data was NOT updated but also was NOT created or removed too (e.j. was NOT changed at all),
    140          * we have to check children too: */
     138        /* If parent data was NOT updated but also was NOT created or removed too
     139         * (e.j. was NOT changed at all), we have to check children too: */
    141140        if (!fWasUpdated && !UISettingsCache<ParentCacheData>::wasRemoved() && !UISettingsCache<ParentCacheData>::wasCreated())
    142141        {
     
    148147    }
    149148
    150     /* Reset the initial and the current data to be both empty.
    151      * Removes all the children: */
     149    /** Resets the initial and the current one data to be both empty.
     150      * Removes all the children. */
    152151    void clear()
    153152    {
     
    158157private:
    159158
     159    /** Returns QString representation of passed @a iIndex. */
    160160    QString indexToKey(int iIndex) const
    161161    {
     
    170170    }
    171171
    172     /* Children: */
     172    /** Holds the children. */
    173173    UISettingsCacheChildMap m_children;
    174174};
    175175
    176176#endif /* !___UISettingsDefs_h___ */
     177
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette