Click here to Skip to main content
15,891,766 members
Articles / Desktop Programming / MFC

Ultimate FastMaps!

Rate me:
Please Sign up or sign in to vote.
3.73/5 (7 votes)
19 Jan 2000 153.3K   1.1K   35  
A fully featured map class that uses balanced trees to store and retrieve data quickly by key
//=========================================================================
//
// Copyright � Dundas Software Ltd. 1998, All Rights Reserved
//
// tbtremfc.h : header file
//
//==========================================================================

// conditional compilation to avoid multiple defintions
#ifndef _tbtremfc_h_
#define _tbtremfc_h_

#ifndef _tbtreed_h_
#include "tbtreed.h"
#endif

//==========================================================================
// MFC Derived tree class: string key, string data
//==========================================================================
class EXT_CLASS CtStringToString : public CObject, public tStringToString
{
public:
    DECLARE_SERIAL(CtStringToString)
    virtual ~CtStringToString();
    virtual void Serialize(CArchive& ar);
protected:
    virtual int onStore(void* where, POSITION node);
};

//==========================================================================
// MFC Derived tree class: string key, unsigned long data
//==========================================================================
class EXT_CLASS CtStringToULong : public CObject, public tStringToULong
{
public:
    DECLARE_SERIAL(CtStringToULong)
    virtual ~CtStringToULong();
    virtual void Serialize(CArchive& ar);
protected:
    virtual int onStore(void* where, POSITION node);
};

//==========================================================================
// MFC Derived tree class: string key, CObject data
//==========================================================================
class EXT_CLASS CtStringToCObject : public CObject, public tStringToULong
{
public:
    DECLARE_SERIAL(CtStringToCObject)
    virtual ~CtStringToCObject();
    virtual void Serialize(CArchive& ar);
    
    inline int Set(const char* key, CObject* data);
    inline CObject* Get(const char* key);
    inline CObject* GetData(POSITION pos);
    inline int SetData(POSITION pos, CObject* data);
    
protected:
    virtual void onDeleteData(void*& dataPtr);
    virtual int onSetData(void*& dataPtr, void* data);
    virtual int onStore(void* where, POSITION node);
    
    // CObject does not support serialization to streams:
    virtual int Store(NQ ostream* ostrm){return 0;}
    virtual int Load(NQ istream* istrm){return 0;}
};

//==========================================================================
// MFC Derived tree class: unsigned long key, string data
//==========================================================================
class EXT_CLASS CtULongToString : public CObject, public tULongToString
{
public:
    DECLARE_SERIAL(CtULongToString)
    virtual ~CtULongToString();
    virtual void Serialize(CArchive& ar);
protected:
    virtual int onStore(void* where, POSITION node);
};

//==========================================================================
// MFC Derived tree class: unsigned long key, unsigned long data
//==========================================================================
class EXT_CLASS CtULongToULong : public CObject, public tULongToULong
{
public:
    DECLARE_SERIAL(CtULongToULong)
    virtual ~CtULongToULong();
    virtual void Serialize(CArchive& ar);
protected:
    virtual int onStore(void* where, POSITION node);
};

//==========================================================================
// MFC Derived tree class: unsigned long key, CObject data
//==========================================================================
class EXT_CLASS CtULongToCObject : public CObject, public tULongToULong
{
public:
    DECLARE_SERIAL(CtULongToCObject)
    virtual ~CtULongToCObject();
    virtual void Serialize(CArchive& ar);
    
    inline int Set(unsigned long key, CObject* data);
    inline CObject* Get(unsigned long key);
    inline CObject* GetData(POSITION pos);
    inline int SetData(POSITION pos, CObject* data);
    
protected:
    virtual void onDeleteData(void*& dataPtr);
    virtual int onSetData(void*& dataPtr, void* data);
    virtual int onStore(void* where, POSITION node);
    
    // CObject does not support serialization to streams:
    virtual int Store(NQ ostream* ostrm){return 0;}
    virtual int Load(NQ istream* istrm){return 0;}
};

//==========================================================================
// MFC Derived tree class: long key, string data
//==========================================================================
class EXT_CLASS CtLongToString : public CObject, public tLongToString
{
public:
    DECLARE_SERIAL(CtLongToString)
    virtual ~CtLongToString();
    virtual void Serialize(CArchive& ar);
protected:
    virtual int onStore(void* where, POSITION node);
};

//==========================================================================
// MFC Derived tree class: long key, unsigned long data
//==========================================================================
class EXT_CLASS CtLongToULong : public CObject, public tLongToULong
{
public:
    DECLARE_SERIAL(CtLongToULong)
    virtual ~CtLongToULong();
    virtual void Serialize(CArchive& ar);
protected:
    virtual int onStore(void* where, POSITION node);
};

//==========================================================================
// MFC Derived tree class: long key, CObject data
//==========================================================================
class EXT_CLASS CtLongToCObject : public CObject, public tLongToULong
{
public:
    DECLARE_SERIAL(CtLongToCObject)
    virtual ~CtLongToCObject();
    virtual void Serialize(CArchive& ar);
    
    inline int Set(long key, CObject* data);
    inline CObject* Get(long key);
    inline CObject* GetData(POSITION pos);
    inline int SetData(POSITION pos, CObject* data);
    
protected:
    virtual void onDeleteData(void*& dataPtr);
    virtual int onSetData(void*& dataPtr, void* data);
    virtual int onStore(void* where, POSITION node);
    
    // CObject does not support serialization to streams:
    virtual int Store(NQ ostream* ostrm){return 0;}
    virtual int Load(NQ istream* istrm){return 0;}
};

//--------------------------------------------------------------------------
// INLINE members for all classes defined here.
//--------------------------------------------------------------------------

// CtStringToCObject
inline int CtStringToCObject::Set(const char* key, CObject* data)
{
    return set((void*)key, (void*)data);
}

inline CObject* CtStringToCObject::Get(const char* key)
{
    return (CObject*)getData(find((void*)key));
}

inline CObject* CtStringToCObject::GetData(POSITION pos)
{
    return (CObject*)getData(pos);
}

inline int CtStringToCObject::SetData(POSITION node, CObject* data)
{
    return setData(node, (void*)data);
}

// CtULongToCObject
inline int CtULongToCObject::Set(unsigned long key, CObject* data)
{
    return set((void*)key, (void*)data);
}

inline CObject* CtULongToCObject::Get(unsigned long key)
{
    return (CObject*)getData(find((void*)key));
}

inline CObject* CtULongToCObject::GetData(POSITION pos)
{
    return (CObject*)getData(pos);
}

inline int CtULongToCObject::SetData(POSITION node, CObject* data)
{
    return setData(node, (void*)data);
}

// CtLongToCObject
inline int CtLongToCObject::Set(long key, CObject* data)
{
    return set((void*)key, (void*)data);
}

inline CObject* CtLongToCObject::Get(long key)
{
    return (CObject*)getData(find((void*)key));
}

inline CObject* CtLongToCObject::GetData(POSITION pos)
{
    return (CObject*)getData(pos);
}

inline int CtLongToCObject::SetData(POSITION node, CObject* data)
{
    return setData(node, (void*)data);
}

#endif
//// end ///////////////////////////////////////////////////////////////////

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United States United States
Since 1992 Dundas Data Visualization has been helping companies all over the world visualize their data. Dundas products have a global reputation of being the highest quality, and are all designed, built and tested to meet the strictest requirements that developers and business managers demand.

Our showcase product is Dundas Dashboard, an easy-to-integrate digital dashboard software solution. Dundas Dashboard allows for the rapid and collaborative development of performance dashboards, helping companies leverage their business intelligence (BI) solutions.

Our web-based dashboard software comes with wizard interfaces, and a unique Dundas DashFlowTM process, allowing for the simultaneous development of an executive dashboard by business analysts, IT staff and database administrators. It also uses premier charts, maps, gauges and graph controls, letting end-users visualize their data as required.

Dundas also offers superb, world class consulting services for those companies that do not have the in-house expertise to implement their data visualization projects.

The quality of our products in conjunction with our unmatched technical support, numerous awards and years of experience reflect Dundas Data Visualization's commitment to being the best!
This is a Organisation

3 members

Comments and Discussions