object architecture,

  • Thread starter Vincent RICHOMME
  • Start date
V

Vincent RICHOMME

Hi,

My goal is to display in a graphical application properties of my
objects. To do that I am using on windows a graphical control (MFC)
called EPropCtrl with the following definition :


Code:
class IPropertyHost
{
public:
     virtual void GetProperties( EPropList& PropList ) {}
};


// EPropCtrl : Windows control (MFC) that looks like a ListBox
class EPropCtrl
{
     public:
     SetPropPointer( IPropertyHost* pHost);
};


Pratically when I want to display/modify properties of a simple class
defined like this :

Code:
class Simple
{
protected:
     int iValue;
};

I just need to create a new class deriving from Simple Class AND from
IPropertyHost like this :

Code:
class SimpleProp : public Simple,
                    public IPropertyHost
{
public:
     virtual void     GetProperties( EPropList& PropList )
     {
         PropList.AddPropInt(this,_T("iValue"),&iValue, false);
     }



     IPropertyHost*     GetPropPointer() { return this; }
protected:
     int iValue;
};
and after to update my control by doing :

EPropCtrl objPropCtrl; // Graphical window to display/edit propertis
SimpleProp simpleProp; //Objet SimpleProp
objPropCtrl.SetPropPointer( simpleProp.GetPropPointer() );
// --------------- SO FAR EVERYTHING IS OK --------------------------

Now let's consider two objects that wrapps C structures like this :

Code:
typedef struct tagStructB
{
     int        iSizeB;
     char*      szTextB;
} StructB;

typedef struct tagStructA
{
     int        iSizeA;
     char*      szTextA;

     StructB sStructB;
} StructA;

class B
{
public:
     B(structB& refStructB) { m_refStructB = refStructB ;}
     int        GetSize() {return m_StructB.iSizeB;}
     char*    GetText() {return m_StructB.szTextB;}

protected:
     structB& m_refStructB;
};


class A
{
public:
     A();
     int        GetSize() {return m_StructA.iSizeA;}
     char*    GetText() {return m_StructA.szTextA;}
     B&        GetB() { return m_B; }


protected:
     structA m_StructA;
     B        m_B;
};

Example of use :

A m_a;
int iSizeA = m_A.GetSize();
m_A.GetB().GetSize();

If I am doing the same as the simple example I would do somthing like :

class BProp: public B,
public IPropertyHost
{
public:
virtual void GetProperties( EPropList& PropList )
{
PropList.AddPropInt(this,_T("iSizeB"),&m_refStructB.iSizeB, false);
PropList.AddPropString(this,_T("szTextB"),&m_refStructB.szTextB, false);

}


IPropertyHost* GetPropPointer() { return this; }
};

class AProp: public A,
public IPropertyHost
{
public:
virtual void GetProperties( EPropList& PropList )
{

PropList.AddPropInt(this,_T("iSizeA"),&m__StructA.iSizeA, false);
PropList.AddPropString(this,_T("szTextA"),&m__StructA.szTextA, false);
m_B.GetProperties( PropList ); // <----- CANNOT WORK
}


IPropertyHost* GetPropPointer() { return this; }
};



EPropCtrl objPropCtrl;
AProp objAProp;

objPropCtrl.SetPropPointer( objAProp.GetPropPointer() );

// PROBLEM : I CANNOT call m_B.GetProperties( PropList ) to display B
properties from AProp since Aprop has only a B and not a BProp.
HOw should I change my objets to display my properties ??????????????
 
V

Victor Bazarov

Vincent said:
My goal is to display in a graphical application properties of my
objects. To do that I am using on windows a graphical control (MFC)
called EPropCtrl with the following definition :


Code:
class IPropertyHost
{
public:
virtual void GetProperties( EPropList& PropList ) {}
};


// EPropCtrl : Windows control (MFC) that looks like a ListBox
class EPropCtrl
{
public:
SetPropPointer( IPropertyHost* pHost);
};


Pratically when I want to display/modify properties of a simple class
defined like this :

Code:
class Simple
{
protected:
int iValue;
};

I just need to create a new class deriving from Simple Class AND from
IPropertyHost like this :

Code:
class SimpleProp : public Simple,
public IPropertyHost
{
public:
virtual void     GetProperties( EPropList& PropList )
{
PropList.AddPropInt(this,_T("iValue"),&iValue, false);
}



IPropertyHost*     GetPropPointer() { return this; }
protected:
int iValue;
};
and after to update my control by doing :

EPropCtrl objPropCtrl; // Graphical window to display/edit propertis
SimpleProp simpleProp; //Objet SimpleProp
objPropCtrl.SetPropPointer( simpleProp.GetPropPointer() );
// --------------- SO FAR EVERYTHING IS OK --------------------------

Now let's consider two objects that wrapps C structures like this :

Code:
typedef struct tagStructB
{
int        iSizeB;
char*      szTextB;
} StructB;

typedef struct tagStructA
{
int        iSizeA;
char*      szTextA;

StructB sStructB;
} StructA;

class B
{
public:
B(structB& refStructB) { m_refStructB = refStructB ;}
int        GetSize() {return m_StructB.iSizeB;}
char*    GetText() {return m_StructB.szTextB;}

protected:
structB& m_refStructB;
};


class A
{
public:
A();
int        GetSize() {return m_StructA.iSizeA;}
char*    GetText() {return m_StructA.szTextA;}
B&        GetB() { return m_B; }


protected:
structA m_StructA;
B        m_B;
};

Example of use :

A m_a;
int iSizeA = m_A.GetSize();
m_A.GetB().GetSize();

If I am doing the same as the simple example I would do somthing like
:
class BProp: public B,
public IPropertyHost
{
public:
virtual void GetProperties( EPropList& PropList )
{
PropList.AddPropInt(this,_T("iSizeB"),&m_refStructB.iSizeB, false);
PropList.AddPropString(this,_T("szTextB"),&m_refStructB.szTextB,
false);
}


IPropertyHost* GetPropPointer() { return this; }
};

class AProp: public A,
public IPropertyHost
{
public:
virtual void GetProperties( EPropList& PropList )
{

PropList.AddPropInt(this,_T("iSizeA"),&m__StructA.iSizeA, false);
PropList.AddPropString(this,_T("szTextA"),&m__StructA.szTextA, false);
m_B.GetProperties( PropList ); // <----- CANNOT WORK
}


IPropertyHost* GetPropPointer() { return this; }
};



EPropCtrl objPropCtrl;
AProp objAProp;

objPropCtrl.SetPropPointer( objAProp.GetPropPointer() );

// PROBLEM : I CANNOT call m_B.GetProperties( PropList ) to display B
properties from AProp since Aprop has only a B and not a BProp.
HOw should I change my objets to display my properties ??????????????

You can make your 'AProp' to keep a 'BProp' instead...

You could change the whole scheme of creating/displaying of properties
to using "visitors" instead of deriving "property-ized" objects from
"regular" ones.

V
 
V

Victor Bazarov

red said:
Vincent said:
Hi,

My goal is to display in a graphical application properties of my
objects. To do that I am using on windows a graphical control (MFC)
called EPropCtrl with the following definition :
[long OT post redacted]

You would do better in a newsgroup with MFC or Windows in its name.

See FAQ 5.9 :
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9

Not really, he wouldn't. The question is not about MFC per se.
Did you bother to read it to the end?

V
 
V

Vincent RICHOMME

Victor Bazarov wrote:
Could You tell me more about your suggestion on visitors ?
Just give me an example starting from what I give. I will try to understand.

thanks





Vincent said:
My goal is to display in a graphical application properties of my
objects. To do that I am using on windows a graphical control (MFC)
called EPropCtrl with the following definition :


Code:
class IPropertyHost
{
public:
virtual void GetProperties( EPropList& PropList ) {}
};


// EPropCtrl : Windows control (MFC) that looks like a ListBox
class EPropCtrl
{
public:
SetPropPointer( IPropertyHost* pHost);
};


Pratically when I want to display/modify properties of a simple class
defined like this :

Code:
class Simple
{
protected:
int iValue;
};

I just need to create a new class deriving from Simple Class AND from
IPropertyHost like this :

Code:
class SimpleProp : public Simple,
public IPropertyHost
{
public:
virtual void     GetProperties( EPropList& PropList )
{
PropList.AddPropInt(this,_T("iValue"),&iValue, false);
}



IPropertyHost*     GetPropPointer() { return this; }
protected:
int iValue;
};
and after to update my control by doing :

EPropCtrl objPropCtrl; // Graphical window to display/edit propertis
SimpleProp simpleProp; //Objet SimpleProp
objPropCtrl.SetPropPointer( simpleProp.GetPropPointer() );
// --------------- SO FAR EVERYTHING IS OK --------------------------

Now let's consider two objects that wrapps C structures like this :

Code:
typedef struct tagStructB
{
int        iSizeB;
char*      szTextB;
} StructB;

typedef struct tagStructA
{
int        iSizeA;
char*      szTextA;

StructB sStructB;
} StructA;

class B
{
public:
B(structB& refStructB) { m_refStructB = refStructB ;}
int        GetSize() {return m_StructB.iSizeB;}
char*    GetText() {return m_StructB.szTextB;}

protected:
structB& m_refStructB;
};


class A
{
public:
A();
int        GetSize() {return m_StructA.iSizeA;}
char*    GetText() {return m_StructA.szTextA;}
B&        GetB() { return m_B; }


protected:
structA m_StructA;
B        m_B;
};

Example of use :

A m_a;
int iSizeA = m_A.GetSize();
m_A.GetB().GetSize();

If I am doing the same as the simple example I would do somthing like
:
class BProp: public B,
public IPropertyHost
{
public:
virtual void GetProperties( EPropList& PropList )
{
PropList.AddPropInt(this,_T("iSizeB"),&m_refStructB.iSizeB, false);
PropList.AddPropString(this,_T("szTextB"),&m_refStructB.szTextB,
false);
}


IPropertyHost* GetPropPointer() { return this; }
};

class AProp: public A,
public IPropertyHost
{
public:
virtual void GetProperties( EPropList& PropList )
{

PropList.AddPropInt(this,_T("iSizeA"),&m__StructA.iSizeA, false);
PropList.AddPropString(this,_T("szTextA"),&m__StructA.szTextA, false);
m_B.GetProperties( PropList ); // <----- CANNOT WORK
}


IPropertyHost* GetPropPointer() { return this; }
};



EPropCtrl objPropCtrl;
AProp objAProp;

objPropCtrl.SetPropPointer( objAProp.GetPropPointer() );

// PROBLEM : I CANNOT call m_B.GetProperties( PropList ) to display B
properties from AProp since Aprop has only a B and not a BProp.
HOw should I change my objets to display my properties ??????????????


You can make your 'AProp' to keep a 'BProp' instead...

You could change the whole scheme of creating/displaying of properties
to using "visitors" instead of deriving "property-ized" objects from
"regular" ones.

V
 
R

red floyd

Victor said:
red said:
Vincent said:
Hi,

My goal is to display in a graphical application properties of my
objects. To do that I am using on windows a graphical control (MFC)
called EPropCtrl with the following definition :
[long OT post redacted]

You would do better in a newsgroup with MFC or Windows in its name.

See FAQ 5.9 :
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9

Not really, he wouldn't. The question is not about MFC per se.
Did you bother to read it to the end?

Sorry, I saw all this properties stuff, and IThis, IThat and
IAmAnInterface stuff and pretty much figured it was. My apologies to
the OP.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top