コード例 #1
0
ファイル: fieldcachefield.c プロジェクト: antmd/OpenMAMA
mama_status
mamaFieldCacheField_copy(const mamaFieldCacheField field, mamaFieldCacheField copy)
{
    if (!field || !copy)
    {
        return MAMA_STATUS_NULL_ARG;
    }
    if (field == copy)
    {
        return MAMA_STATUS_OK;
    }
    if (field->mFid != copy->mFid || field->mType != copy->mType)
    {
        return MAMA_STATUS_INVALID_ARG;
    }

    copy->mIsModified = field->mIsModified;
    copy->mPublish = field->mPublish;
    copy->mCheckModified = field->mCheckModified;
    copy->mDescriptor = field->mDescriptor;
    if (field->mName)
    {
        if (copy->mName)
        {
            free((void*)copy->mName);
        }
        copy->mName = strdup(field->mName);
    }
    switch (field->mType)
    {
        case MAMA_FIELD_TYPE_BOOL:
        {
            mama_bool_t result;
            mamaFieldCacheField_getBool(field, &result);
            mamaFieldCacheField_setBool(copy, result);
            break;
        }
        case MAMA_FIELD_TYPE_CHAR:
        {
            char value;
            mamaFieldCacheField_getChar(field, &value);
            mamaFieldCacheField_setChar(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_I8:
        {
            mama_i8_t value;
            mamaFieldCacheField_getI8(field, &value);
            mamaFieldCacheField_setI8(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_U8:
        {
            mama_u8_t value;
            mamaFieldCacheField_getU8(field, &value);
            mamaFieldCacheField_setU8(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_I16:
        {
            mama_i16_t value;
            mamaFieldCacheField_getI16(field, &value);
            mamaFieldCacheField_setI16(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_U16:
        {
            mama_u16_t value;
            mamaFieldCacheField_getU16(field, &value);
            mamaFieldCacheField_setU16(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_I32:
        {
            mama_i32_t value;
            mamaFieldCacheField_getI32(field, &value);
            mamaFieldCacheField_setI32(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_U32:
        {
            mama_u32_t value;
            mamaFieldCacheField_getU32(field, &value);
            mamaFieldCacheField_setU32(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_I64:
        {
            mama_i64_t value;
            mamaFieldCacheField_getI64(field, &value);
            mamaFieldCacheField_setI64(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_U64:
        {
            mama_u64_t value;
            mamaFieldCacheField_getU64(field, &value);
            mamaFieldCacheField_setU64(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_F32:
        {
            mama_f32_t value;
            mamaFieldCacheField_getF32(field, &value);
            mamaFieldCacheField_setF32(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_QUANTITY:
        case MAMA_FIELD_TYPE_F64:
        {
            mama_f64_t value;
            mamaFieldCacheField_getF64(field, &value);
            mamaFieldCacheField_setF64(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_STRING:
        {
            const char* value;
            mama_size_t len;
            mamaFieldCacheField_getString(field, &value, &len);
            mamaFieldCacheField_setString(copy, value, len);
            break;
        }
        case MAMA_FIELD_TYPE_PRICE:
        {
            mamaPrice value = NULL;
            const mamaPrice* pvalue = &value;
            mamaFieldCacheField_getPrice(field, pvalue);
            mamaFieldCacheField_setPrice(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_TIME:
        {
            mamaDateTime value = NULL;
            const mamaDateTime* pvalue = &value;
            mamaFieldCacheField_getDateTime(field, pvalue);
            mamaFieldCacheField_setDateTime(copy, value);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_BOOL:
        {
            const mama_bool_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getBoolVector(field, &values, &size);
            mamaFieldCacheField_setBoolVector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_CHAR:
        {
            const char* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getCharVector(field, &values, &size);
            mamaFieldCacheField_setCharVector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I8:
        {
            const mama_i8_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getI8Vector(field, &values, &size);
            mamaFieldCacheField_setI8Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U8:
        {
            const mama_u8_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getU8Vector(field, &values, &size);
            mamaFieldCacheField_setU8Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I16:
        {
            const mama_i16_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getI16Vector(field, &values, &size);
            mamaFieldCacheField_setI16Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U16:
        {
            const mama_u16_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getU16Vector(field, &values, &size);
            mamaFieldCacheField_setU16Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I32:
        {
            const mama_i32_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getI32Vector(field, &values, &size);
            mamaFieldCacheField_setI32Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U32:
        {
            const mama_u32_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getU32Vector(field, &values, &size);
            mamaFieldCacheField_setU32Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I64:
        {
            const mama_i64_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getI64Vector(field, &values, &size);
            mamaFieldCacheField_setI64Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U64:
        {
            const mama_u64_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getU64Vector(field, &values, &size);
            mamaFieldCacheField_setU64Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_F32:
        {
            const mama_f32_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getF32Vector(field, &values, &size);
            mamaFieldCacheField_setF32Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_F64:
        {
            const mama_f64_t* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getF64Vector(field, &values, &size);
            mamaFieldCacheField_setF64Vector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_STRING:
        {
            const char** values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getStringVector(field, &values, &size);
            mamaFieldCacheField_setStringVector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_PRICE:
        {
            const mamaPrice* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getPriceVector(field, &values, &size);
            mamaFieldCacheField_setPriceVector(copy, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_TIME:
        {
            const mamaDateTime* values = NULL;
            mama_size_t size;
            mamaFieldCacheField_getDateTimeVector(field, &values, &size);
            mamaFieldCacheField_setDateTimeVector(copy, values, size);
            break;
        }
        default:
            break;
    }
    return MAMA_STATUS_OK;
}
コード例 #2
0
ファイル: fieldcacheimpl.c プロジェクト: dmaguire/OpenMAMA
mama_status mamaFieldCache_updateCacheFromMsgField(mamaFieldCache fieldCache,
                                                   const mamaMsgField messageField)
{
    mama_status ret;
    mama_fid_t fid;
    mamaFieldType type = MAMA_FIELD_TYPE_UNKNOWN;
    const char* name = NULL;
    mamaFieldDescriptor descriptor = NULL;
    mamaFieldCacheField field = NULL;

    ret = mamaMsgField_getFid(messageField, &fid);
    if (ret != MAMA_STATUS_OK)
    {
        return ret;
    }

    if (MAMA_STATUS_OK != mamaFieldCacheMap_find(fieldCache->mMap, fid, type, name, &field))
    {
        ret = mamaMsgField_getType(messageField, &type);
        if (ret != MAMA_STATUS_OK)
        {
            return ret;
        }
        if (fieldCache->mUseFieldNames)
        {
            mamaMsgField_getName(messageField, &name);
        }
        mamaFieldCacheField_create(&field, fid, type, name);
        ret = mamaFieldCacheMap_add(fieldCache->mMap, field);
        if (ret != MAMA_STATUS_OK)
        {
            return ret;
        }
        fieldCache->mSize++;

        mamaMsgField_getDescriptor(messageField, &descriptor);
        if (descriptor)
        {
            mamaFieldCacheField_setDescriptor(field, descriptor);
        }
    }
    else
    {
        type = field->mType;
    }

    if (fieldCache->mTrackModified && field->mPublish && !field->mIsModified)
    {
        field->mIsModified = 1;
        mamaFieldCacheList_add(fieldCache->mModifiedFields, (void*)field);
    }

    switch (type)
    {
        case MAMA_FIELD_TYPE_BOOL:
        {
            mama_bool_t result;
            mamaMsgField_getBool(messageField, &result);
            mamaFieldCacheField_setBool(field, result);
            break;
        }
        case MAMA_FIELD_TYPE_CHAR:
        {
            char value;
            mamaMsgField_getChar(messageField, &value);
            mamaFieldCacheField_setChar(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_I8:
        {
            mama_i8_t value;
            mamaMsgField_getI8(messageField, &value);
            mamaFieldCacheField_setI8(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_U8:
        {
            mama_u8_t value;
            mamaMsgField_getU8(messageField, &value);
            mamaFieldCacheField_setU8(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_I16:
        {
            mama_i16_t value;
            mamaMsgField_getI16(messageField, &value);
            mamaFieldCacheField_setI16(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_U16:
        {
            mama_u16_t value;
            mamaMsgField_getU16(messageField, &value);
            mamaFieldCacheField_setU16(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_I32:
        {
            mama_i32_t value;
            mamaMsgField_getI32(messageField, &value);
            mamaFieldCacheField_setI32(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_U32:
        {
            mama_u32_t value;
            mamaMsgField_getU32(messageField, &value);
            mamaFieldCacheField_setU32(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_I64:
        {
            mama_i64_t value;
            mamaMsgField_getI64(messageField, &value);
            mamaFieldCacheField_setI64(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_U64:
        {
            mama_u64_t value;
            mamaMsgField_getU64(messageField, &value);
            mamaFieldCacheField_setU64(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_F32:
        {
            mama_f32_t value;
            mamaMsgField_getF32(messageField, &value);
            mamaFieldCacheField_setF32(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_QUANTITY:
        case MAMA_FIELD_TYPE_F64:
        {
            mama_f64_t value;
            mamaMsgField_getF64(messageField, &value);
            mamaFieldCacheField_setF64(field, value);
            break;
        }
        case MAMA_FIELD_TYPE_STRING:
        {
            const char* value = NULL;
            mamaMsgField_getString(messageField, &value);
            mamaFieldCacheField_setString(field, value, 0);
            break;
        }
        case MAMA_FIELD_TYPE_PRICE:
        {
            mamaMsgField_getPrice(messageField, fieldCache->mReusablePrice);
            mamaFieldCacheField_setPrice(field, fieldCache->mReusablePrice);
            break;
        }
        case MAMA_FIELD_TYPE_TIME:
        {
            mamaMsgField_getDateTime(messageField, fieldCache->mReusableDateTime);
            mamaFieldCacheField_setDateTime(field, fieldCache->mReusableDateTime);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I8:
        {
            const mama_i8_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorI8(messageField, &values, &size);
            mamaFieldCacheField_setI8Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U8:
        {
            const mama_u8_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorU8(messageField, &values, &size);
            mamaFieldCacheField_setU8Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I16:
        {
            const mama_i16_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorI16(messageField, &values, &size);
            mamaFieldCacheField_setI16Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U16:
        {
            const mama_u16_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorU16(messageField, &values, &size);
            mamaFieldCacheField_setU16Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I32:
        {
            const mama_i32_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorI32(messageField, &values, &size);
            mamaFieldCacheField_setI32Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U32:
        {
            const mama_u32_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorU32(messageField, &values, &size);
            mamaFieldCacheField_setU32Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_I64:
        {
            const mama_i64_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorI64(messageField, &values, &size);
            mamaFieldCacheField_setI64Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_U64:
        {
            const mama_u64_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorU64(messageField, &values, &size);
            mamaFieldCacheField_setU64Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_F32:
        {
            const mama_f32_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorF32(messageField, &values, &size);
            mamaFieldCacheField_setF32Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_F64:
        {
            const mama_f64_t* values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorF64(messageField, &values, &size);
            mamaFieldCacheField_setF64Vector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_STRING:
        {
            const char** values = NULL;
            mama_size_t size = 0;
            mamaMsgField_getVectorString(messageField, &values, &size);
            mamaFieldCacheField_setStringVector(field, values, size);
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_PRICE:
        {
            /* TODO: mamaMsgField does not provide methods to get price vector
            const mamaPrice* values = NULL;
            mama_size_t size;
            mamaMsgField_getVectorPrice(messageField, &values, &size);
            mamaFieldCacheField_setPriceVector(field, values, size);
             */
            break;
        }
        case MAMA_FIELD_TYPE_VECTOR_TIME:
        {
            /* TODO: mamaMsgField does not provide methods to get time vector
            const mamaDateTime* values = NULL;
            mama_size_t size;
            mamaMsgField_getVectorDateTime(messageField, &values, &size);
            mamaFieldCacheField_setDateTimeVector(field, values, size);
             */
            break;
        }
        default:
            break;
    }
    return ret;
}
コード例 #3
0
ファイル: fieldcachetest.cpp プロジェクト: dmagOM/OpenMAMA
TEST_F(MamaFieldCacheTestC, applyFieldNew)
{
    mama_status ret = MAMA_STATUS_OK;
    mamaFieldCache fieldCache = NULL;
    mamaFieldCacheField cachedField = NULL;
    mama_size_t size = 0;
    mama_bool_t boolValue = 0;
    mamaFieldCache_create(&fieldCache);

    mamaFieldCacheField field1 = NULL;
    mamaFieldCacheField_create(&field1, 2, MAMA_FIELD_TYPE_F32, NULL);
    mamaFieldCacheField_setF32(field1, 13.13);
    mamaFieldCacheField_setPublish(field1, 1);
    mamaFieldCacheField_setCheckModified(field1, 1);

    mamaFieldCache_getSize(fieldCache, &size);
    ASSERT_EQ(0, size);

    mamaFieldCache_applyField(fieldCache, field1);

    mamaFieldCache_getSize(fieldCache, &size);
    ASSERT_EQ(1, size);

    ret = mamaFieldCache_find(fieldCache, 2, NULL, &cachedField);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_TRUE(cachedField != NULL);

    mamaFieldCacheField_getPublish(cachedField, &boolValue);
    ASSERT_EQ(1, boolValue);
    boolValue = 0;
    mamaFieldCacheField_getCheckModified(cachedField, &boolValue);
    ASSERT_EQ(1, boolValue);
    boolValue = 0;
    mamaFieldCacheField_isModified(cachedField, &boolValue);
    ASSERT_EQ(1, boolValue);

    mamaFieldCacheField field2 = NULL;
    mamaFieldCacheField_create(&field2, 4, MAMA_FIELD_TYPE_I32, "name4");
    mamaFieldCacheField_setI32(field2, 321);
    mamaFieldCacheField_setPublish(field2, 0);
    mamaFieldCacheField_setCheckModified(field2, 0);

    mamaFieldCache_applyField(fieldCache, field2);

    mamaFieldCache_getSize(fieldCache, &size);
    ASSERT_EQ(2, size);

    cachedField = NULL;
    ret = mamaFieldCache_find(fieldCache, 4, "", &cachedField);
    ASSERT_TRUE(cachedField != NULL);
    ASSERT_EQ(MAMA_STATUS_OK, ret);

    boolValue = 0;
    mamaFieldCacheField_getPublish(cachedField, &boolValue);
    ASSERT_EQ(0, boolValue);
    boolValue = 0;
    mamaFieldCacheField_getCheckModified(cachedField, &boolValue);
    ASSERT_EQ(0, boolValue);
    boolValue = 0;
    mamaFieldCacheField_isModified(cachedField, &boolValue);
    ASSERT_EQ(0, boolValue);

    const char* cachedName = NULL;
    ret = mamaFieldCacheField_getName(cachedField, &cachedName);
    ASSERT_EQ(MAMA_STATUS_OK, ret);
    ASSERT_TRUE(cachedName != NULL);
    ASSERT_STREQ("name4", cachedName);

    mamaFieldCacheField_destroy(field1);
    mamaFieldCacheField_destroy(field2);
    mamaFieldCache_destroy(fieldCache);
}