Fill in the blanks - OOP communication

I have a 3rd party working on a system for me and they've delivered a working vxWorks image with binaries that run their software. They've also provided me with source code describing the specific models, but haven't provided me the entire development environment yet. I'm trying to fill in some of the dependencies so I can emulate their models in my own software for when the vxWorks machines fail and I can only emulate real-time in Windows. I have everything working except for the configuration loading.

In the following code, I am writing GenericBase and ParameterSet from scratch as those were not provided. CReadOnlyModule is read-only since I expect to get updates and can't maintain configuration control if I change this class.

Header
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "GenericBase.h"
#include <string>
class ParameterSet;

class CReadOnlyModule : public GenericBase
{
public:
    CReadOnlyModule(const std::string& inName);
                  
private:
    float                 mMyParameter1;
    ParameterSet*         m_pParameterSet;
};


Source
1
2
3
4
5
6
7
8
9
10
11
#include "CReadOnlyModule.h"
#include "ParameterSet.h"

                                         // I think inName is "ReadOnlyModule"
CReadOnlyModule::CReadOnlyModule(const std::string& inName)
                                 : GenericBase(inName)
{
    m_pParameterSet = new ParameterSet("default", false);
    
    m_pParameterSet->CreateFloat(&mMyParameter1, "MyParameter1");
}


I also have a configuration file which sets the value of mMyParameter1. It looks like this (but it contains several Modules and parameters per module.
MODULE ReadOnlyModule
	FLOAT MyParameter1 200
ENDDEF MODULE ReadOnlyModule


Question:
How can I set mMyParameter1 to the value in the config file within the framework above?

I believe the parsing needs to be done in the constructors of GenericBase or ParameterSet and the driving needs to be in CreateFloat. The inName is important here because it defines the name to lookup when reading the cfg. Therefore I can only assume that the file is opened and parsed in GenericBase. But if that's the case, how can I get the information into the CreateFloat() function?

MyParameter1 is not an exclusive name and it's set to different values for different modules in this cfg.

Edit: F5 F5 F5 F5 F5 F5 F5
Last edited on
Ideas?
My current thought is to implement ParameterSet like so. The only trick is that I need to ensure that I define each module in the correct order so that they don't read the wrong parameters.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
template <class T>
class Parameter
{
public:
    T m_value;
}

class FloatParameter : Parameter<float>
{
public:
    FloatParameter(float inValue) : m_value(inValue);
}

class ParameterSet
{
    static int m_occurances;
    static vector<Parameter*> m_parameterList;
public:
    ParameterSet() 
    {
        m_occurances++;
        if (m_occurances == 1) 
            parsecfg(); // adds all parameters from the file to m_parameterList;
    }

    CreateFloat(float* pParam, std::string name)
    {
        *pParam = first instance of MyParameter1 in m_parameterList;
        remove that instance from m_parameterList
    }
}
Topic archived. No new replies allowed.