XLL+ Class Library

AvgOptDataCache class

The AvgOptDataCache object contains all the AvgOptData objects for the add-in instance. This includes (i) new objects, waiting to be calculated, (ii) objects currently being calculated by a worker thread and (iii) objects whose calculation are complete.

The cache uses an STL std::set to map the objects against their inputs. Thus when the add-in function is called it can build a new AvgOptData object and compare it with those already in the cache; if it is matched, then the existing object can be used, and there is no need to create a new one.

Only three methods are provided by the class:

FunctionDescription
Find(AvgOptData* t) If an object in the cache has the same inputs as *t then a pointer to the existing object is returned. If no match is found, then zero is returned.
Add(AvgOptData* t) The object is added to the cache.
Clear() All objects are removed from the cache.
class AvgOptDataCache
{
protected:
    typedef std::set<AvgOptData*, AvgOptData_less> set_t;
    set_t m_set;
public:
    AvgOptData* Find(AvgOptData* t)
    {
        set_t::iterator itF = m_set.find(t);
        return itF == m_set.end() ? 0 : *itF;
    }
    void Add(AvgOptData* t)
    {
        ASSERT(t != 0);
        m_set.insert(t);
    }
    void Clear()
    {
        for (set_t::iterator it = m_set.begin(); it != m_set.end(); it++)
            delete *it;
        m_set.clear();
    }
};

AvgOptData_less

This helper class acts as the predicate for a set containing the AvgOptData pointers. A set normally compares two contained objects using "x < y"; however since our set contains pointers, we need to compare "*x < *y". The AvgOptData_less class implements this behavior.

Next: Converting a project to RTD >>