Connecting Tech Pros Worldwide Help | Site Map

Strong Type generic Composite class

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 4th, 2008, 11:15 AM
ManicQin
Guest
 
Posts: n/a
Default Strong Type generic Composite class

Hi,
I tried to code a -Strong typed generic composite class ...
i want to generalize the <function calland the <interfacethat the
compositor will implement
I tried writing it in many variations but none was suffice, or
working.
Any idea what should I look for?

Maybe a pseudo code will help explain:

//Pseudo code

template <class T , Function FunctinName>
class IComposite
{
void addnewItem(T* newItem) { m_list.push_back(newItem); } //
This line problematic too
void IterateThrough()
{
for (m_list::iterator iDx = m_list.begin;iDx != m_list.end(); iDx++)
{
(*iDx)->FunctionName(); //This line is the
main problem
}
}
vector<T*m_list;
}

class ICommand
{
virtual void work() = 0;
};

class worker : public ICommand
{
void work(){ cout << "BLA" << endl; }
};
class CommandComposite : public ICommand , public IComposite
<ICommand*,ICommand::*work>
{
void work()
{
IterateThrough();
}
};


Thanks

  #2  
Old July 4th, 2008, 11:45 AM
Ron AF Greve
Guest
 
Posts: n/a
Default Re: Strong Type generic Composite class

Hi,

Shouldn't it be

for (m_list::iterator iDx = m_list.begin();iDx != m_list.end(); iDx++)

--------------------------------------|



Regards, Ron AF Greve

http://www.InformationSuperHighway.eu

"ManicQin" <ManicQin@gmail.comwrote in message
news:b070ee82-1f22-46e9-b0df-1c56946bb959@s33g2000pri.googlegroups.com...
Quote:
Hi,
I tried to code a -Strong typed generic composite class ...
i want to generalize the <function calland the <interfacethat the
compositor will implement
I tried writing it in many variations but none was suffice, or
working.
Any idea what should I look for?
>
Maybe a pseudo code will help explain:
>
//Pseudo code
>
template <class T , Function FunctinName>
class IComposite
{
void addnewItem(T* newItem) { m_list.push_back(newItem); } //
This line problematic too
void IterateThrough()
{
for (m_list::iterator iDx = m_list.begin;iDx != m_list.end(); iDx++)
{
(*iDx)->FunctionName(); //This line is the
main problem
}
}
vector<T*m_list;
}
>
class ICommand
{
virtual void work() = 0;
};
>
class worker : public ICommand
{
void work(){ cout << "BLA" << endl; }
};
class CommandComposite : public ICommand , public IComposite
<ICommand*,ICommand::*work>
{
void work()
{
IterateThrough();
}
};
>
>
Thanks

  #3  
Old July 4th, 2008, 01:55 PM
Kai-Uwe Bux
Guest
 
Posts: n/a
Default Re: Strong Type generic Composite class

ManicQin wrote:
Quote:
Hi,
I tried to code a -Strong typed generic composite class ...
i want to generalize the <function calland the <interfacethat the
compositor will implement
I tried writing it in many variations but none was suffice, or
working.
Any idea what should I look for?
I don't even have an idea what you are trying to accomplish.

Quote:
Maybe a pseudo code will help explain:
>
//Pseudo code
>
template <class T , Function FunctinName>
class IComposite
{
void addnewItem(T* newItem) { m_list.push_back(newItem); } //
This line problematic too
void IterateThrough()
{
for (m_list::iterator iDx = m_list.begin;iDx != m_list.end(); iDx++)
{
(*iDx)->FunctionName(); //This line is the
main problem
And what is the problem?
Quote:
}
}
vector<T*m_list;
}
The above amounts to nothing more than calling a certain member function on
all items in a list of T*. If have no idea why you would call that a
composition class.
Quote:
class ICommand
{
virtual void work() = 0;
};
>
class worker : public ICommand
{
void work(){ cout << "BLA" << endl; }
};
class CommandComposite : public ICommand , public IComposite
<ICommand*,ICommand::*work>
{
void work()
{
IterateThrough();
}
};

Nope. Pseudocode did not help either.

Maybe, if you would show a use case, some piece of possible client code
together with an explanation of the resulting behavior, it might become
more clear what you are after.



Best

Kai-Uwe Bux
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.