(someArray, sizeof(someArray)) in constructor

Status
Not open for further replies.

Dozer

Member
Hi all,

Today I made a class which does this:

Code:
typedef const double ScaleMap [][2];

ScaleMap myMap = {
  {0.0, 120}, //left column is input values. Right column is output values.
  {0.34, 90},
  {1.0, 45}
  // indefinitely many pairs, but probably less than 20.
};

SimServo::SimServo (..., ScaleMap map, size_t sizeof_map);

SimServo myServo (... , myMap, sizeof(myMap));

The class converts an input (an X-Plane dataref) into an output by interpolating it through the ScaleMap, then writes the result to a servo. The constructor takes a pointer to ScaleMap and the size of ScaleMap.

I'm writing this for reluctant programmers, X-Plane users who want to build custom hardware without learning much C++. So I'm trying to remove as many points of failure as possible. Is there a sensible way to pass this input-output map to my class without using a 'pointer, sizeof(pointer)' syntax?

I'm looking perhaps at a #define, or some other way of storing the map. It is very important that the map and constructor are written sequentially in the same place in the source file (a lot of push_back(input, output) statements in setup() would not do!), as the resulting source code needs to be as readable as possible.

Cheers,
Jack
 
Status
Not open for further replies.
Back
Top