Dapfor home  

How to implement enumeration format?

// This example demonstrates how to present a numeric value (enum) as a text in the grid


//MyClass.h file
//Declaration of some C++ class
class CMyClass : public Dapfor::Common::CDataObject
{
public:
    //It is useful to use enumerations instead of long-type numeric values...
    //The grid can use the same identifiers to show the values returned by the functions of this class.
    enum
    {
        ...
        FidCity,
    };

    // A list of the numeric identifiers, used by CLongEnumFormat.
    // A table of mapping between these identifiers and strings 
    // is declared in MyClass.cpp file
    enum City
    {
        London = 100,
        Paris,
        Totonto,
        NewYork,
    };

public:
    CMyClass(City city);
    virtual ~CMyClass();

    //Public methods
    ...
    City    GetCity() const {return m_City;}

private:
    City    m_City;

    //Declaration of the map, that contains a list of the functions, that can be called by their identifiers.
    DF_DECLARE_FIELD_MAP();
};


//MyClass.cpp file

// This declaration is useful to present numeric value (enum) as a text in the grid
Dapfor::Common::CLongEnumFormat::Item cities[] =
{
    {CMyClass::London,  "London"},
    {CMyClass::Paris,   "Paris"},
    {CMyClass::Totonto, "Totonto"},
    {CMyClass::NewYork, "New York"},
};

// Declaration of the field map.
// To put an object of CMyClass into the grid, it should declare the table, 
// which permits to call specified functions by its identifiers. 
// Also, we can customize a presentation using the formats, uncluded in 
// Common library or our custom formats.
DF_BEGIN_FIELD_MAP(CMyClass)
    ...
    DF_ENUM_ID  (FidCity,     "City",     &CMyClass::GetCity,     0, DF_ENUM_FORMAT(cities))
DF_END_FIELD_MAP()


CMyClass::CMyClass(City city) : m_City(city)
{
}

//Virtual destructor
CMyClass::~CMyClass()
{
    //The object ends the life cycle. We notify remaining subscribers.
    NotifyDelete();
}



//Using sample:


    //grid initialization
    ...

    Dapfor::GUI::CHeader* header = new Dapfor::GUI::CHeader();
    ...
    header->Add(new Dapfor::GUI::CColumn(CMyClass::FidCity,     "City", 100));
    m_Grid.SetHeader(header);

    Dapfor::Common::CDataObject* pDO = new CMyClass(CMyClass::Paris);
    m_Grid.Add(pDO);



Copyright Dapfor 2007-2009
Generated on Sat Jan 30 15:01:23 2010 for MFCGrid by doxygen 1.5.5