ITQuants blog

Misys Sophis Risque/Value toolkit: how to use a CSRCustomMenu class for your own types

Nov 8

Written by:
11/8/2012 1:22 PM  RssIcon

Using the CSRCustomMenu class gives the opportunity for the developer to control at least the behaviour of the items and the type of the internal variable used for storing the information. The subject of this entry is to detail the virtual methods which have to be overloaded in order to control the type of the variable.

In our sample, we will try to declare a CSRCustomMenu on which we will ba able to get an information of type long using the generic methods CSRElement::LoadGeneralElement, CSRElement::SaveGeneralElement, GetValue and SetValue.

First declare a new class that inherits from CSRCustomMenu. In the CSRCustomeMenu class, there are 2 member variables which are important:

    - fListValue which stores the index of the menu

    - fValue, a pointer to the portion of memory which will be used to store the information using the right type.

In order to set the portion of memory stored in fValue, the initialization of fListValue and fValue hhave to be done using the SetValueFromList and SetListFromValue method as declared below:

01.class CLongMenu : public CSRCustomMenu 
04.    CLongMenu(CSRFitDialog *dialog, int ERId_Menu);
06.    virtual void SetValueFromList();
07.    virtual void SetListFromValue();
09.    void    init();
10.    size_t m_size;


Concerning the implementation fo these methods, in our case, we just want to copy the index into the long value and the inverse. We will implement it as follow:

01.void CLongMenu::SetValueFromList()
03.    long *lValue = (long*)fValue;
04.    if (fListValue>0 && fListValue <= m_size)
05.        *lValue = fListValue;
06.    else
07.        *lValue = 0;
10.void CLongMenu::SetListFromValue()
12.    long lValue = *(long*)fValue ;
13.    if (lValue<=m_size && lValue>0)
14.        fListValue = lValue;
15.    else
16.        fListValue = 0;


 The declaration of the size of memory to be allocated and the type oof the variable used is done in the constructor of CSRCustomMenu as follow:

01.CLongMenu::CLongMenu(CSRFitDialog *dialog, int ERId_Menu)
02.        : CSRCustomMenu(dialog, ERId_Menu, 
03.    false// not editable
04.    NSREnums::dLong,    // type of the variable 
05.    sizeof(long), // size of the type
06.    2)  // default value index
08.    ZeroMemory( fValue, sizeof(long)) ;
10.    init();


 Finally, our little method init (optional) will add the the menu items in the combo box, using the CSRcustomMenu::AddElement method as follow:

1.void CLongMenu::init()
3.    static const char* _items[] = { "Item0", "Item1", "Item2" };
4.    m_size = sizeof(_items)/sizeof(const char*);
5.    for (size_t i=0;i
6.        AddElement(_items[i]);


Don't forget that the fListValue is 1-indexed and not 0-indexed. Item0 will the correspond to a value of 1 when getting and setting using the GetValue and SetValue methods.

That's all!

Tags: Misys , Risque , C++
Categories: Sophis

Search blog