To easily check, compare, etc. VectorComposite should have the method getStructure() however, the ordering in the unordered_map and the string provided by the user does necessarily follow the same order.
So I propose to return a sorted (alphabetically) string. And agreeing on the Wolf::Structure are a sorted, maybe a class instead of a typedef is required here, I don't know.
Alphabetical order is easy to achieve. Just replace unordered_map by map, and that's it. Then obtaining getters and so on is simple.
However alphabetical order is not the best desired option. We are used to PO, POV, and the like, for a reason, because it is more intuitive. I want to keep this custom ordering.
For this, we can have a field structure in VectorComposite, in the same manner as we have it in HasStateBlocks (therefore Sensor, Frame, Capture and Landmark), and in Processors and Problem.
This field structure_ can be defined beforehand (i.e. in the constructor) or built incrementally as state blocks are emplaced in the VectorComposite. HasStateBlocks has a similar mechanism.
Of course the order is not "very important". It just contributes to peace of mind when viewing logs and debugging.
I think that for comparing strings the order should be clear. Otherwise we can leave it unordered and whenever it has to be compared, then it has to be sorted (this is not convenient for assertions and simple checks).
If we want to specify an special order we can, for example, first in this order POVW, afterwards in alphabetical order.
If in this issue you are mostly concerned with comparing structures, then yes, a predictable order is necessary, and this can be alphabetical. In such case I'd redesign VectorComposite as a regular map to really simplify (and also make more efficient) the getter:
This would be also beneficial, for the same reason, in HasStateBlocks.
However, this has some impact in other classes. In particular, currently Problem, Processor and HasStateBlocks already have the getStructure() and this returns the predefined order, which is not alphabetical.
My worries about StateStructure being a mere typedef of string is that it is very limited.
As structure, for example, we might want to store the sizes of each block; the local sizes; the name of the state block that it is supposed to represent (in case you want to create a state block with it using a Factory), and the like. Then, as you say, you can add methods to manipulate (union, intersection, concatenation, comparison, etc).
I thought about doing it during the big merge but I had so many things to touch that I could not think clearly about what we really needed, and I did not want to create a whole now fancy class if it was not necessary.
BTW as a small temporary fix concerning the last part of #349 (comment 7414), I am going to homogenize the API for the name of the structure_ variables and the getStructure() methods. This will be pushed to devel without further discussion.
From here, one can use the pretty option for ordering the elements "POV" when e.g. printing on screen, but the normal structure when doing any other kind of manipulation.
Why not define a to_string method and just iterate the underlying set and build structure_pretty when you want to print it instead of keeping it updated every time you add a char. Then StateStructure is just a set with a custom to_string method.
The idea is not to have a pretty string to print the string itself, but to have a pretty order to print the blocks in good order, e.g. if pretty = "POVba" then,
yes, exactly. But this applies to VectorComposite, to HasStateBlocks, to Processors, and to Problem, not merely to StateStructure.
I find annoying that when printing vectors the blocks appear in random orders (so difficult for debugging when comparing e.g. one vector against another one, visually on the screen).
Likewise, I find it not nice to have alphabetical order when it is humans that are analyzing the results.
This is already the case with the current string implementation of StateStructure. However, VectorComposite does not have a StateStructure defined, only HasStateBlocks, Problem and Processor have it.
SO I need to add a StateStructure to VectorComposite for the couts to be pretty..
In Problem, Processors, HasStateBlocks and VectorComposite, have a StateStructure which is a std::string as now (I need to add it also to VectorComposite).
But the question of where to define the pretty ordering still remains, right? We cannot expect that the user will always initialize StateStructure with "POV" for instance, or that they will do
We can also force it in the constructor, but this seems to indicate that the structure in non mutable, which is not true -- you can add blocks to a structure at any time.
Processors can add blocks to Frames. In such case the final order depends on the sequence followed. If the Frame had a predefined structure, this will not be altered. Only blocks that were not in the predefined structure will be appended.
Logically, when a Processor appends blocks to a Frame, it does it in its own 'pretty' order. That means:
Processor 1: "POV"Processor 2: "CDLOB"
resulting structure in Frames and Problem: "POVCDLB"
In this case, to me, "P", "O" and "V" are no longer mere chars and are another type that accepts a particular ordering, namely P < O < V. What I understand is that this ordering is defined locally for each StateStructure so it is the responsibility of the programmer to always input the values in the right order if they expect to get the same prints. Suppose we run the following code
because you, as a programmer, have not been "careful".
What I am trying to get at, is that I feel this opens up the door for some weird cases of unexpected behavior regarding this ordering thing and I don't know if this is something we are ok with.
I am ok with it, just throwing my thoughts out here.
Following your last example, what happens when you have
Processor 1: "POV"Processor 2: "VOP"
Whose order ends up "winning"? I guess we get Problem: POV?
And there might be issues if programmers are not careful. However, these issues have no impact on the machine, only on humans reading the screen. This is why we are tolerating them more or less.