Beispiel #1
0
 void ConstData::setParameter(unsigned int id, const Data& value)
 {
     try
     {
         switch(id)
         {
         case ALLOCATE_DATA:
             m_allocateData = data_cast<Bool>(value);
             break;
         case DATA_TYPE:
             DataOperatorBase::setParameter(id, value);
             
             // make sure some value is set 
             if (! valuePtr())
                 resetValuePtr(typeToData(data_cast<Enum>(value)));
             break;
         default:
             DataOperatorBase::setParameter(id, value);
         }
     }
     catch(std::bad_cast&)
     {
         throw WrongParameterType(parameter(id), *this);
     }
 }
Beispiel #2
0
unique_ptr<Value> XJson::fromUValue(const ::urbi::UValue & uvalue, rapidjson::Document::AllocatorType &allocator) {
    unique_ptr<Value> result(new Value());
    switch (uvalue.type) {
        case ::urbi::DATA_DOUBLE:
            (*result).SetDouble(uvalue.val);
            break;
        case ::urbi::DATA_STRING:
            (*result).SetString(uvalue.stringValue->c_str(), uvalue.stringValue->size(), allocator);
            break;
        case ::urbi::DATA_LIST:
            (*result).SetArray();
            for (auto itemPtr : *uvalue.list) {
                unique_ptr<Value> valuePtr(fromUValue(*itemPtr, allocator));
                (*result).PushBack(*valuePtr, allocator);
            }
            break;
        case ::urbi::DATA_DICTIONARY:
            (*result).SetObject();
            for (auto pair : *uvalue.dictionary) {
                unique_ptr<Value> mappedItemPtr(fromUValue(pair.second, allocator));
                (*result).AddMember(Value().SetString(pair.first.c_str(), pair.first.size(), allocator), *mappedItemPtr, allocator);
            }
            break;
        case ::urbi::DATA_VOID:
            (*result).SetNull();
            break;
        default:
            throw runtime_error("Unsupported type of UValue for JSON serialization.");
            break;
    }
    return result;
}
TRgb CHuiFxEffectParser::ParseColorValueL(CMDXMLNode* aNode)
    {
    // Parse color definition in HTML notation (#aarrggbb)
    if ( !aNode || aNode->NodeType() != CMDXMLNode::ETextNode )
        {
        FAIL(KErrGeneral, _L("Text node expected while parsing a color value")); // leaves
        return KRgbBlack; // never reached. For completeness
        }
    
    TPtrC valuePtr( ((CMDXMLText *)aNode)->Data() );
    TLex parser(valuePtr);

    if (parser.Get() != '#')
            {
            FAIL(KErrGeneral, _L("Invalid color specification")); // leaves
            return KRgbBlack; // never reached. For completeness
            }

    TUint32 color;
    parser.Val(color, EHex);
    // Opaque alpha by default
    if (valuePtr.Length() <= 7)
        {
        color |= 0xff000000;
        }
    
    TUint32 r = (color & 0x00ff0000) >> 16;
    TUint32 g = (color & 0x0000ff00) >> 8;
    TUint32 b = (color & 0x000000ff);
    TUint32 a = (color & 0xff000000) >> 24;
    
    return TRgb(r, g, b, a);
    }
void CTestContextData::ExternalizeL( RWriteStream& aStream )
    {
    TPtrC keyPtr( *iKey );
    aStream.WriteInt16L( keyPtr.Length() );
    aStream.WriteL( keyPtr, keyPtr.Length() );

    TPtrC valuePtr( *iValue );
    aStream.WriteInt16L( valuePtr.Length() );
    aStream.WriteL( valuePtr, valuePtr.Length() );
    }
Beispiel #5
0
 void ConstData::execute(DataProvider& provider)
 {
     if (! valuePtr())
         throw InternalError("Value has not been set");
     
     DataContainer data;
     if (m_allocateData)
     {
         data = DataContainer(valuePtr()->clone());
     }
     else
     {
         Data* dataPtr = 0;
         
         if (m_recycleAccess.empty())
         {
             // if this is the first time the operator executes the value must
             // be cloned
             dataPtr = valuePtr()->clone();
         }
         else 
         {         
             // otherwise the value in the recycler can be reused              
             dataPtr = m_recycleAccess.get();
         }
             
         if (dataPtr != valuePtr())
         {
             // if the value was changed by the user since the last execution
             // update it
             delete dataPtr;
             dataPtr = valuePtr()->clone();
         }
         
         // send and remember for the next execution
         data = DataContainer(dataPtr);
         m_recycleAccess.add(data);
     }
     
     Id2DataPair outputDataMapper(OUTPUT, data);
     provider.sendOutputData( outputDataMapper);
 }
TReal32 CHuiFxEffectParser::ParseFloatValueL(CMDXMLNode* aNode)
    {
    if ( !aNode || aNode->NodeType() != CMDXMLNode::ETextNode )
        {
        FAIL(KErrGeneral, _L("Text node expected while parsing a floating point value"));
        }
    
    TPtrC valuePtr( ((CMDXMLText *)aNode)->Data() );
    TReal32 v = ParseFloatVal(valuePtr);
    return v;
    }
// -----------------------------------------------------------------------------
// CExtensionDescrParam::InternalizeL
// -----------------------------------------------------------------------------
//
CExtensionDescrParam*
CExtensionDescrParam::InternalizeL(RReadStream& aReadStream)
	{
	TUint32 id = aReadStream.ReadUint32L();
	CExtensionDescrParam* self = new (ELeave) CExtensionDescrParam(id);	
	CleanupStack::PushL(self);

	TUint32 valueLength = aReadStream.ReadInt32L();
	self->iValue = HBufC8::NewL(valueLength);
	TPtr8 valuePtr(self->iValue->Des());
	aReadStream.ReadL(valuePtr, valueLength);
	CleanupStack::Pop(self);
	return self;
	}
void UPPayHttpConnection::setRequestProperty(const char *property, const char *value)
{
	TInt len = User::StringLength((const TUint8*) property);
	if (!len)
		return;
	TPtr8 namePtr((TUint8 *) property, len, len);
	len = User::StringLength((const TUint8*) value);
	if (!len)
		return;
	TPtr8 valuePtr((TUint8 *) value, len, len);
	//CommonUtils::WriteLogL(namePtr, valuePtr);
	RStringF val;
	val = stringPool.OpenFStringL(namePtr);
	headers.SetRawFieldL(val, valuePtr, _L8(";"));
	val.Close();
}
Beispiel #9
0
 // Non-Const
 void add(typename Passable<K const>::Type key)
 {
     uint64_t* valuePtr(0);
     if( _map.find(key, valuePtr) ) {
         ++(*valuePtr);
     } else {
         _map[key] = 1;
         if( _sampleCount ) {
             if( key < _min ) {
                 _min = key;
             } else if( _max < key ) {
                 _max = key;
             }
         } else {
             _min = _max = key;
         }
     }
     ++_sampleCount;
 }
// -----------------------------------------------------------------------------
// CAknConfGestureSettingList::DataValuePointer()
// -----------------------------------------------------------------------------
//
TInt* CAknConfGestureSettingList::DataValuePointer( const TInt& aId, TInt& aCenRepKey )
    {
    TInt* valuePtr( NULL );/*
    switch ( aId )
        {
        case EAknConfGestureSettingTapThreshold:
            valuePtr = &iTapThreshold;
            aCenRepKey = KTapThreshold;
            break;
        case EAknConfGestureSettingLongTapThreshold:
            valuePtr = &iLongTapThreshold;
            aCenRepKey = KLongTapThreshold;
            break;
        case EAknConfGestureSettingDoubleTapThreshold:
            valuePtr = &iDoubleTapThreshold;
            aCenRepKey = KDoubleTapMaximumDuration;
            break;
        case EAknConfGestureSettingDragThreshold:
            valuePtr = &iDragThreshold;
            aCenRepKey = KDragThreshold;
            break;
        case EAknConfGestureSettingFlickBuffer:
            valuePtr = &iFlickBuffer;
            aCenRepKey = KFlickBuffer;
            break;
        case EAknConfGestureSettingFlickSpeedThreshold:
            valuePtr = &iFlickSpeedThreshold;
            aCenRepKey = KFlickSpeedThreshold;
            break;
        case EAknConfGestureSettingFlickDetectionTime:
            valuePtr = &iFlickDetectionTime;
            aCenRepKey = KFlickDetectionTime;
            break;
        case EAknConfGestureSettingFlickDirectionChange:
            valuePtr = &iFlickChangeSensitivity;
            aCenRepKey = KFlickDirectionChange;
            break;
        case EAknConfGestureSettingPinchInitialThreshold:
            valuePtr = &iPinchInitialThreshold;
            aCenRepKey = KPinchInitialThreshold;
            break;
        case EAknConfGestureSettingPinchMovementThreshold:
            valuePtr = &iPinchMovementThreshold;
            aCenRepKey = KPinchMovementThreshold;
            break;
        case EAknConfGestureSettingPinchDirectionChangeSensitivity:
            valuePtr = &iPinchDirectionChangeSensitivity;
            aCenRepKey = KPinchDirectionChangeSensitivity;
            break;
        case EAknConfGestureSettingPinchDirectionResetSensitivity:
            valuePtr = &iPinchDirectionResetSensitivity;
            aCenRepKey = KPinchDirectionResetSensitivity;
            break;
        case EAknConfGestureSettingPinchDimensionThreshold:
            valuePtr = &iPinchDimensionThreshold;
            aCenRepKey = KPinchDimensionThreshold;
            break;
        case EAknConfGestureSettingPinchMaximumConfirmationDuration:
            valuePtr = &iPinchMaximumConfirmationDuration;
            aCenRepKey = KPinchMaximumConfirmationDuration;
            break;
        default:
            break;
        }*/
    return valuePtr;
    }
Beispiel #11
0
void StructFieldValueTest::testStruct()
{
    const DocumentType *doc_type = doc_repo.getDocumentType(42);
    CPPUNIT_ASSERT(doc_type);
    FixedTypeRepo repo(doc_repo, *doc_type);
    const DataType &type = *repo.getDataType("test.header");
    StructFieldValue value(type);
    const Field &intF = value.getField("int");
    const Field &longF = value.getField("long");
    const Field &strF = value.getField("content");

        // Initially empty
    CPPUNIT_ASSERT_EQUAL(size_t(0), value.getSetFieldCount());
    CPPUNIT_ASSERT(!value.hasValue(intF));

    value.setValue(intF, IntFieldValue(1));

        // Not empty
    CPPUNIT_ASSERT_EQUAL(size_t(1), value.getSetFieldCount());
    CPPUNIT_ASSERT(value.hasValue(intF));

        // Adding some more
    value.setValue(longF, LongFieldValue(2));

        // Not empty
    CPPUNIT_ASSERT_EQUAL(size_t(2), value.getSetFieldCount());
    CPPUNIT_ASSERT_EQUAL(1, value.getValue(intF)->getAsInt());
    CPPUNIT_ASSERT_EQUAL(2, value.getValue(longF)->getAsInt());

        // Serialize & equality
    std::unique_ptr<ByteBuffer> buffer(value.serialize());
    buffer->flip();

    CPPUNIT_ASSERT_EQUAL(buffer->getLength(), buffer->getLimit());
    StructFieldValue value2(type);
    CPPUNIT_ASSERT(value != value2);

    deserialize(*buffer, value2, repo);

    CPPUNIT_ASSERT(value2.hasValue(intF));
    CPPUNIT_ASSERT_EQUAL(value, value2);

    // Various ways of removing
    {
        // By value
        buffer->setPos(0);
        deserialize(*buffer, value2, repo);
        value2.remove(intF);
        CPPUNIT_ASSERT(!value2.hasValue(intF));
        CPPUNIT_ASSERT_EQUAL(size_t(1), value2.getSetFieldCount());

        // Clearing all
        buffer->setPos(0);
        deserialize(*buffer, value2, repo);
        value2.clear();
        CPPUNIT_ASSERT(!value2.hasValue(intF));
        CPPUNIT_ASSERT_EQUAL(size_t(0), value2.getSetFieldCount());
    }

    // Updating
    value2 = value;
    CPPUNIT_ASSERT_EQUAL(value, value2);
    value2.setValue(strF, StringFieldValue("foo"));
    CPPUNIT_ASSERT(value2.hasValue(strF));
    CPPUNIT_ASSERT_EQUAL(vespalib::string("foo"),
                         value2.getValue(strF)->getAsString());
    CPPUNIT_ASSERT(value != value2);
    value2.assign(value);
    CPPUNIT_ASSERT_EQUAL(value, value2);
    StructFieldValue::UP valuePtr(value2.clone());

    CPPUNIT_ASSERT(valuePtr.get());
    CPPUNIT_ASSERT_EQUAL(value, *valuePtr);

        // Iterating
    const StructFieldValue& constVal(value);
    for(StructFieldValue::const_iterator it = constVal.begin();
        it != constVal.end(); ++it)
    {
        constVal.getValue(it.field());
    }

        // Comparison
    value2 = value;
    CPPUNIT_ASSERT_EQUAL(0, value.compare(value2));
    value2.remove(intF);
    CPPUNIT_ASSERT(value.compare(value2) < 0);
    CPPUNIT_ASSERT(value2.compare(value) > 0);
    value2 = value;
    value2.setValue(intF, IntFieldValue(5));
    CPPUNIT_ASSERT(value.compare(value2) < 0);
    CPPUNIT_ASSERT(value2.compare(value) > 0);

        // Output
    CPPUNIT_ASSERT_EQUAL(
            std::string("Struct test.header(\n"
                        "  int - 1,\n"
                        "  long - 2\n"
                        ")"),
            value.toString(false));
    CPPUNIT_ASSERT_EQUAL(
            std::string("  Struct test.header(\n"
                        "..  int - 1,\n"
                        "..  long - 2\n"
                        "..)"),
            "  " + value.toString(true, ".."));
    CPPUNIT_ASSERT_EQUAL(
            std::string("<value>\n"
                        "  <int>1</int>\n"
                        "  <long>2</long>\n"
                        "</value>"),
            value.toXml("  "));

        // Failure situations.

        // Refuse to set wrong types
    try{
        value2.setValue(intF, StringFieldValue("bar"));
        CPPUNIT_FAIL("Failed to check type equality in setValue");
    } catch (std::exception& e) {
        CPPUNIT_ASSERT_CONTAIN("Cannot assign value of type", e.what());
    }
}