I am trying to perform integrity checks on input data before the core of my algorithm gets to work by making sure inputs are neither NAN or out of a reasonable set of bounds.I have defined the following class for a flag to indicate the status of a particular input:class IM_flag{private:    // Flag Status    //------------    //  Convention (regular):    //       0 = no latched faults and currently OK (or unchecked)    //      -1 = input is currently NAN and has no latched faults    //      -2 = input has latched a NAN condition since last clear but is currently OK    //      -3 = input has latched a NAN and is currently NAN    //      +1 = input is currently OOB and has no latched faults    //      +2 = input has latched an OOB condition since last clear but is currently OK    //      +3 = input has latched an OOB and is currently OOB    //    //      +7 = input has latched a NAN and is currently OOB or has latched an OOB and is currently NAN    //      +8 = input has latched both NAN and OOB conditions but is currently OK    //      +9 = input has latched both NAN and OOB conditions and is currently NAN or OOB    //    //  Convention (special cases):    //   +/- 1x = mismatched vs. a value expected to be the same (offsets regular status code by 10)    int     status;    // Flag Internals    //---------------    int     NANcount;           // number of NAN since last clear    int     OOBhighCount;       // number of high limit exceedances since last clear    int     OOBlowCount;        // number of low limit exceedances since last clear    int     NANisLatched;       // 0=NAN latch limit not exceeded; 1=NAN latch limit exceeded    int     OOBisLatched;       // 0=OOB latch limit not exceeded; 1=OOB latch limit exceeded    int     NANlatchLimit;      // latch NAN error once limit exceeded    int     OOBlatchLimit;      // latch OOB error once limit exceeded    int     OOBclampMode;       // 0=report OOB only; 1=report OOB and coerce to upper/lower limitpublic:    // Constructors    //-------------    IM_flag()                                   : status(0), NANcount(0), OOBhighCount(0), OOBlowCount(0), NANisLatched(0), OOBisLatched(0),                                                    NANlatchLimit(2), OOBlatchLimit(2), OOBclampMode(0) {}    IM_flag(int clamp)                          : status(0), NANcount(0), OOBhighCount(0), OOBlowCount(0), NANisLatched(0), OOBisLatched(0),                                                    NANlatchLimit(2), OOBlatchLimit(2), OOBclampMode(clamp) {}    IM_flag(int clamp, int NANlim, int OOBlim)  : status(0), NANcount(0), OOBhighCount(0), OOBlowCount(0),  NANisLatched(0), OOBisLatched(0),                                                    NANlatchLimit(NANlim), OOBlatchLimit(OOBlim), OOBclampMode(clamp) {}    // Operators    //----------    operator    int& ()                     { return status; }    operator    int const& ()               { return status; }    // Utility Functions    //------------------    int     getStatus()                     { return status; }    void    clear()                         { status = NANcount = OOBhighCount = OOBlowCount = NANisLatched = OOBisLatched = 0; }    int     getNANcount()                   { return NANcount; }    int     getOOBhighCount()               { return OOBhighCount; }    int     getOOBlowCount()                { return OOBlowCount; }    int     getNANlatchLimit()              { return NANlatchLimit; }    int     getOOBlatchLimit()              { return OOBlatchLimit; }    int     getOOBclampMode()               { return OOBclampMode; }    int     setNANlatchLimit(int newLim)    { int prev = NANlatchLimit; NANlatchLimit = newLim; return prev; }    int     setOOBlatchLimit(int newLim)    { int prev = OOBlatchLimit; OOBlatchLimit = newLim; return prev; }    int     setOOBclampMode(int newMode)    { int prev = OOBclampMode;  OOBclampMode = newMode; return prev; }    // Checking Functions    //-------------------    int check(double *input, double lowLim = DOUBLE_NEG_INF, double highLim = DOUBLE_POS_INF)    {        int badNow = 0;                     // local variable for tracking whether the input is currently bad        // Check the input first        if      (ISNAN(*input))             // check for NAN first        {            NANcount++;            badNow = -1;        }        else if (*input>highLim)            // check high limit exccedance next        {            OOBhighCount++;            badNow = 1;            if  (1==OOBclampMode)   *input = highLim;        }        else if (*input<lowLim)             // check low limit exccedance last        {            OOBlowCount++;            badNow = 1;            if  (1==OOBclampMode)   *input = lowLim;        }        // Check latch limits        if ((!NANisLatched) && (NANcount>=NANlatchLimit))            NANisLatched = 1;        if ((!OOBisLatched) && ((OOBhighCount+OOBlowCount)>=OOBlatchLimit))            OOBisLatched = 1;        // Set status flag        if      ((1==NANisLatched) && (1==OOBisLatched) && (0!=badNow))            status = 9;                     //  +9 = input has latched both NAN and OOB conditions and is currently NAN or OOB        else if ((1==NANisLatched) && (1==OOBisLatched) && (0==badNow))            status = 8;                     //  +8 = input has latched both NAN and OOB conditions but is currently OK        else if (((1==NANisLatched) && (0==OOBisLatched) && (1==badNow)) || ((0==NANisLatched) && (1==OOBisLatched) && (-1==badNow)))            status = 7;                     //  +7 = input has latched a NAN and is currently OOB or has latched an OOB and is currently NAN        else if ((0==NANisLatched) && (1==OOBisLatched) && (1==badNow))            status = 3;                     //  +3 = input has latched an OOB and is currently OOB        else if ((0==NANisLatched) && (1==OOBisLatched) && (0==badNow))            status = 2;                     //  +2 = input has latched an OOB condition since last clear but is currently OK        else if ((0==NANisLatched) && (0==OOBisLatched) && (1==badNow))            status = 1;                     //  +1 = input is currently OOB and has no latched faults        else if ((1==NANisLatched) && (0==OOBisLatched) && (-1==badNow))            status = -3;                    //  -3 = input has latched a NAN and is currently NAN        else if ((1==NANisLatched) && (0==OOBisLatched) && (0==badNow))            status = -2;                    //  -2 = input has latched a NAN condition since last clear but is currently OK        else if ((0==NANisLatched) && (0==OOBisLatched) && (-1==badNow))            status = -1;                    //  -1 = input is currently NAN and has no latched faults        else if ((0==NANisLatched) && (0==OOBisLatched) && (0==badNow))            status = 0;                     //   0 = no latched faults and currently OK        else                                // shouldn't be possible to get to this else, but include it to identify problems            status = -99999;        return status;    }    int checkMismatch(double *input, double *expectedMatch, double tol = DOUBLE_TOL)    {        // Test equality within tolerance and offset status if unequal        if (abs(*input-*expectedMatch)>tol)        {            // +/- 1x = mismatched vs. a value expected to be the same (offsets regular status code by 10)            if (status<0)                status -= 10;               // make a negative error code more negative by 10            else                status += 10;               // make a zero or positive error code more positive by 10                       }        return status;    }};Then I defined another class to contain all the flags and provide a couple outputs which summarize the flags:class IM_InputsCheck{public:    // Summary status variables    //-------------------------    int     errorLatchedCount;              // counter for inputs currently latch for NAN and/or OOB    int     errorActiveCount;               // counter for inputs currently NAN or OOB    int     errorMismatchCount;             // counter for inputs currently mismatched    // Array of flags    //---------------    IM_flag flags[NUMEL_InputList];    // Constructors    //-------------    IMstruct_InputsCheck()                                  : errorLatchedCount(0), errorActiveCount(0), errorMismatchCount(0) {}    IMstruct_InputsCheck(int clamp)                         : errorLatchedCount(0), errorActiveCount(0), errorMismatchCount(0)    {        for (int ii=0; ii<NUMEL_InputList; ii++)            flags[ii] = IM_flag(clamp);    }    IMstruct_InputsCheck(int clamp, int NANlim, int OOBlim) : errorLatchedCount(0), errorActiveCount(0), errorMismatchCount(0)    {        for (int ii=0; ii<NUMEL_InputList; ii++)            flags[ii] = IM_flag(clamp,NANlim,OOBlim);    }    // Utility Functions    //------------------    void summarize()    {        // Reset count of active, latched, and mismatch errors in inputs        errorActiveCount = errorLatchedCount = errorMismatchCount = 0;        // Loop through all inputs        for (int ii=0, status=0; ii<NUMEL_InputList; ii++)        {            // get current status            status = flags[ii].getStatus();            // increment mismatched error counter if appropriate            if (abs(status)>9)                errorMismatchCount++;            // get just the core status now, dropping off the 10s place if it was there, and not differentiating between NAN and OOB            status = (abs(status)%10);            // increment active error counter if appropriate            if ((1==status) || (3==status) || (7==status) || (9==status))                errorActiveCount++;            // increment latched error counter if appropriate            if (status>=2)                errorLatchedCount++;        }    }    void setAllNANlatchLimit(int newLim)    { for (int ii=0; ii<NUMEL_InputList; ii++) flags[ii].setNANlatchLimit(newLim); }    void setAllOOBlatchLimit(int newLim)    { for (int ii=0; ii<NUMEL_InputList; ii++) flags[ii].setOOBlatchLimit(newLim); }    void setAllOOBclampMode(int newMode)    { for (int ii=0; ii<NUMEL_InputList; ii++) flags[ii].setOOBclampMode(newMode); }    void clearAllFlags()                    { for (int ii=0; ii<NUMEL_InputList; ii++) flags[ii].clear(); }};I was anticipating using an enumeration as follows to size and index my array of flags:enum InputList{    Lat,    Lon,    Alt,    VelN,    VelE,    VelD,    /* ... about another 70 items ... */    SysTime,    NUMEL_InputList};Then I do checks on individual inputs like this:inputCheckStruct->flags[Alt].check(Input_Altitude,-2000.,100000.);In asking a question on Stack Overflow a concern was raised over the use of enum at all. So...is this a good approach or is there a better way to accomplish what I'm trying to do? My main question is in regards to defining an enum with list of meaningful names, using the NUMEL_InputList dummy entry to get the size of array for the IM_InputsCheck class, indexing with the enum items, etc. but I'll also welcome other relevant suggestions. Please forgive me...I'm an engineer who needs to write code, not a real programmer.
Input data integrity checking
c++;enum