当前位置: 首页>>代码示例>>C++>>正文


C++ PVDataCreatePtr::createPVScalar方法代码示例

本文整理汇总了C++中PVDataCreatePtr::createPVScalar方法的典型用法代码示例。如果您正苦于以下问题:C++ PVDataCreatePtr::createPVScalar方法的具体用法?C++ PVDataCreatePtr::createPVScalar怎么用?C++ PVDataCreatePtr::createPVScalar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PVDataCreatePtr的用法示例。


在下文中一共展示了PVDataCreatePtr::createPVScalar方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setValue

static void setValue(PVUnionPtr const &pvUnion, double value)
{
    UnionConstPtr u = pvUnion->getUnion();
    FieldConstPtr field = u->getField(0);
    Type type = field->getType();
    if(type==scalar) {
         ScalarConstPtr scalar = static_pointer_cast<const Scalar>(field);
         ScalarType scalarType = scalar->getScalarType();
         if(scalarType==pvDouble) {
              PVDoublePtr pvValue = static_pointer_cast<PVDouble>(
                   pvDataCreate->createPVScalar(pvDouble));
              pvValue->put(value);
              pvUnion->set(0,pvValue);
              return;
         }
         if(scalarType==pvString) {
              PVStringPtr pvValue = static_pointer_cast<PVString>(
                   pvDataCreate->createPVScalar(pvString));
              stringstream ss;
              ss << "value" << value;
              pvValue->put(ss.str());
              pvUnion->set(0,pvValue);
              return;
         }
         throw std::runtime_error("only pvDouble and pvString are supported");
    }
    if(type==scalarArray) {
         ScalarArrayConstPtr scalarArray = static_pointer_cast<const ScalarArray>(field);
         ScalarType scalarType = scalarArray->getElementType();
         if(scalarType==pvDouble) {
              size_t num = 5;
              PVDoubleArrayPtr pvValue = static_pointer_cast<PVDoubleArray>(
                   pvDataCreate->createPVScalarArray(pvDouble));
              shared_vector<double> data(num);
              for(size_t i=0; i<num; ++i) data[i] = value +i;
              pvValue->replace(freeze(data));
              pvUnion->set(0,pvValue);
              return;
         }
         if(scalarType==pvString) {
              size_t num = 5;
              PVStringArrayPtr pvValue = static_pointer_cast<PVStringArray>(
                   pvDataCreate->createPVScalarArray(pvString));
              shared_vector<string> data(num);
              for(size_t i=0; i<num; ++i) {
                  stringstream ss;
                  ss << "value" << value << i;
                  data[i] = ss.str();
              }
              pvValue->replace(freeze(data));
              pvUnion->set(0,pvValue);
              return;
         }
         throw std::runtime_error("only pvDouble and pvString are supported");
    }
    throw std::runtime_error("only scalar and scalarArray fields are supported");
}
开发者ID:anjohnson,项目名称:exampleCPP,代码行数:57,代码来源:examplePvaClientNTMulti.cpp

示例2: testPVScalarCommon

static void testPVScalarCommon(string /*fieldName*/,ScalarType stype)
{
    PVScalarPtr pvScalar = pvDataCreate->createPVScalar(stype);
    if(stype==pvBoolean) {
        convert->fromString(pvScalar,string("true"));
    } else {
        convert->fromString(pvScalar,string("10"));
    }
}
开发者ID:mrkraimer,项目名称:pvDataCPP,代码行数:9,代码来源:testPVData.cpp

示例3: testCreatePVStructureWithInvalidName

static void testCreatePVStructureWithInvalidName()
{
    testDiag("testCreatePVStructureWithInvalidName");
    StringArray fieldNames;
    fieldNames.push_back("ok");
    fieldNames.push_back("this.is-wrong");
    PVFieldPtrArray pvFields;
    pvFields.push_back(pvDataCreate->createPVScalar(pvString));
    pvFields.push_back(pvDataCreate->createPVScalar(pvInt));
    try{
        PVStructurePtr pvParent = pvDataCreate->createPVStructure(
            fieldNames,pvFields);
        testFail("Creation of invalid field name '%s' was allowed", fieldNames[1].c_str());
    } catch(std::invalid_argument& e) {
        testDiag("Exception: \"%s\"", e.what());
        testPass("Creation of invalid field name '%s' fails as expected", fieldNames[1].c_str());
    }
}
开发者ID:mrkraimer,项目名称:pvDataCPP,代码行数:18,代码来源:testPVData.cpp

示例4: testCreatePVStructure

static void testCreatePVStructure()
{
    PVStructurePtr pv0 = standardPVField->scalar(
         pvDouble,alarmTimeStampValueAlarm);
    PVScalarPtr pv1 = pvDataCreate->createPVScalar(pvString);
    PVFieldPtrArray pvFields;
    StringArray fieldNames;
    pvFields.reserve(2);
    fieldNames.reserve(2);
    fieldNames.push_back("value");
    fieldNames.push_back("extra");
    pvFields.push_back(pv0);
    pvFields.push_back(pv1);
    PVStructurePtr pvParent = pvDataCreate->createPVStructure(
        fieldNames,pvFields);
        
    std::cout << "testCreatePVStructure PASSED" << std::endl;
}
开发者ID:mrkraimer,项目名称:pvDataCPP,代码行数:18,代码来源:testPVData.cpp

示例5: testConvertScalar

static void testConvertScalar(FILE *fd) {
    PVScalarPtr pvBytePtr = pvDataCreate->createPVScalar(pvByte);
    PVScalarPtr pvUBytePtr = pvDataCreate->createPVScalar(pvUByte);
    PVScalarPtr pvShortPtr = pvDataCreate->createPVScalar(pvShort);
    PVScalarPtr pvUShortPtr = pvDataCreate->createPVScalar(pvUShort);
    PVScalarPtr pvIntPtr = pvDataCreate->createPVScalar(pvInt);
    PVScalarPtr pvUIntPtr = pvDataCreate->createPVScalar(pvUInt);
    PVScalarPtr pvLongPtr = pvDataCreate->createPVScalar(pvLong);
    PVScalarPtr pvULongPtr = pvDataCreate->createPVScalar(pvULong);
    PVScalarPtr pvFloatPtr = pvDataCreate->createPVScalar(pvFloat);
    PVScalarPtr pvDoublePtr = pvDataCreate->createPVScalar(pvDouble);

    fprintf(fd,"testConvertScalar\n");
    if(debug) fprintf(fd,"\nfromByte\n");
    int8 bval = 127;
    for(int i=0; i<3; i++) {
        convert->fromByte(pvBytePtr, bval);
        builder.clear(); pvBytePtr->toString(&builder);
        if(debug) fprintf(fd,"byte %s\n",builder.c_str());
        convert->fromByte(pvUBytePtr, bval);
        builder.clear(); pvUBytePtr->toString(&builder);
        if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
        convert->fromByte(pvShortPtr, bval);
        builder.clear(); pvShortPtr->toString(&builder);
        if(debug) fprintf(fd,"short %s\n",builder.c_str());
        convert->fromByte(pvUShortPtr, bval);
        builder.clear(); pvUShortPtr->toString(&builder);
        if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
        convert->fromByte(pvIntPtr, bval);
        builder.clear(); pvIntPtr->toString(&builder);
        if(debug) fprintf(fd,"int %s\n",builder.c_str());
        convert->fromByte(pvUIntPtr, bval);
        builder.clear(); pvUIntPtr->toString(&builder);
        if(debug) fprintf(fd,"uint %s\n",builder.c_str());
        convert->fromByte(pvLongPtr, bval);
        builder.clear(); pvLongPtr->toString(&builder);
        if(debug) fprintf(fd,"long %s\n",builder.c_str());
        convert->fromByte(pvULongPtr, bval);
        builder.clear(); pvULongPtr->toString(&builder);
        if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
        convert->fromByte(pvFloatPtr, bval);
        builder.clear(); pvFloatPtr->toString(&builder);
        if(debug) fprintf(fd,"float %s\n",builder.c_str());
        convert->fromByte(pvDoublePtr, bval);
        builder.clear(); pvDoublePtr->toString(&builder);
        if(debug) fprintf(fd,"double %s\n",builder.c_str());
        convert->copyScalar(pvUBytePtr, pvFloatPtr);
        builder.clear(); pvFloatPtr->toString(&builder);
        if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
        convert->copyScalar(pvUBytePtr, pvDoublePtr);
        builder.clear(); pvDoublePtr->toString(&builder);
        if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
        bval++;
    }
    fprintf(fd,"fromByte PASSED\n");

    if(debug) fprintf(fd,"\nfromShort\n");
    int16 sval = 0x7fff;
    for(int i=0; i<3; i++) {
        convert->fromShort(pvBytePtr, sval);
        builder.clear(); pvBytePtr->toString(&builder);
        if(debug) fprintf(fd,"byte %s\n",builder.c_str());
        convert->fromShort(pvUBytePtr, sval);
        builder.clear(); pvUBytePtr->toString(&builder);
        if(debug) fprintf(fd,"ubyte %s\n",builder.c_str());
        convert->fromShort(pvShortPtr, sval);
        builder.clear(); pvShortPtr->toString(&builder);
        if(debug) fprintf(fd,"short %s\n",builder.c_str());
        convert->fromShort(pvUShortPtr, sval);
        builder.clear(); pvUShortPtr->toString(&builder);
        if(debug) fprintf(fd,"ushort %s\n",builder.c_str());
        convert->fromShort(pvIntPtr, sval);
        builder.clear(); pvIntPtr->toString(&builder);
        if(debug) fprintf(fd,"int %s\n",builder.c_str());
        convert->fromShort(pvUIntPtr, sval);
        builder.clear(); pvUIntPtr->toString(&builder);
        if(debug) fprintf(fd,"uint %s\n",builder.c_str());
        convert->fromShort(pvLongPtr, sval);
        builder.clear(); pvLongPtr->toString(&builder);
        if(debug) fprintf(fd,"long %s\n",builder.c_str());
        convert->fromShort(pvULongPtr, sval);
        builder.clear(); pvULongPtr->toString(&builder);
        if(debug) fprintf(fd,"ulong %s\n",builder.c_str());
        convert->fromShort(pvFloatPtr, sval);
        builder.clear(); pvFloatPtr->toString(&builder);
        if(debug) fprintf(fd,"float %s\n",builder.c_str());
        convert->fromShort(pvDoublePtr, sval);
        builder.clear(); pvDoublePtr->toString(&builder);
        if(debug) fprintf(fd,"double %s\n",builder.c_str());
        convert->copyScalar(pvUShortPtr, pvFloatPtr);
        builder.clear(); pvFloatPtr->toString(&builder);
        if(debug) fprintf(fd,"float from unsigned %s\n",builder.c_str());
        convert->copyScalar(pvUShortPtr, pvDoublePtr);
        builder.clear(); pvDoublePtr->toString(&builder);
        if(debug) fprintf(fd,"double from unsigned %s\n",builder.c_str());
        sval++;
    }
    fprintf(fd,"fromShort PASSED\n");

    if(debug) fprintf(fd,"\nfromInt\n");
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


注:本文中的PVDataCreatePtr::createPVScalar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。