I don't get your point, if you do
if (...)
else {
std::stack<...>
}
whenever the first condition is false I never compute anyway the values
below.
I can certainly do this:
if(in_representation(node))
{
...
}
else
{
std::stack<PFNodeID> trail;
PFNodeID ancestor = find_ancestor_in_representation(node, trail);
if(ancestor != PFNodeID::invalid())
{
...
}
else
{
std::list<PFNodeID> descendants = descendants_in_representation(node);
if(!descendants.empty())
{
...
}
}
}
But that just makes the thing more nested -- and if anything less rather
than more clear. At the moment, there are certain objections I have to
the way I've written it, but it is at least pretty clear what's going on.
There is also some not nice duplication like
m_listeners->node_was_deselected(node, commandDepth);
Agreed -- that's one of the objections I have to it.
And that line also is very suspicios.
For my understanding something called
"node_was_deselected" should be BOOL, and thus not being discarded like
this.
That thing I guess has some side effects then, not very nice for a
function called like that...
I think you may be missing the point because you don't have the context,
actually -- the point is to alert any listeners that a node was
deselected, so that they can react to it. (It's just an implementation
of the Observer pattern, for what it's worth.) I have similar functions
called things like "layer_will_be_deleted" and "layer_was_deleted" --
the point being that listeners sometimes need to be told before things
happen, sometimes afterwards and sometimes both. Hence the "will be" vs.
"was" aspect of the naming scheme.
For what it's worth, it's quite common to see Model-View implementations
that use a function called something like model_changed -- the name
node_was_deselected is more or less along the same sort of lines.
Well I don't know the problem enough, but for example you can divide
ancestors and descendants in two separate sets maybe..
This is from some hierarchical selection code -- either (1) the node is
selected and none of its ancestors or descendants are, or (2) one of the
node's ancestors is selected and none of that ancestor's ancestors or
descendants are (including the original node), or (3) some of the node's
descendants are selected, but neither it nor any of its ancestors are,
or (4) neither the node, nor any of its ancestors or descendants are
selected.
I'm not sure what you mean about dividing the ancestors and descendants
into two separate sets, though.
Cheers,
Stu