#include "datapoint_value.h"

void
GCDatapointValue_setQualityGood(GCDatapointValue value)
{
    value->quality &= !GC_DATAPOINT_QUALITY_FIRST_TWO_BITS_MASK;
}

void
GCDatapointValue_setQualityInvalid(GCDatapointValue value)
{
    value->quality &= !GC_DATAPOINT_QUALITY_FIRST_TWO_BITS_MASK;
    value->quality |= GC_DATAPOINT_QUALITY_INVALID;
}

void
GCDatapointValue_setQualityQuestionable(GCDatapointValue value)
{
    value->quality &= !GC_DATAPOINT_QUALITY_FIRST_TWO_BITS_MASK;
    value->quality |= GC_DATAPOINT_QUALITY_QUESTIONABLE;
}

void
GCDatapointValue_setQualityOverflow(GCDatapointValue value)
{
    value->quality |= GC_DATAPOINT_QUALITY_OVERFLOW;
}

void
GCDatapointValue_setQualityOutOfRange(GCDatapointValue value)
{
    value->quality |= GC_DATAPOINT_QUALITY_OUT_OF_RANGE;
}

void
GCDatapointValue_setQualityBadReference(GCDatapointValue value)
{
    value->quality |= GC_DATAPOINT_QUALITY_BAD_REFERENCE;
}

void
GCDatapointValue_setQualityOscillatory(GCDatapointValue value)
{
    value->quality |= GC_DATAPOINT_QUALITY_OSCILLATORY;
}

void
GCDatapointValue_setQualityFailure(GCDatapointValue value)
{
    value->quality |= GC_DATAPOINT_QUALITY_FAILURE;
}

void
GCDatapointValue_setQualityOldData(GCDatapointValue value)
{
    value->quality |= GC_DATAPOINT_QUALITY_OLD_DATA;
}

void
GCDatapointValue_setQualityInconsistent(GCDatapointValue value)
{
    value->quality |= GC_DATAPOINT_QUALITY_INCONSISTENT;
}

void
GCDatapointValue_setQualityInaccurate(GCDatapointValue value)
{
    value->quality |= GC_DATAPOINT_QUALITY_INACCURATE;
}

void
GCDatapointValue_setQualitySourceProcessing(GCDatapointValue value)
{
    value->quality |= GC_DATAPOINT_QUALITY_SOURCE;
}

void
GCDatapointValue_setQualityTest(GCDatapointValue value)
{
    value->quality |= GC_DATAPOINT_QUALITY_TEST;
}

void
GCDatapointValue_setQualityOperatorBlocked(GCDatapointValue value)
{
    value->quality |= GC_DATAPOINT_QUALITY_OPERATOR_BLOCKED;
}

bool
GCDatapointValue_isQualityGood(GCDatapointValue value)
{
    return (value->quality & GC_DATAPOINT_QUALITY_FIRST_TWO_BITS_MASK) == 0;
}

bool
GCDatapointValue_isQualityInvalid(GCDatapointValue value)
{
    return (value->quality & GC_DATAPOINT_QUALITY_FIRST_TWO_BITS_MASK) == GC_DATAPOINT_QUALITY_INVALID;
}

bool
GCDatapointValue_isQualityQuestionable(GCDatapointValue value)
{
    return (value->quality & GC_DATAPOINT_QUALITY_FIRST_TWO_BITS_MASK) == GC_DATAPOINT_QUALITY_QUESTIONABLE;
}

bool
GCDatapointValue_isQualityOverflow(GCDatapointValue value)
{
    return (value->quality & GC_DATAPOINT_QUALITY_OVERFLOW) != 0;
}

bool
GCDatapointValue_isQualityOutOfRange(GCDatapointValue value)
{
    return (value->quality & GC_DATAPOINT_QUALITY_OUT_OF_RANGE) != 0;
}

bool
GCDatapointValue_isQualityBadReference(GCDatapointValue value)
{
    return (value->quality & GC_DATAPOINT_QUALITY_BAD_REFERENCE) != 0;
}

bool
GCDatapointValue_isQualityOscillatory(GCDatapointValue value)
{
    return (value->quality & GC_DATAPOINT_QUALITY_OSCILLATORY) != 0;
}

bool
GCDatapointValue_isQualityFailure(GCDatapointValue value)
{
    return (value->quality & GC_DATAPOINT_QUALITY_FAILURE) != 0;
}

bool
GCDatapointValue_isQualityOldData(GCDatapointValue value)
{
    return (value->quality & GC_DATAPOINT_QUALITY_OLD_DATA) != 0;
}

bool
GCDatapointValue_isQualityInconsistent(GCDatapointValue value)
{
    return (value->quality & GC_DATAPOINT_QUALITY_INCONSISTENT) != 0;
}

bool
GCDatapointValue_isQualityInaccurate(GCDatapointValue value)
{
    return (value->quality & GC_DATAPOINT_QUALITY_INACCURATE) != 0;
}

bool
GCDatapointValue_isQualitySourceProcessing(GCDatapointValue value)
{
    return (value->quality & GC_DATAPOINT_QUALITY_SOURCE) != 0;
}

bool
GCDatapointValue_isQualityTest(GCDatapointValue value)
{
    return (value->quality & GC_DATAPOINT_QUALITY_TEST) != 0;
}

bool
GCDatapointValue_isQualityOperatorBlocked(GCDatapointValue value)
{
    return (value->quality & GC_DATAPOINT_QUALITY_OPERATOR_BLOCKED) != 0;
}
