Hello all, I’m trying to use ofParameterGroup to store values read from an xml file.
My problem is that I don’t know how to retrieve the ofParameter instance from an ofParameterGroup.
I can do
float v = properties.getFloat("opacity");
But how can I
ofParameter aProp = properties.get("opacity");
properties beeing an instance of ofParameterGroup.
I understand that ofParameter is a class template and so I can’t define a local aProp without giving it a type (float, int whatever). But is there any kind of typecasting what would allow me to get back an instance of ofParameter ?
But in that case it means that I ‘know’ the kind of inner type that ofParameter is storing…
How could I stay abstract from this ? I would like an Interpolator class to register ofParameters, then interpolate theirs values (no matter if they are float or int) using theirs overloaded operators (+= in that case).
Crashes, because [] operator is intended to read ofParameterGroup content but not to write something in it.
So, adding an ofParameter to the ofParameterGroup must be done with add, then call getPosition(“opacity”), store the index value somewhere, then use it with the [] operator of ofParameterGroup. Quite tedious, unless I missed something…
My idea of using integer index is, obviously, speed. Getting the property from the group by string key can’t be as fast as integer key.
In fact, I want to use ofParameterGroup in a way totally unrelated with ofxGui… May be I’m following the wrong path.
I have properties in an xml file, then when I load the file, I create class instances. And instead of using plain float or int class members I thought to switch to ofParameter… Dunno, may be I’m over complicating things
as i said that example is valid if you are not using any gui, just change the gui with another ofParameterGroup. then you can load the whole hierarchy in one call by loading the top group. that’s of course if you know the hierarchy structure before hand if not then you’ll need to parse the xml anyway. at some point ofParameterGroup should be able to deserialized dynamically by having some kind of type indication in the file but that doesn’t work yet.
in any case something[index] when index doesn’t exist yet will usually crash in almost any other collection mostly when it’s a position based index.
Figured it out, reading OF source code -> ofXml.cpp, deserialize() method
The parameters must already exist in the group. The deserialize function doesn’t try to guess the parameters type (“2.something” being a float, 3 floats being an ofVector3, “true” being a bool, anything else being a string, and so on. Which would be very hazardous.
Yes, would be very cool and (dunno but) the same format could be used for ofMesh file saving, instead of current ascii (don’t remember the name) format…
No matter, still still fighting. I did get ofParameterGroup deserialize to work, in a small sandbox test application.
But, when integrated in my “real” app, I get a strange behavior.
I’ve stepped into deserialize source code and found that :
The current tag is well handled, is tagPushed, ok
BUT, when deserialize goes recursive the name of the next parameter is not retrieved correctly. In fact it appears that my ofParameter had a “” name.
Thanks Arturo, I’ll go that way… But I still don’t understand why the 1.0f value of the constructor is correctly taken in account, while the name is not…
In OF source code, ofParameter.h I can find this constructor
ofParameter(string name, ParameterType v);
If name is not used / has no effect, so why is there a constructor like this ?