Strong Type generic Composite class

Discussion in 'C++' started by ManicQin, Jul 4, 2008.

  1. ManicQin

    ManicQin Guest

    Hi,
    I tried to code a -> Strong typed generic composite class ...
    i want to generalize the <function call> and the <interface> that 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
    ManicQin, Jul 4, 2008
    #1
    1. Advertising

  2. ManicQin

    Ron AF Greve Guest

    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" <> wrote in message
    news:...
    > Hi,
    > I tried to code a -> Strong typed generic composite class ...
    > i want to generalize the <function call> and the <interface> that 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
    Ron AF Greve, Jul 4, 2008
    #2
    1. Advertising

  3. ManicQin

    Kai-Uwe Bux Guest

    ManicQin wrote:

    > Hi,
    > I tried to code a -> Strong typed generic composite class ...
    > i want to generalize the <function call> and the <interface> that 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.


    > 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?

    > }
    > }
    > 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.

    > 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
    Kai-Uwe Bux, Jul 4, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    435
  2. ManicQin
    Replies:
    0
    Views:
    250
    ManicQin
    Jul 17, 2008
  3. minlearn
    Replies:
    2
    Views:
    454
    red floyd
    Mar 13, 2009
  4. namekuseijin

    Re: "Strong typing vs. strong testing"

    namekuseijin, Sep 27, 2010, in forum: C Programming
    Replies:
    214
    Views:
    3,343
    Nick Keighley
    Oct 17, 2010
  5. namekuseijin

    Re: "Strong typing vs. strong testing"

    namekuseijin, Sep 27, 2010, in forum: Python
    Replies:
    229
    Views:
    3,440
    Gregory Ewing
    Oct 29, 2010
Loading...

Share This Page