It's posible to pass reference to an ofParameter<float> as a 'simple' C float type?

hey,
I have a class where I pass some variables (string, int, float, bool) as reference:

ofApp.h

    #include "ofxPrintMyVars.h"
    string s;
    float f;
    int i;
    bool b;

ofApp.cpp

setup()
    ofxPrintMyVars::addString("myString", &s);
    ofxPrintMyVars::addFloat("myFloat", &f);
    ofxPrintMyVars::addInt("myInt   ", &i);
    ofxPrintMyVars::addBool("myBool  ", &b);

ofxPrintMyVars.h

void addFloat(string name, float *var);
vector<float> floats;

ofxPrintMyVars.cpp

void ofxPrintMyVars::addFloat(string name, float *var, bool _newLine)
{
     floats.push_back(var);
}

The class just draws the values of these variables and runs very well.

But I want to add ofParameters types too.

Has the ofParameter type (or others) ‘a simple C float type variable’ somewhere accesible?
If it has, then I can pass directly this &var with the methods I have already implemented.

Something like:
ofApp

ofParameter<float> fParam;
ofxPrintMyVars::addFloat("myFloat", & (> fParam <) );

The point is that here I don’t need the ofParameter more stuff like min, max, name, listener …etc

If this is not possible, my approach would be to make “adder methods” to any ofParameter types or ofAbstractParameter, and then to cast them to identify types…etc.

I want to know if there is an easier way…

I think you can simply do:

ofParameter<float> fParam;
ofxPrintMyVars::addFloat("myFloat", (float*)&fParam.get());
1 Like

thanks @EduardFrigola, it works like that!

1 Like