templates and listeners

This is a discussion on templates and listeners within the C++ Programming forums, part of the General Programming Boards category; does any one has any good ideas to solve this problem. I have a base window class that is called ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    470

    templates and listeners

    does any one has any good ideas to solve this problem.

    I have a base window class that is called GfxWindow that generates a number of events. These events are given notifications within the GfxWindowListener class.
    Code:
    class GfxWindowListener
    {
    public:
        virtual void ModifiedTitle(GfxWindow* window,
                                     const std::string& str) = 0;
        virtual void DeleteWindow(GfxWindow* window) = 0;
    
        virtual void Select(GfxWindow* window) = 0;
        virtual void UnSelect(GfxWindow* window) = 0;
        virtual void Select2(GfxWindow* window) = 0;
    };
    I then create adapter classes which will be used to derive from

    Code:
    class GfxInfoAdapter : public GfxWindowListener
    {
    public:
        virtual void OnSelect(GfxWindow* window)
        {
    
        }
    
        virtual void OnUnSelect(GfxWindow* window)
        {
    
        }
    
        virtual void OnSelect2(GfxWindow* window)
        {
    
        }
    };
    
    class GfxSelectAdapter : public GfxWindowListener
    {   
    public:
        virtual void ModifiedTitle(GfxWindow* window,
                                   const std::string& str) 
        {
    
        }
    
        virtual void DeleteWindow(GfxWindow* window) 
        { 
        
        }
    };
    The problem is that GfxWindow will be derived from GfxListBox that will have its own set of events. I could do something like
    Code:
    class GfxListBoxListener : public GfxWindowListener
    but this would mean that cilent programers would not be able to use the GfxWindow adapter class. Thus, I do something like
    Code:
    template<class GFX_WINDOW_LISTENER = GfxWindowListener>
    class GfxListBoxListener : public GFX_WINDOW_LISTENER
    {
    public:
        typedef long int SizeType;
        
        // when the user has requested to insert a string
        virtual void RequestInsertString(GfxListBox* lb,
                                         SizeType place) = 0;
    
        virtual void InsertString(GfxListBox* lb,
                                  const std::string& str, 
                                  SizeType place) = 0;
    
        virtual void AddString(GfxListBox* lb,
                               const std::string& str) = 0;
    
        virtual void ReplaceString(GfxListBox* lb,
                                   SizeType item, 
                                   const std::string& str) = 0;
    
        virtual void DeleteItem(GfxListBox* lb, SizeType item) = 0;
    
    };
    Is this a good thing or should I create separate adapters for GfxListBox?

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    470
    Ok, I think I solved the problem I was having with the design.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21