コード例 #1
0
void PrinterPlain::beginStructure(const PVStructure& pv)
{
    indentN(S(), ilvl);
    S() << pv.getStructure()->getID() << " " << pv.getFieldName();
    S() << std::endl;
    ilvl++;
}
コード例 #2
0
ファイル: PVField.cpp プロジェクト: mrkraimer/pvDataCPP
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");
        }
    }
}
コード例 #3
0
ファイル: PVField.cpp プロジェクト: mrkraimer/pvDataCPP
void PVField::copyUnchecked(const PVField& from)
{
    switch(getField()->getType())
    {
    case scalar:
        {
             const PVScalar* fromS = static_cast<const PVScalar*>(&from);
             PVScalar* toS = static_cast<PVScalar*>(this);
             toS->copyUnchecked(*fromS);
             break;
        }
    case scalarArray:
        {
             const PVScalarArray* fromS = static_cast<const PVScalarArray*>(&from);
             PVScalarArray* toS = static_cast<PVScalarArray*>(this);
             toS->copyUnchecked(*fromS);
             break;
        }
    case structure:
        {
             const PVStructure* fromS = static_cast<const PVStructure*>(&from);
             PVStructure* toS = static_cast<PVStructure*>(this);
             toS->copyUnchecked(*fromS);
             break;
        }
    case structureArray:
        {
             const PVStructureArray* fromS = static_cast<const PVStructureArray*>(&from);
             PVStructureArray* toS = static_cast<PVStructureArray*>(this);
             toS->copyUnchecked(*fromS);
             break;
        }
    case union_:
        {
             const PVUnion* fromS = static_cast<const PVUnion*>(&from);
             PVUnion* toS = static_cast<PVUnion*>(this);
             toS->copyUnchecked(*fromS);
             break;
        }
    case unionArray:
        {
             const PVUnionArray* fromS = static_cast<const PVUnionArray*>(&from);
             PVUnionArray* toS = static_cast<PVUnionArray*>(this);
             toS->copyUnchecked(*fromS);
             break;
        }
    default:
        {
            throw std::logic_error("PVField::copy unknown type");
        }
    }
}
コード例 #4
0
void ValueBuilder::_add(const std::string& name, const PVStructure& V)
{
    StructureConstPtr T(V.getStructure());
    ValueBuilder& self = addNested(name, structure, T->getID());
    child_struct::fillStruct(self, V);
    self.endNested();
}
コード例 #5
0
PVFieldPtr  PVStructure::getSubField(size_t fieldOffset) const
{
    if(fieldOffset<=getFieldOffset()) {
        return nullPVField;
    }
    if(fieldOffset>getNextFieldOffset()) return nullPVField;
    size_t numFields = pvFields.size();
    for(size_t i=0; i<numFields; i++) {
        PVFieldPtr pvField  = pvFields[i];
        if(pvField->getFieldOffset()==fieldOffset) return pvFields[i];
        if(pvField->getNextFieldOffset()<=fieldOffset) continue;
        if(pvField->getField()->getType()==structure) {
            PVStructure *pvStructure = static_cast<PVStructure *>(pvField.get());
            return pvStructure->getSubField(fieldOffset);
        }
    }
    throw std::logic_error("PVStructure.getSubField: Logic error");
}
コード例 #6
0
ファイル: pvCopy.cpp プロジェクト: epics-base/pvIOCCPP
std::tr1::shared_ptr<PVCopy> PVCopy::create(
    PVRecord &pvRecord, PVStructure &request, String structureName)
{
    PVStructure *pvRequest = &request;
    if(structureName.length()>0) {
        if(pvRequest->getStructure()->getNumberFields()>0) {
            PVStructure *pvStructure
                 = pvRequest->getStructureField(structureName);
            if(pvStructure==0) return std::tr1::shared_ptr<PVCopy>();
            pvRequest = pvStructure;
        }
    }
    std::tr1::shared_ptr<PVCopy> pvCopy =
        std::tr1::shared_ptr<PVCopy>(new PVCopy(pvRecord));
    PVStructure *pvStruct = pvRequest;
    if(pvRequest->getSubField("field")!=0) {
        pvStruct = pvRequest->getStructureField("field");
    }
    pvCopy->init(*pvStruct);
    return pvCopy;
}
コード例 #7
0
bool PVTimeStamp::attach(PVFieldPtr const & pvField)
{
    if(pvField->getField()->getType()!=structure) return false;
    PVStructurePtr xxx = static_pointer_cast<PVStructure>(pvField);
    PVStructure* pvStructure = xxx.get();
    while(true) {
        PVLongPtr pvLong = pvStructure->getLongField("secondsPastEpoch");
        if(pvLong.get()!=NULL) {
            pvSecs = pvLong;
            pvNano = pvStructure->getIntField("nanoseconds");
            pvUserTag = pvStructure->getIntField("userTag");
        }
        if(pvSecs.get()!=NULL
        && pvNano.get()!=NULL
        && pvUserTag.get()!=NULL) return true;
        detach();
        // look up the tree for a timeSyamp
        pvStructure = pvStructure->getParent();
        if(pvStructure==NULL) break;
    }
    return false;
}
コード例 #8
0
void PVStructure::fixParentStructure()
{
    PVStructure *parent = getParent();
    if(parent==NULL) return;
    StructureConstPtr parentStructure = parent->structurePtr;
    String fieldName = getFieldName();
    size_t index = parentStructure->getFieldIndex(fieldName);
    StringArray const &fieldNames = parentStructure->getFieldNames();
    size_t num = fieldNames.size();
    FieldConstPtrArray fields(num);
    FieldConstPtrArray const & oldFields = parentStructure->getFields();
    for(size_t i=0; i< num; i++) {
        if(i==index) {
            fields[i] = structurePtr;
        } else {
            fields[i] = oldFields[i];
        }
    }
    FieldConstPtr field = getFieldCreate()->createStructure(
        parentStructure->getID(),fieldNames,fields);
    parent->replaceField(field);
    parent->fixParentStructure();
}
コード例 #9
0
void PVStructure::serialize(ByteBuffer *pbuffer,
        SerializableControl *pflusher, BitSet *pbitSet) const {
	PVStructure* nonConstThis = const_cast<PVStructure*>(this);
    size_t numberFields = nonConstThis->getNumberFields();
    size_t offset = nonConstThis->getFieldOffset();
    int32 next = pbitSet->nextSetBit(offset);

    // no more changes or no changes in this structure
    if(next<0||next>=static_cast<int32>(offset+numberFields)) return;

    // entire structure
    if(static_cast<int32>(offset)==next) {
        serialize(pbuffer, pflusher);
        return;
    }

    size_t fieldsSize = pvFields.size();
    for(size_t i = 0; i<fieldsSize; i++) {
        PVFieldPtr pvField = pvFields[i];
        offset = pvField->getFieldOffset();
        int32 inumberFields = pvField->getNumberFields();
        next = pbitSet->nextSetBit(offset);

        // no more changes
        if(next<0) return;
        //  no change in this pvField
        if(next>=static_cast<int32>(offset+inumberFields)) continue;

        // serialize field or fields
        if(inumberFields==1) {
            pvField->serialize(pbuffer, pflusher);
        } else {
            PVStructurePtr pvStructure = std::tr1::static_pointer_cast<PVStructure>(pvField);
            pvStructure->serialize(pbuffer, pflusher, pbitSet);
       }
    }
}
コード例 #10
0
ValueBuilder::ValueBuilder(const PVStructure& clone) :parent(0)
{
    StructureConstPtr ctype(clone.getStructure());
    id = ctype->getID();
    child_struct::fillStruct(*this, clone);
}