Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Developing U++ » U++ Developers corner » true dynamic dispatching with Upp?
Re: true dynamic dispatching with Upp? [message #37564 is a reply to message #37558] Thu, 18 October 2012 23:15 Go to previous messageGo to previous message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
Hi Kohait,

if you can't change you're elements, maybe you can encapsulate them in a helper class that would manage the editing part:


class ElementHelperBase {
  public:
  virtual Element* get() = 0;
  virtual void Edit() = 0;
}

template<class ElementType>
class ElementHelper : public ElementHelperBase
{
  private:
  ElementType& element;  // initialized by some constructor

  public:
  virtual Element* get() { return &element; }
  virtual void Edit() { EditElement(element); }
}

// using function overloading
// you can add an 'EditElement()' function for each type

void EditElement(ElementA& element)
{
  ElementAEditor editor;
  ... do you're stuff
}

void EditElement(ElementB& element)
{
  ElementBEditor editor;
  ... do you're stuff
}


and finally you can do:

void EditElement(ElementHelperBase& e)
{
  e.Edit();
}



No need for dynamic_cast<> any more Wink

This will work, but you need to create ElementHelper classes and instead of keeping track of 'Element's you need to keep track of 'ElementHelper's.

I used somthing close to this in ma GraphCtrl class to manage editing the axis properties depending on axis class type

Hope this idea help's you

[Updated on: Thu, 18 October 2012 23:22]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Exception handling in Http::Dispatch
Next Topic: TheIDE : allow single translation file in main package
Goto Forum:
  


Current Time: Sat May 18 01:56:19 CEST 2024

Total time taken to generate the page: 0.03443 seconds