Re: document class
On 26 Sep., 03:46, Joseph M. Newcomer <newco...@flounder.com> wrote:
On Fri, 24 Sep 2010 11:29:41 -0700 (PDT), mfc <mfcp...@googlemail.com> wr=
ote:
On 24 Sep., 20:01, Joseph M. Newcomer <newco...@flounder.com> wrote:
I did not say you shouldn't be updating the information; what I said w=
as that using a
CStringArray probably said too much about the representation of inform=
ation. In fact, the
communication should be reasonably opaque as to the types passed aroun=
d. I would have
something like a CProperties type, which took named properties. When =
passed into the
CDisplay world, the CProperties::GetValue and CProperties::SetValue me=
thods would be used
to get and set the values. When passed into the XML handler, it would=
use these methods
to extract the information and put it into whatever XML structure was =
used. Nobody
outside the XML handler should know or care that the representaiton is=
XML.
Could you give me a small example? I`m not sure if I got you right,
and I can`t find anything to this subject in the www....
CProperties is a MFC class or a class which I have to create bymyself?
And how =B4does this class relating to my CDisplay class for example???
It seems to me that every class (CDisplay class or CNetwork class)
will be a derrivated class from the CProperties class?
****
CProperties is a class you define yourself. It holds property informatio=
n encoded as
<name, value> pairs and you retrieve a value by providing its name.
Which way do you prefer to store these name strings? In each class -
CDisplay class, CNetwork class which is responsible for these
settings? And the Cproperty class only includes the Get/Set methods to
get/set these values, but has no clue about these values - This class
won`t need any further information.
The simplest form is
both name and value are strings. End of specification. Implementation c=
an be anything
you feel like, CStringArray, CMap, std::map, something of your own invent=
ion, nobody
outside it cares.
The CDisplay class for example is responsible for storing these values
- as string, as st::map and so on - nobody outside this class / the
property class etc. has these information.
Your program is written in terms of these CProperties objects.
Ok I have to install one global variable of each class (CDisplay,
CNetwork) and then I will call the virtual get/set methods of the
CProperty class to get
the specific required information.
Your
XML interface is responsible for encoding name-value pairs into a CProper=
ties object and
decoding values into XML from a CProperties object. I eliminated the int=
ermediate state
by representing my XML strictly as name-value pairs, so I just use SetPro=
perty and
GetProperty without worrying about how they are encoded.
****
I think the best would be to init a std::map for the xml file
information, so it should be really easy and fast to get the required
information.
void DisplayDialog::OnInitDialog()
{
CDisplay disp;
CString bright = disp.GetValue(NAME_OF_BRIGHTNESS);
}
class CProperty
{
public:
CProperty();
~CProperty();
virtual CString GetValue(const CString & name);
virtual void SetValue(const CString & name, const CString & value);
void SetValue(const CString & name, int value)
{
CString svalue;
svalue.Format(_T("%d"), value);
SetValue(name, svalue);
}
};
class CDisplay :
public CProperty
{
public:
CDisplay(void)
{
m_error = _T("Disp err: get value\n");
CDisplay::DISPLAY_BRIGHT.SetString(_T("Brightness"));
}
~CDisplay(void);
virtual CString GetValue(const CString & name)
{
if(name == CProperty::DISPLAY_BRIGHT)
return m_brightness;
else if(name == _T("contrast"))
return m_contrast;
else if(name == _T("state"))
return m_state;
else
return m_error;
}
virtual void SetValue(const CString & name, const CString & value)
{
if(name == _T("contrast"))
m_contrast = value;
}
void Init(void);
protected:
CString m_brightness;
CString m_contrast;
CString m_state;
CString m_error;
public:
static CString DISPLAY_BRIGHT;
static const CString DISPLAY_CONTRAST;
static const CString DISPLAY_STATE;
};
How is it possible to add a string to DISPLAY_CONTRAST using the const
attribute?
Using these name strings:
void DisplayDialog::OnInitDialog()
{
CDisplay disp;
CString bright = disp.GetValue(CDisplay::DISPLAY_BRIGHT);
}
best regards
Hans