Ejemplo n.º 1
0
void PVField::computeOffset(const PVField   *  pvField,size_t offset) {
    size_t beginOffset = offset;
    size_t nextOffset = offset + 1;
    const PVStructure *pvStructure = static_cast<const PVStructure *>(pvField);
    const PVFieldPtrArray & pvFields = pvStructure->getPVFields();
    for(size_t i=0; i < pvStructure->getStructure()->getNumberFields(); i++) {
        offset = nextOffset;
        PVField *pvSubField = pvFields[i].get();
        FieldConstPtr field = pvSubField->getField();
        switch(field->getType()) {
            case scalar:
            case scalarArray:
            case structureArray:
            case union_:
            case unionArray: {
                nextOffset++;
                pvSubField->fieldOffset = offset;
                pvSubField->nextFieldOffset = nextOffset;
                break;
            }
            case structure: {
                pvSubField->computeOffset(pvSubField,offset);
                nextOffset = pvSubField->getNextFieldOffset();
            }
        }
    }
    PVField *xxx = const_cast<PVField *>(pvField);
    xxx->fieldOffset = beginOffset;
    xxx->nextFieldOffset = nextOffset;
}
Ejemplo n.º 2
0
void PVField::copy(const PVField& from)
{
    if(isImmutable())
        throw std::invalid_argument("destination is immutable");

    if (getField()->getType() != from.getField()->getType())
        throw std::invalid_argument("field types do not match");

    switch(getField()->getType())
    {
    case scalar:
        {
             const PVScalar* fromS = static_cast<const PVScalar*>(&from);
             PVScalar* toS = static_cast<PVScalar*>(this);
             toS->copy(*fromS);
             break;
        }
    case scalarArray:
        {
             const PVScalarArray* fromS = static_cast<const PVScalarArray*>(&from);
             PVScalarArray* toS = static_cast<PVScalarArray*>(this);
             toS->copy(*fromS);
             break;
        }
    case structure:
        {
             const PVStructure* fromS = static_cast<const PVStructure*>(&from);
             PVStructure* toS = static_cast<PVStructure*>(this);
             toS->copy(*fromS);
             break;
        }
    case structureArray:
        {
             const PVStructureArray* fromS = static_cast<const PVStructureArray*>(&from);
             PVStructureArray* toS = static_cast<PVStructureArray*>(this);
             toS->copy(*fromS);
             break;
        }
    case union_:
        {
             const PVUnion* fromS = static_cast<const PVUnion*>(&from);
             PVUnion* toS = static_cast<PVUnion*>(this);
             toS->copy(*fromS);
             break;
        }
    case unionArray:
        {
             const PVUnionArray* fromS = static_cast<const PVUnionArray*>(&from);
             PVUnionArray* toS = static_cast<PVUnionArray*>(this);
             toS->copy(*fromS);
             break;
        }
    default:
        {
            throw std::logic_error("PVField::copy unknown type");
        }
    }
}
Ejemplo n.º 3
0
bool operator==(const PVField& left, const PVField& right)
{
    if(&left == &right)
        return true;

    Type lht = left.getField()->getType();
    if(lht != right.getField()->getType())
        return false;

    switch(lht) {
    case scalar: return compareField(static_cast<const PVScalar*>(&left), static_cast<const PVScalar*>(&right));
    case scalarArray: return compareField(static_cast<const PVScalarArray*>(&left), static_cast<const PVScalarArray*>(&right));
    case structure: return compareField(static_cast<const PVStructure*>(&left), static_cast<const PVStructure*>(&right));
    case structureArray: return compareField(static_cast<const PVStructureArray*>(&left), static_cast<const PVStructureArray*>(&right));
    case union_: return compareField(static_cast<const PVUnion*>(&left), static_cast<const PVUnion*>(&right));
    case unionArray: return compareField(static_cast<const PVUnionArray*>(&left), static_cast<const PVUnionArray*>(&right));
    }
    throw std::logic_error("PVField with invalid type!");
}
Ejemplo n.º 4
0
void PVField::computeOffset(const PVField   *  pvField) {
    const PVStructure * pvTop = pvField->getParent();
    if(pvTop==NULL) {
        if(pvField->getField()->getType()!=structure) {
           PVField *xxx = const_cast<PVField *>(pvField);
           xxx->fieldOffset = 0;
           xxx->nextFieldOffset = 1;
           return;
        }
        pvTop = static_cast<const PVStructure *>(pvField);
    } else {
        while(pvTop->getParent()!=NULL) pvTop = pvTop->getParent();
    }
    size_t offset = 0;
    size_t nextOffset = 1;
    const PVFieldPtrArray & pvFields = pvTop->getPVFields();
    for(size_t i=0; i < pvTop->getStructure()->getNumberFields(); i++) {
        offset = nextOffset;
        PVField *pvField = pvFields[i].get();
        FieldConstPtr field = pvField->getField();
        switch(field->getType()) {
        case scalar:
        case scalarArray:
        case structureArray:
        case union_:
        case unionArray: {
            nextOffset++;
            pvField->fieldOffset = offset;
            pvField->nextFieldOffset = nextOffset;
            break;
        }
        case structure: {
            pvField->computeOffset(pvField,offset);
            nextOffset = pvField->getNextFieldOffset();
        }
        }
    }
    PVField *top = (PVField *)pvTop;
    PVField *xxx = const_cast<PVField *>(top);
    xxx->fieldOffset = 0;
    xxx->nextFieldOffset = nextOffset;
}