Esempio n. 1
0
//! function
static bool nodeToVariant(const QDomNode &aNode,QVariant &aValue) {
    bool vRetval = false;
    QString vType, vValue;

    aValue = QVariant();
    if(!vRetval && aNode.isCDATASection()) {
        vValue = aNode.toCDATASection().data();
        vRetval = true;
    }

    if(!vRetval && aNode.isText()) {
        vValue = aNode.toText().data();
        vRetval = true;
    }

    if(!vRetval) return vRetval;
    if(vValue.isEmpty()) return false; // ????

    const QDomNode vParent = aNode.parentNode();
    if(vParent.isElement()) {
        vType = vParent.toElement().attribute(QString::fromLatin1("type"));
    }

    if(vType == QString::fromLatin1("bytearray")) {
        aValue = QVariant(vValue.toLatin1());
    }
    else if(vType == QString::fromLatin1("variant")) {
        QByteArray vArray(vValue.toLatin1());
        QDataStream vStream(&vArray, QIODevice::ReadOnly);
        vStream >> aValue;
    }
Esempio n. 2
0
/*
*********************************************************************************************
	描述:解密函数,可以对密文进行解密。
	输入:	
		pData	要密文数据的首地址。
		d_len	数据的长度
		pPwd	密码
		p_len	密码长度
	输出:
		字符类型	解密后的数据首地址,等于data
*********************************************************************************************
*/
char* CEncrypt::Right ( char *pData , int d_len , const char *pPwd , int p_len )
{
	if ( pData && pPwd && d_len > 0 && p_len > 0 ){
		
		char *pKey = new char[p_len];

		if ( pKey ){

			memcpy( pKey, pPwd, p_len );	// 因为pPwd是不可写的,所以要申请一个pKey代替pPwd进行计算

			GenKey( pKey, p_len );	// 将密码转换成钥匙
			
			CVirtualArray vArray( pData, d_len, pKey, p_len );	// 将pData与pKey用vArray连接成一个虚拟数组

			for ( int j = p_len ; j > 0 ; j -- ){	// 解密算法...
				for ( int i = d_len + p_len - 1 ; ( i - j ) >= 0 ; i -- ){
					vArray [i-j] ^= vArray [i] ;
				}
			}

			memset( pKey , 0 , p_len );	// 销毁钥匙
			delete [] pKey;
		}
	}
	return	pData ;
}
Esempio n. 3
0
vArray(uchar) vImageToRGBA(color_image * the_image)
{
  vint8 buffer_size = the_image->Size() * 4;
  vArray(uchar) buffer = vnew(uchar, (vector_size) buffer_size);
  vImageToRGBA(the_image, buffer);
  return buffer;
}
void ArduinoSerial::ReadAvailable()
{
	// Use the ClearCommError function to get status info on the Serial port
	ClearCommError(m_hSerial, &m_dwError, &m_status);

	//Check if there is something to read
	if(m_status.cbInQue < 1)
	{
		return;
	}

	std::vector<char> vArray(m_status.cbInQue, 0);

	//Try to read the require number of chars
	DWORD dwBytesRead = 0;
	if(FALSE == ReadFile(m_hSerial, &vArray[0], static_cast<DWORD>(vArray.size()), &dwBytesRead, nullptr))
	{
		return;
	}

	for(auto c : vArray)
	{
		m_vBuffer.push_back(c);
	}
}
// -----------------------------------------------------------------------------
// CTestPlatAlfVisual::TestAlfDisplayForBackgroundL
// -----------------------------------------------------------------------------
//
TInt CTestPlatAlfVisual::TestAlfDisplayForBackgroundL( CStifItemParser& /*aItem*/ )
    {
    _LIT( KTestPlatAlfVisual, "TestPlatAlfVisual" );
    _LIT( KTestAlfDisplayForBackgroundL, "TestAlfDisplayForBackgroundL" );
    TestModuleIf().Printf( 0, KTestPlatAlfVisual, KTestAlfDisplayForBackgroundL );
    // Print to log file
    iLog->Log( KTestAlfDisplayForBackgroundL );
    
    iAlfDisplay->SetClearBackgroundL( CAlfDisplay::EClearWithColor );
    RArray<TAlfDisplayBackgroundItem> vArray( 1 );
    iAlfDisplay->SetBackgroundItemsL( vArray );
    
    return KErrNone;
    }
Esempio n. 6
0
/*
*********************************************************************************************
	描述:加密函数,可以对任意数据进行加密。
	输入:	
		pData	要加密数据的首地址。
		d_len	数据的长度
		pPwd	密码
		p_len	密码长度
	输出:
		字符类型	加密后的数据首地址,等于data
	注:
*********************************************************************************************
*/
char* CEncrypt::Left ( char *pData , int d_len , const char *pPwd , int p_len )
{
	if ( pData && pPwd && d_len > 0 && p_len > 0 ){

		char *pKey = new char [p_len];

		if (pKey){

			memcpy( pKey , pPwd , p_len );

			CVirtualArray vArray(pData, d_len, pKey, p_len);	// 将pData与pKey用vArray连接成一个虚拟数组

			for ( int j = 1 ; j <= p_len ; j ++ ){
				for ( int i = 0 ; ( i + j ) != ( d_len + p_len ) ; i ++ ){
					vArray [i] ^= vArray [i+j] ;
				}
			}

			memset( pKey , 0 , p_len );
			delete [] pKey;
		}
	}
	return 	pData ;
}
Esempio n. 7
0
TEST(syntax, param_ordering) {
  CREATE_RUNTIME();
  CREATE_TEST_ARENA();

  value_t any_guard_ast = new_heap_guard_ast(runtime, gtAny, null());

  reusable_scratch_memory_t scratch;
  reusable_scratch_memory_init(&scratch);

  variant_t *sub = vValue(ROOT(runtime, subject_key));
  variant_t *sel = vValue(ROOT(runtime, selector_key));
  variant_t *just_sub = vArray(sub);
  variant_t *just_sel = vArray(sel);
  variant_t *just_0 = vArray(vInt(0));
  variant_t *just_1 = vArray(vInt(1));
  variant_t *just_2 = vArray(vInt(2));
  variant_t *just_3 = vArray(vInt(3));

  CHECK_ORDERING(4, vArray(just_0, just_1, just_2, just_3), 0 o 1 o 2 o 3);
  CHECK_ORDERING(4, vArray(just_3, just_2, just_1, just_0), 3 o 2 o 1 o 0);
  CHECK_ORDERING(4, vArray(just_2, just_0, just_3, just_1), 2 o 0 o 3 o 1);
  CHECK_ORDERING(3, vArray(just_2, just_0, just_3), 1 o 0 o 2);
  CHECK_ORDERING(2, vArray(just_2, just_3), 0 o 1);

  CHECK_ORDERING(3, vArray(just_2, vArray(vInt(0), vInt(1)), just_3), 1 o 0 o 2);
  CHECK_ORDERING(3, vArray(just_2, vArray(vInt(0), vInt(4)), just_3), 1 o 0 o 2);
  CHECK_ORDERING(3, vArray(just_2, vArray(vInt(5), vInt(4)), just_3), 0 o 2 o 1);

  CHECK_ORDERING(4, vArray(just_0, just_1, just_2, just_sel), 1 o 2 o 3 o 0);
  CHECK_ORDERING(4, vArray(just_0, just_sub, just_2, just_sel), 2 o 0 o 3 o 1);
  CHECK_ORDERING(3, vArray(just_0, vArray(sub, sel), just_3), 1 o 0 o 2);

  reusable_scratch_memory_dispose(&scratch);

  DISPOSE_TEST_ARENA();
  DISPOSE_RUNTIME();
}
Esempio n. 8
0
TEST(syntax, parameter_order_index) {
  CREATE_RUNTIME();
  CREATE_TEST_ARENA();

  variant_t *subject_key = vValue(ROOT(runtime, subject_key));
  variant_t *selector_key = vValue(ROOT(runtime, selector_key));

  CHECK_ORDERING_INDEX(0, vArray(subject_key));
  CHECK_ORDERING_INDEX(1, vArray(selector_key));
  CHECK_ORDERING_INDEX(0, vArray(subject_key, selector_key));

  CHECK_ORDERING_INDEX(2, vArray(vInt(0)));
  CHECK_ORDERING_INDEX(3, vArray(vInt(1)));
  CHECK_ORDERING_INDEX(4, vArray(vInt(2)));
  CHECK_ORDERING_INDEX(2, vArray(vInt(0), vInt(2)));
  CHECK_ORDERING_INDEX(2, vArray(vInt(2), vInt(0)));
  CHECK_ORDERING_INDEX(1, vArray(vInt(2), selector_key));

  CHECK_ORDERING_INDEX(kMaxOrderIndex, vArray(vStr("foo")));
  CHECK_ORDERING_INDEX(102, vArray(vStr("foo"), vInt(100)));

  DISPOSE_TEST_ARENA();
  DISPOSE_RUNTIME();
}
Esempio n. 9
0
int main(){

    sf::RenderWindow window(sf::VideoMode(800, 600), "Particles");
    sf::RectangleShape rectangle, rectangle2, nexus;

    ParticleSystem particles(1000);
    sf::Clock clock;

    sf::Vector2i screenDimensions(800, 600);
    sf::Vector2i blockDimensions(10, 10);

    sf::View view1(sf::FloatRect(0, 0, 800, 600));
    sf::View view2(sf::FloatRect(800, 0, 800, 600));

    sf::View standard = window.getView();
    unsigned int size = 100;
    sf::View minimap(sf::FloatRect(0, 0, 800, 600));
    //sf::View minimap(sf::FloatRect(view1.getCenter().x, view1.getCenter().y, size, window.getSize().y*size/window.getSize().x));
    //minimap.setViewport(sf::FloatRect(1.f-(1.f*minimap.getSize().x)/window.getSize().x-0.02f, 1.f-(1.f*minimap.getSize().y)/window.getSize().y-0.02f, (1.f*minimap.getSize().x)/window.getSize().x, (1.f*minimap.getSize().y)/window.getSize().y));
    minimap.setViewport(sf::FloatRect(0.75f, 0, 0.25f, 0.25f));
    minimap.zoom(2.f);
    //view1.setViewport(sf::FloatRect(0, 0, 0.5f, 1));

    // joueur 2 (côté droit de l'écran)
    //view2.setViewport(sf::FloatRect(0.5f, 0, 0.5f, 1));


    rectangle.setOutlineThickness(3);
    rectangle.setOutlineColor(sf::Color(0, 0, 0, 255));
    rectangle.setSize({50.f, 50.f});
    rectangle.setPosition({400.f, 300.f});
    rectangle.setFillColor(sf::Color::Red);

    rectangle2.setOutlineThickness(3);
    rectangle2.setOutlineColor(sf::Color(0, 0, 0, 255));
    rectangle2.setSize({500.f, 500.f});
    rectangle2.setPosition({800.f, 0.f});
    rectangle2.setFillColor(sf::Color::Blue);

    int x = rand()%(800-800*2)+800;
    int y = rand()%(600-0)+0;
    nexus.setSize({100.f, 100.f});
     std::cout << x << " , " << y << std::endl;
    nexus.setPosition({400.f, 300.f});

    sf::Vector2f mouse;
    //view1.setCenter(rectangle.getPosition());

    while (window.isOpen()){
        sf::Event event;
        while (window.pollEvent(event)){
            if(event.type == sf::Event::Closed){
                window.close();
            }

            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) {
                rectangle.move(-7, 0);
                mouse = {rectangle.getPosition().x+(rectangle.getSize().x/2), rectangle.getPosition().y+(rectangle.getSize().y/2)};

                view1.setCenter(rectangle.getPosition());
                std::cout << rectangle.getPosition().x << " , " << rectangle.getPosition().y << std::endl;
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) {
                mouse = {rectangle.getPosition().x+(rectangle.getSize().x/2), rectangle.getPosition().y+(rectangle.getSize().y/2)};
                rectangle.move(+7,0);
                view1.setCenter(rectangle.getPosition());
                std::cout << rectangle.getPosition().x << " , " << rectangle.getPosition().y << std::endl;
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) {
                mouse = {rectangle.getPosition().x+(rectangle.getSize().x/2), rectangle.getPosition().y+(rectangle.getSize().y/2)};
                rectangle.move(0,-7);
                view1.setCenter(rectangle.getPosition());
                std::cout << rectangle.getPosition().x << " , " << rectangle.getPosition().y << std::endl;
            }
            if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) {
                mouse = {rectangle.getPosition().x+(rectangle.getSize().x/2), rectangle.getPosition().y+(rectangle.getSize().y/2)};
                rectangle.move(0,+7);
                view1.setCenter(rectangle.getPosition());
                std::cout << rectangle.getPosition().x << " , " << rectangle.getPosition().y << std::endl;
            }
        }

        particles.setEmitter(mouse);
        //particles.setEmitter(window.mapPixelToCoords((sf::Vector2i)mouse));

        sf::Time elapsed = clock.restart();
        particles.update(elapsed);


        window.clear();
        window.setView(view1);

        for(int i = 0;i<nexus.getSize().x/blockDimensions.x; i++){
            for(int j = 0;j<nexus.getSize().y/blockDimensions.y;j++){
                sf::VertexArray vArray(sf::PrimitiveType::Quads, 4);
                vArray[0].position = sf::Vector2f(i*blockDimensions.x+nexus.getPosition().x, j*blockDimensions.y+nexus.getPosition().y);
                vArray[1].position = sf::Vector2f(i*blockDimensions.x+blockDimensions.x+nexus.getPosition().x, j*blockDimensions.y+nexus.getPosition().y);
                vArray[2].position = sf::Vector2f(i*blockDimensions.x+blockDimensions.x+nexus.getPosition().x, j*blockDimensions.y+blockDimensions.y+nexus.getPosition().y);
                vArray[3].position = sf::Vector2f(i*blockDimensions.x+nexus.getPosition().x, j*blockDimensions.y+blockDimensions.y+nexus.getPosition().y);

                for(int k=0;k<4;k++){
                    int red = rand() % 255;
                    int green = rand() % 255;
                    int blue = rand() % 255;

                    vArray[k].color = sf::Color(red, green, blue);
                }
                window.draw(vArray);
            }
        }


        //window.clear();

        window.setView(standard);
        window.draw(particles);
        window.draw(rectangle);

        //window.draw(rectangle2);
        //window.setView(view2);
        //window.draw(rectangle2);

        window.setView(minimap);
        window.draw(particles);
        window.draw(rectangle);

        window.display();
    }

    return 0;
}
Esempio n. 10
0
    exit_error("\nerror: unexpected argument in vSuperType\n");
    return OtherType;
  }
}


vArray(uchar) vImageToRGBA(color_image * the_image)
{
  vint8 buffer_size = the_image->Size() * 4;
  vArray(uchar) buffer = vnew(uchar, (vector_size) buffer_size);
  vImageToRGBA(the_image, buffer);
  return buffer;
}


void vImageToRGBA(color_image * the_image, vArray(uchar) buffer)
{
  vArray(uchar) R = the_image->GetR();
  vArray(uchar) G = the_image->GetG();
  vArray(uchar) B = the_image->GetB();
  vint8 size = the_image->Size();
  vint8 i;
  vint8 index = 0;

  for (i = 0; i < size; i++)
  {
    buffer[index++] = R[i];
    buffer[index++] = G[i];
    buffer[index++] = B[i];
    buffer[index++] = 0;
  }