Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Is this what delagates do?

Reply
Thread Tools

Is this what delagates do?

 
 
Steven T. Hatton
Guest
Posts: n/a
 
      09-07-2004
I just wrote some code that does the following:

Starting frome existing code that generates a grid of nested boxes
representing the range of indeces in a set of bounded unsigned int values,
e.g., vector<size_t>(3,3) creates a nested grid with 27==(3^3) leaves, and
all the boxes required to border each branch of the tree up to the root.
The details don't matter.

Understand the following to mean there are an arbitrary number child_nodes
at each level, and an arbitrary number of levels. Each child_node has an
associated box, and each box has a box_properties, with a connected
box_widget acting as an observer to state changes in its associated
box_properties:

tree->root_node->child_nodes->child_nodes->...->box->box_properties->box_widget

I wanted a way to uniquely address any given box, and to use that address to
modify the appearance of the widget. I created a class called an
addressed_visitor which is capable of descending the tree to a specified
address using a visitor pattern. When it gets to the specified node, it
detects that it has used all the information in its address which results
in a different behavior frome previous invocation of
addressed_visitor->visit(this).

This time it asks the node to return its associated box. The
addressed_visitor invokes a visit function on the box, but instead of
passing itself, it passes a 'payload' object which knows about box objects.
The visit function on the box invokes the visit function on the payload
which result in the payload calling a visit_properties function on the box
and passing its own payload box_properties_visitor object which knows about
box_properties. The box_properties are protected members of box, but the
box_properties_visitor is granted access within the visit_properties
function. The box_properties_visitor then visits the box_properties object
and calls functions on the box_properties which modify its state, followed
by a fire_properties_changed function which notifies all the registered
listeners of box_properties by passing the properties object to the
listeners. The widget is the only registered listener in this case, and
its handle_properties_changed function applies the changes (by brute force
for now), and refreshes the display.

This may seem overly complicated, and perhaps it is. I will observe that it
worked the first time I ran it, and I have yet to find any errors generated
by the implementation. It's also pretty much a repeated visitor pattern
with the variation that specialized payload visitors are passed at certain
points. Are these specialized payload visitors I'm describing the same
thing as what people call delegates?

--
"[M]y dislike for the preprocessor is well known. Cpp is essential in C
programming, and still important in conventional C++ implementations, but
it is a hack, and so are most of the techniques that rely on it. ...I think
the time has come to be serious about macro-free C++ programming." - B. S.

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      09-07-2004
Steven T. Hatton wrote:
> I just wrote some code that does the following:
>
> [...] The details don't matter. [...]
>
> This may seem overly complicated, and perhaps it is. I will observe that it
> worked the first time I ran it, and I have yet to find any errors generated
> by the implementation. It's also pretty much a repeated visitor pattern
> with the variation that specialized payload visitors are passed at certain
> points. Are these specialized payload visitors I'm describing the same
> thing as what people call delegates?
>


It seems that your question/issue belongs either to comp.object or to
comp.software.patterns. If you have a C++ language question, we'll be
happy to read about it.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments