Esempio n. 1
0
bool XMLRW::CreateRow(TiXmlElement *pRootEle,unsigned long int i)
{
	struct BLACK_DATA_ST data={0};

	//取一条数据
#if ALLTAB_DETECT_CAR_MODE
//汽车
	if(OracleIO.CAR_BlackTable_ReadOne(i,data))
#else
//电动车
	if(OracleIO.ELECAR_BlackTable_ReadOne(i,data))
#endif
	{
		// 生成子节点:row
		TiXmlElement *prow = new TiXmlElement(_T("ROW"));  
		if (NULL==prow)  
		{  
			return false;  
		}  
		pRootEle->LinkEndChild(prow);  
		
		if(!CreateData(prow,"SCARNUMBER",data.plate))
			return false;
		if(!CreateData(prow,"SBRAND",data.brand))
			return false;
		if(!CreateData(prow,"SLOSTNAME",data.name))
			return false;
		if(!CreateData(prow,"SPHONE",data.Phone))
			return false;
		if(!CreateData(prow,"SMARK",data.other))
			return false;
	}
	return true;
}
Esempio n. 2
0
int main(void)
{
	Lcountry head=NULL;

	//生成数据
	if(CreateData(&head)!=1)
		return 1;

	//显示数据
	Print(head);

	//写入数据
	if(WriteData(head)!=1)
		return 1;

	//释放资源
	Free(&head);
	printf("写入完毕\n");

	printf("\n读取数据...\n");
	//读入数据
	if(ReadData(&head)!=1)
		return 1;

	//显示数据
	Print(head);

	//释放资源
	Free(&head);
	return 0;
}
Esempio n. 3
0
int empty(void)
{
    int m, n;
    int k;
    int m1, n1, p1;
    int m2, n2, p2;
    int NZMAX = 1;
    int jc = 5;
    int ir;
    int *header;
    double *value;
    GetRhsVar(1, MATRIX_OF_DOUBLE_DATATYPE, &m1, &n1, &p1);
    GetRhsVar(2, MATRIX_OF_DOUBLE_DATATYPE, &m2, &n2, &p2);
    m = (int) * stk(p1);
    n = (int) * stk(p2);
    CreateData(3, (6 + n + 1)*sizeof(int) + sizeof(double));
    header = (int *) GetData(3);
    value = (double *) header;
    header[0] = 7;
    header[1] = m;
    header[2] = n;
    header[3] = 0;
    header[4] = NZMAX;
    header[jc] = 0;
    ir = jc + n + 1;
    for (k = 0; k < n; ++k)
    {
        header[jc + k + 1] = 0;
    }
    header[ir] = 0;
    value[(5 + header[2] + header[4]) / 2 + 1] = 0.0;
    LhsVar(1) = 3;
    PutLhsVar();
    return 1;
}
Esempio n. 4
0
	UInt32::UInt32( const char *name )
		:Exist::Value<mdk::uint32>(name, true)
	{
		m_type = DataType::uInt32;
		Exist::IOBus::CreateExistObj( this, m_type );
		CreateData();
	}
//----------------------------------------------------------------------------
// PhSrvDebugInfo::Print
//----------------------------------------------------------------------------
//
void PhSrvDebugInfo::Print(TInt/* aArea*/,const TDesC& aText )
{
    


            // LOG TO FILE
#ifdef __PHSRV_DEBUG_WRITE_LOG__

            TBuf8<128> toFile;
            CnvUtfConverter::ConvertFromUnicodeToUtf8( toFile, aText.Left(126) );
            toFile.Append( KPhSrvDebugEOF );
            
            PhSrvDebugInfo::CPhSrvDebugData* data = NULL;
    if( !data )
        {
        data = CreateData();
        }
    if( data )
        {
        data->CreateFile();           
        data->WriteFile( toFile );
        }
#endif  // __PHSRV_DEBUG_WRITE_LOG__
#ifdef __PHSRV_PRINT_DEBUG_INFO__
            RDebug::Print( aText );
#endif // __PHSRV_PRINT_DEBUG_INFO__
          //  }   
      //  }
    }
Esempio n. 6
0
UInt8::UInt8( const char *name )
:Value<mdk::uint8>(name, false)
{
	m_type = DataType::uInt8;
	IOBus::CreateExistObj( this, m_type );
	CreateData();
}
Esempio n. 7
0
//修改一个用户
bool CEmployee::Edit(const BNSEmployeeData& data)
{
	//生成数据	
	WXDB::DBEmployeeData empData;
	CreateData(data, empData);

	return this->Edit(empData);
}
Esempio n. 8
0
int main(void)
{
	InfoPtr linfo;

	int pressedEnter = '0';
	int option = 0;
	
	while(pressedEnter != '\n')
	{
		printf("			--------------------------------\n");
		printf("			 WELCOME TO Tic-Tac-Toe !\n");
		printf("			--------------------------------\n");
		printf("			        -Press ENTER-\n");

		pressedEnter = getchar();
	}
	
	while(option != '4')
	{
		printf("			-------------------------\n");
		printf("			       Tic-Tac-Toe !\n");
		printf("			-------------------------\n");
		printf("			1.New Game\n");
		printf("			2.Continue Game\n");
		printf("			3.Achievements\n");
		printf("			4.Exit\n");
		printf("Option: ");
		option = getchar();

		printf("option has the value of: %d\n", option);

		while((option <= '0') && (option >= '5'))
		{
			printf("You need to choose between 1-5.\n");
			printf("Option: ");

			option = getchar();
		}
		
		switch(option)
		{
			case '1':
				linfo = CreateData();
				NewGame(linfo);
				break;
			
			case '2':
				//LoadGame();
				break;
			
			case '3':
				//ShowStatistics();
				break;
		}
	}
	return (0);
}
/* argv[1] is the device e.g. eth0
   argv[2] is the number of packets to send
*/ 
int main(int argc, char **argv){
	if (argc < 1){
		perror("Arguments?\n");
		return 1;
	}

	int raw;
	unsigned char* packet;
	struct ethhdr *ethernet_header;
	struct iphdr *ip_header;
	struct tcphdr  *tcp_header;
	unsigned char *data;	
	int num_of_pkts;
	int pkt_len;
	
	/* Create the raw socket */
	raw = CreateRawSocket(ETH_P_ALL);

	/* Bind raw socket to interface */
	BindRawSocketToInterface(argv[1], raw, ETH_P_ALL);
	//num_of_pkts = atoi(argv[2]);

	ethernet_header = CreateEthernetHeader();
	ip_header = CreateIPHeader();
	tcp_header = CreateTcpHeader();
	data = CreateData(DATA_SIZE);

	/* Create PseudoHeader and compute TCP Checksum  */
	CreatePseudoHeaderAndComputeTcpChecksum(tcp_header, ip_header, data);

	//pkt_len = sizeof(struct ethhdr) + sizeof(struct iphdr);
	pkt_len = sizeof(struct ethhdr) + ntohs(ip_header->tot_len);

	packet = (unsigned char *) malloc(pkt_len);
	memcpy(packet, ethernet_header, sizeof(struct ethhdr));
	memcpy((packet + sizeof(struct ethhdr)), ip_header, ip_header->ihl*4);
	memcpy((packet + sizeof(struct ethhdr) + ip_header->ihl*4),tcp_header, tcp_header->doff*4);
	memcpy((packet + sizeof(struct ethhdr) + ip_header->ihl*4 + tcp_header->doff*4), data, DATA_SIZE);

	//while((num_of_pkts--)>0){
		if(!SendRawPacket(raw, packet, pkt_len))
			perror("Error sending packet");
		else
			printf("Packet sent successfully\n");
	//}

	/*free(ethernet_header);
	free(ip_header);
	free(tcp_header);
	free(data);
	free(packet);*/

	close(raw);

	return 0;
}
Esempio n. 10
0
void FScreenShotManager::GenerateLists()
{
	// Create the screen shot tree root
	ScreenShotRoot = MakeShareable( new FScreenShotBaseNode( "ScreenShotRoot" ) ); 

	// Create the screen shot data
	CreateData();

	// Populate the screen shot tree with the dummy screen shot data
	for ( int32 Index = 0; Index < ScreenShotDataArray.Num(); Index++ )
	{
		ScreenShotRoot->AddScreenShotData( ScreenShotDataArray[ Index ] );
	}
}
Esempio n. 11
0
DATA ArrayToListControl()
{
    DATA P;
    CreateData(&P);
    int initial=1;
    while(initial<=id)
    {
        DATA temp,last;

        if(P==Nil)
        {
            P=Alokasi();
            if(P==Nil)
            {
                printf("\nOut of Memory / Error in program\n");
            }
            else
            {
                P=ArrayToList(P,initial);
                Next(P)=Nil;
            }
        }
        else
        {
            temp=P;
            while(temp!=Nil)
            {
                last=temp;
                temp=Next(temp);
            }
            Next(last)=Alokasi();
            last=Next(last);
            if(last==Nil)
            {
                printf("\nOut of Memory / Error in program\n");
            }
            else
            {
                last=ArrayToList(last,initial);
                Next(last)=Nil;
            }
        }
        initial++;
    }
    return P;
}
Esempio n. 12
0
/*---------------------------------------------------------------
 * Creates a node and then calls the application-specific
 * function CreateData() to create the node's data structure.
 * Returns NULL on error.
 *-------------------------------------------------------------*/
Link CreateNode ( struct List *L, void *data )
{
    Link new_node;

    new_node = (Link) malloc ( sizeof ( struct Node ));
    if ( new_node == NULL )
        return ( NULL );

    new_node->prev = NULL;
    new_node->next = NULL;

    /*--- now call the application-specific data allocation ---*/
    new_node->pdata = CreateData( data );
    if ( new_node->pdata == NULL )
    {
        free ( new_node );
        return ( NULL );
    }
    else
        return ( new_node );
}
Esempio n. 13
0
int copy_op ( )
{
    double	value;
    descriptor *d;


    d = top ( );
    d = CoerceData (deref (d), T_Double);

    if (D_Type (d) != T_Double) {
	TypeError ("in conditional context", d, NULL, NULL, F_False);
	return 1;
    }

    value = *D_Double (d);
    d = push ( );
    CreateData (d, NULL, NULL, T_Double);
    *D_Double (d) = value;

    d_printf ("copy\n");
    return 0;
}
Esempio n. 14
0
//---------------------------------------------------------------------------
void __fastcall TFormReportForma3::ToolBtnPreviewClick(TObject *Sender)
{
  TFormSelectDate* form = new TFormSelectDate(this);
  try
  {
    form->ShowModal();
    Word Year, Month, Day;
    TDateTime dtPresent = form->GetSelectedDate();
    DecodeDate(dtPresent, Year, Month, Day);
    curr_year = AnsiString(Year);

    CreateData();
    CreateWordDocument();
    DestroyData();
  }
  catch(...)
  {
    Application->MessageBox("Работа с MS Excel не возможна. Просмотр отчета невозможен.","Ошибка.",MB_OK|MB_ICONEXCLAMATION);
    Close();
  }
  delete form;
}
Esempio n. 15
0
//添加一个用户
bool CEmployee::Add(const BNSEmployeeData& data)
{
	bool bRtn = true;
	//用户在内存
	if(this->IsBeingInMem(data._id))
	{
		return false;
	}


	//锁定用户,失败则返回 false
	if(!WXBNS::CWXLockDBSingle::Init()->LockEmployee(data._id))
	{
		return false;
	}
	
	//用户不在数据库
	if(!this->IsBeingInDB(data._id))
	{
		//生成数据	
		WXDB::DBEmployeeData empData;
		CreateData(data, empData);

		//添加到数据库
		bRtn = this->Add(data);
	}
	else
	{
		bRtn =false;
	}


	//解除锁定
	WXBNS::CWXLockDBSingle::Init()->UnLockEmployee(data._id);

	return bRtn;
}
std::string IDSEXT::InvokeMethod(const std::string& command)
{
    int index = command.find_first_of(" ");

    string strCommand = command.substr(0, index);
    string strParam = command.substr(index + 1, command.length());

    Json::Reader reader;
    Json::Value obj;
    if (strCommand == "getVersion") {
        return GetVersion();
    } else if (strCommand == "registerProvider") {
        return RegisterProvider(strParam);
    } else if (strCommand == "setOption") {
        // parse the JSON
        bool parse = reader.parse(strParam, obj);

        if (!parse) {
            //fprintf(stderr, "%s\n", "error parsing\n");
            return "unable to parse options";
        }
        int option = obj["option"].asInt();
        const std::string value = obj["value"].asString();
        return( SetOption(option, value) );
    } else if (strCommand == "getToken") {
        // parse the JSON
        bool parse = reader.parse(strParam, obj);

        if (!parse) {
            //fprintf(stderr, "%s", "error parsing\n");
            return "unable to parse options";
        }
        event_id = obj["_eventId"].asString();
        std::string provider = obj["provider"].asString();
        std::string tokenType = obj["tokenType"].asString();
        const std::string appliesTo = obj["appliesTo"].asString();

        GetToken(provider, tokenType, appliesTo);
    } else if (strCommand == "clearToken") {
            // parse the JSON
        bool parse = reader.parse(strParam, obj);

        if (!parse) {
            //fprintf(stderr, "%s", "error parsing\n");
            return "unable to parse options";
        }
        event_id = obj["_eventId"].asString();
        std::string provider = obj["provider"].asString();
        std::string tokenType = obj["tokenType"].asString();
        const std::string appliesTo = obj["appliesTo"].asString();

        ClearToken(provider, tokenType, appliesTo);
    } else if (strCommand == "getProperties") {
        // parse the JSON
        bool parse = reader.parse(strParam, obj);
        if (!parse) {
            //fprintf(stderr, "%s", "error parsing\n");
            return "unable to parse options";
        }
        event_id = obj["_eventId"].asString();
        std::string provider = obj["provider"].asString();
        int propertyType = obj["propertyType"].asInt();
        int numProps = obj["numProps"].asInt();
        const std::string userProps = obj["userProperties"].asString();
        GetProperties(provider, propertyType, numProps, userProps);
    } else if (strCommand == "getData") {
        // parse the JSON
        bool parse = reader.parse(strParam, obj);
        if (!parse) {
            //fprintf(stderr, "%s", "error parsing\n");
            return "unable to parse options";
        }
        event_id = obj["_eventId"].asString();
        std::string provider = obj["provider"].asString();
        int dataType = obj["dataType"].asInt();
        int dataFlags = obj["dataFlags"].asInt();
        const std::string dataName = obj["dataName"].asString();
        GetData(provider, dataType, dataFlags, dataName);
    } else if (strCommand == "createData") {
        // parse the JSON
        bool parse = reader.parse(strParam, obj);
        if (!parse) {
            //fprintf(stderr, "%s", "error parsing\n");
            return "unable to parse options";
        }
        event_id = obj["_eventId"].asString();
        std::string provider = obj["provider"].asString();
        int dataType = obj["dataType"].asInt();
        int dataFlags = obj["dataFlags"].asInt();
        const std::string dataName = obj["dataName"].asString();
        const std::string dataValue = obj["dataValue"].asString();
        CreateData(provider, dataType, dataFlags, dataName, dataValue);
    } else if (strCommand == "deleteData") {
        // parse the JSON
        bool parse = reader.parse(strParam, obj);
        if (!parse) {
            //fprintf(stderr, "%s", "error parsing\n");
            return "unable to parse options";
        }
        event_id = obj["_eventId"].asString();
        std::string provider = obj["provider"].asString();
        int dataType = obj["dataType"].asInt();
        int dataFlags = obj["dataFlags"].asInt();
        const std::string dataName = obj["dataName"].asString();
        DeleteData(provider, dataType, dataFlags, dataName);
    } else if (strCommand == "setData") {
        // parse the JSON
        bool parse = reader.parse(strParam, obj);
        if (!parse) {
            //fprintf(stderr, "%s", "error parsing\n");
            return "unable to parse options";
        }
        event_id = obj["_eventId"].asString();
        std::string provider = obj["provider"].asString();
        int dataType = obj["dataType"].asInt();
        int dataFlags = obj["dataFlags"].asInt();
        const std::string dataName = obj["dataName"].asString();
        const std::string dataValue = obj["dataValue"].asString();
        SetData(provider, dataType, dataFlags, dataName, dataValue);
    } else if (strCommand == "listData") {
        // parse the JSON
        bool parse = reader.parse(strParam, obj);
        if (!parse) {
            //fprintf(stderr, "%s", "error parsing\n");
            return "unable to parse options";
        }
        event_id = obj["_eventId"].asString();
        std::string provider = obj["provider"].asString();
        int dataType = obj["dataType"].asInt();
        int dataFlags = obj["dataFlags"].asInt();
        ListData(provider, dataType, dataFlags);
    } else if (strCommand == "challenge") {
        // parse the JSON
        bool parse = reader.parse(strParam, obj);
        if (!parse) {
            //fprintf(stderr, "%s", "error parsing\n");
            return "unable to parse options";
        }
        event_id = obj["_eventId"].asString();
        std::string provider = obj["provider"].asString();
        int challengeType = obj["challengeType"].asInt();
        int challengeFlags = obj["challengeFlags"].asInt();
        Challenge(provider, challengeType, challengeFlags);
    } else if (strCommand == "registerNotifier") {
        // parse the JSON
        bool parse = reader.parse(strParam, obj);
        if (!parse) {
            //fprintf(stderr, "%s", "error parsing\n");
            return "unable to parse options";
        }
        event_id = obj["_eventId"].asString();
        std::string provider = obj["provider"].asString();
        int notifierType = obj["notifierType"].asInt();
        int notifierFlags = obj["notifierFlags"].asInt();
        std::string notifierName = obj["notifierName"].asString();
        RegisterNotifier(provider, notifierType, notifierFlags, notifierName);
    }

    return "";
}
Esempio n. 17
0
int lt_op ( )
{
    Matrix	a;
    Matrix	b;
    Matrix	c;
    double	lvalue;
    double	rvalue;
    descriptor *left;
    descriptor *right;
    descriptor *result;
    descriptor	temp;
    int		type_error;
    int		status;
    int		cmp;
    unsigned	i;
    unsigned	j;


    right = pop ( );
    result = top ( );
    temp = *result;
    left = &temp;

    left = deref (left);
    right = deref (right);

    if (D_Type (left) != T_String || D_Type (right) != T_String) {
	left = CoerceData (left, T_Double);
	right = CoerceData (right, T_Double);
    }


    status = 0;
    type_error = F_False;


    switch (D_Type (left)) {
    case T_Double:
	switch (D_Type (right)) {
	case T_Double:
	    D_Type    (result) = T_Double;
	    D_Temp    (result) = F_False;
	    D_Trapped (result) = F_False;
	    D_Double  (result) = dbllit (*D_Double (left) < *D_Double (right));
	    break;


	case T_Matrix:
	    a = D_Matrix (right);
	    CreateData (result, left, right, T_Matrix, Mrows (a), Mcols (a));
	    b = D_Matrix (result);
	    lvalue = *D_Double (left);
	    for (i = 1; i <= Mrows (a); i ++)
		for (j = 1; j <= Mcols (a); j ++)
		    sdata (b, i, j) = lvalue < mdata (a, i, j);
	    break;


	default:
	    type_error = F_True;
	    break;
	}
	break;


    case T_Matrix:
	switch (D_Type (right)) {
	case T_Double:
	    a = D_Matrix (left);
	    CreateData (result, left, right, T_Matrix, Mrows (a), Mcols (a));
	    b = D_Matrix (result);
	    rvalue = *D_Double (right);
	    for (i = 1; i <= Mrows (a); i ++)
		for (j = 1; j <= Mcols (a); j ++)
		    sdata (b, i, j) = mdata (a, i, j) < rvalue;
	    break;


	case T_Matrix:
	    a = D_Matrix (left);
	    b = D_Matrix (right);
	    CreateData (result, left, right, T_Matrix, Mrows (a), Mcols (a));
	    c = D_Matrix (result);
	    if ((status = CompareLTMatrices (c, a, b)))
		MatrixError ("<", a, b, status, F_False);
	    break;


	default:
	    type_error = F_True;
	    break;
	}
	break;


    case T_String:
	switch (D_Type (right)) {
	case T_String:
	    cmp = strcmp (*D_String (left), *D_String (right));
	    D_Type    (result) = T_Double;
	    D_Temp    (result) = F_False;
	    D_Trapped (result) = F_False;
	    D_Double  (result) = dbllit (cmp < 0);
	    break;


	default:
	    type_error = F_True;
	    break;
	}
	break;


    default:
	type_error = F_True;
	break;
    }


    if (type_error == F_True)
	TypeError ("<", left, right, NULL, F_False);


    RecycleData (left);
    RecycleData (right);
    d_printf ("lt ans =\n");
    d_PrintData (result);

    return type_error == F_True || status != 0;
}
Esempio n. 18
0
int ne_op ( )
{
    Matrix	a;
    Matrix	b;
    Matrix	c;
    double	lvalue;
    double	rvalue;
    descriptor *left;
    descriptor *right;
    descriptor *result;
    descriptor	temp;
    int		type_error;
    int		status;
    int		cmp;
    unsigned	i;
    unsigned	j;


    right = pop ( );
    result = top ( );
    temp = *result;
    left = &temp;

    left = deref (left);
    right = deref (right);

    if (D_Type (left) != T_String || D_Type (right) != T_String) {
	left = CoerceData (left, T_Double);
	right = CoerceData (right, T_Double);
    }


    status = 0;
    type_error = F_False;


    switch (D_Type (left)) {
    case T_Double:
	switch (D_Type (right)) {
	case T_Double:
	    D_Type    (result) = T_Double;
	    D_Temp    (result) = F_False;
	    D_Trapped (result) = F_False;
	    D_Double  (result) = dbllit (*D_Double (left) != *D_Double (right));
	    break;


	case T_Matrix:
	    a = D_Matrix (right);
	    CreateData (result, left, right, T_Matrix, Mrows (a), Mcols (a));
	    b = D_Matrix (result);
	    lvalue = *D_Double (left);
	    for (i = 1; i <= Mrows (a); i ++)
		for (j = 1; j <= Mcols (a); j ++)
		    sdata (b, i, j) = lvalue != mdata (a, i, j);
	    break;


	default:
	    type_error = F_True;
	    break;
	}
	break;


    case T_Matrix:
	switch (D_Type (right)) {
	case T_Double:
	    a = D_Matrix (left);
	    CreateData (result, left, right, T_Matrix, Mrows (a), Mcols (a));
	    b = D_Matrix (result);
	    rvalue = *D_Double (right);
	    for (i = 1; i <= Mrows (a); i ++)
		for (j = 1; j <= Mcols (a); j ++)
		    sdata (b, i, j) = mdata (a, i, j) != rvalue;
	    break;


	case T_Matrix:
	    a = D_Matrix (left);
	    b = D_Matrix (right);
	    CreateData (result, left, right, T_Matrix, Mrows (a), Mcols (a));
	    c = D_Matrix (result);
	    if ((status = CompareNEQMatrices (c, a, b)))
		MatrixError ("!=", a, b, status, F_False);
	    break;


	default:
	    type_error = F_True;
	    break;
	}
	break;


    case T_String:
	switch (D_Type (right)) {
	case T_String:
	    cmp = strcmp (*D_String (left), *D_String (right));
	    D_Type    (result) = T_Double;
	    D_Temp    (result) = F_False;
	    D_Trapped (result) = F_False;
	    D_Double  (result) = dbllit (cmp != 0);
	    break;


	default:
	    type_error = F_True;
	    break;
	}
	break;


    case T_Function:
    case T_Intrinsic:
    case T_Array:
    case T_Pair:
	if (D_Type (left) == D_Type (right)) {
	    D_Type    (result) = T_Double;
	    D_Temp    (result) = F_False;
	    D_Trapped (result) = F_False;
	    D_Double  (result) = dbllit (D_Pointer (left) == D_Pointer (right));
	} else
	    type_error = F_False;
	break;


    case T_Constraint:
    case T_Definition:
    case T_Element:
    case T_Force:
    case T_Load:
    case T_Material:
    case T_Node:
    case T_Stress:
    case T_External:
	if (D_Type (left) == D_Type (right)) {
	    cmp = *(void **) D_Pointer (left) != *(void **) D_Pointer (right);
	    D_Type    (result) = T_Double;
	    D_Temp    (result) = F_False;
	    D_Trapped (result) = F_False;
	    D_Double  (result) = dbllit (cmp);
	} else if (D_Type (right) == T_Null) {
	    cmp = *(void **) D_Pointer (left) != NULL;
	    D_Type    (result) = T_Double;
	    D_Temp    (result) = F_False;
	    D_Trapped (result) = F_False;
	    D_Double  (result) = dbllit (cmp);
	} else
	    type_error = F_True;
	break;


    case T_Null:
	switch (D_Type (right)) {
	case T_Constraint:
	case T_Definition:
	case T_Element:
	case T_Force:
	case T_Load:
	case T_Material:
	case T_Node:
	case T_Stress:
	case T_External:
	    cmp = *(void **) D_Pointer (right) != NULL;
	    D_Type    (result) = T_Double;
	    D_Temp    (result) = F_False;
	    D_Trapped (result) = F_False;
	    D_Double  (result) = dbllit (cmp);
	    break;


	default:
	    type_error = F_True;
	    break;
	}
	break;


    default:
	type_error = F_True;
	break;
    }


    if (type_error == F_True)
	TypeError ("!=", left, right, NULL, F_False);


    RecycleData (left);
    RecycleData (right);
    d_printf ("ne ans =\n");
    d_PrintData (result);

    return type_error == F_True || status != 0;
}
MemoryLeakWarning::MemoryLeakWarning()
{
	_latest = this; 
	CreateData();	
}
Esempio n. 20
0
int gen_op ( )
{
    Matrix	a;
    Matrix	b;
    void       *ptr;
    descriptor *d;
    descriptor *v;
    descriptor *var;
    descriptor *index;
    descriptor *vector;
    descriptor	temp;
    double	value;
    Address	increment;
    Array	arr;
    int		fail;
    unsigned	offset;
    unsigned	i;
    unsigned	c;
    unsigned	r;


    index = ntop (0);
    vector = ntop (1);
    var = ntop (2);

    offset = fetch (pc ++).ival;


    if (D_Type (index) == T_Double) {
        if (!assignable (var)) {
            TypeError ("cannot assign to", NULL, var, NULL, F_False);
            return 1;
        }

        d = &temp;
        D_Type    (d) = T_Null;
        D_Temp    (d) = F_False;
        D_Trapped (d) = F_False;
        D_Pointer (d) = NULL;

        v = CoerceData (vector, T_Double);
        AssignData (d, &v);
        RecycleData (v);
        D_Temp (d) = F_False;

        d_printf ("d = %s %p\n", D_TypeName (d), D_Pointer (d));

        switch (D_Type (d)) {
        case T_Double:
        case T_Matrix:
        case T_Array:
        case T_Null:
            break;


        default:
            TypeError ("cannot index", NULL, d, NULL, F_False);
            return 1;
        }

        *vector = *d;

        D_Type (index) = T_Row;
        D_Row (index) = 0;
    }

    d_printf ("vector = %s %p\n", D_TypeName (vector), D_Pointer (vector));
    var = deref (var);
    fail = F_False;


    switch (D_Type (vector)) {
    case T_Double:
        if (D_Row (index) ++ == 0)
            AssignData (var, &vector);
        else
            fail = F_True;
        break;


    case T_Matrix:
        a = D_Matrix (vector);
        d = &temp;
        D_Temp	  (d) = F_False;
        D_Trapped (d) = F_False;

        if (Mrows (a) == 1) {
            if (++ D_Row (index) <= Mcols (a)) {
                D_Type   (d) = T_Double;
                D_Double (d) = &value;
                value = mdata (a, 1, D_Row (index));
                AssignData (var, &d);
            } else
                fail = F_True;

        } else if (Mcols (a) == 1) {
            if (++ D_Row (index) <= Mrows (a)) {
                D_Type   (d) = T_Double;
                D_Double (d) = &value;
                value = mdata (a, D_Row (index), 1);
                AssignData (var, &d);
            } else
                fail = F_True;

        } else {
            if (++ D_Row (index) <= Mcols (a)) {
                d_printf ("indexing matrix\n");
                r = Mrows (a);
                c = D_Row (index);

                FreeData (var);
                CreateData (var, NULL, NULL, T_Matrix, r, 1);
                D_Temp (var) = F_False;
                b = D_Matrix (var);

                for (i = 1; i <= r; i ++)
                    sdata (b, i, 1) = mdata (a, i, c);
            } else
                fail = F_True;
        }
        break;


    case T_Array:
        arr = D_Array (vector);
        d = &temp;

        if (++ D_Row (index) <= arr -> length) {
            increment = D_Row (index) * arr -> elt_size;
            ptr = (void *) ((char *) arr -> ptr + increment);

            D_Type    (d) = arr -> type;
            D_Temp    (d) = F_False;
            D_Trapped (d) = F_False;
            D_Pointer (d) = ptr;
            AssignData (var, &d);
        } else
            fail = F_True;
        break;


    case T_Null:
        fail = F_True;
        break;
    }


    /* After assignment the variable is certainly not temporary.  Its trapped
       status remains as before: if it was trapped then AssignData() called
       the trap handler which didn't change the status.  If it wasn't then
       AssignData() left the status alone. */

    D_Temp (var) = F_False;

    if (fail == F_True) {
        pop ( );
        FreeData (pop ( ));		/* free the privately owned vector */
        pop ( );

        d = push ( );
        D_Type	  (d) = T_Null;
        D_Temp	  (d) = F_False;
        D_Trapped (d) = F_False;
        D_Pointer (d) = NULL;

        pc += offset;
        d_printf ("failing\n");
    }

    return 0;
}
Esempio n. 21
0
bool ff::Value::Convert(Type type, Value **ppValue) const
{
	assertRetVal(ppValue, false);
	*ppValue = nullptr;

	if (type == GetType())
	{
		*ppValue = GetAddRef(const_cast<Value *>(this));
		return true;
	}

	wchar_t buf[256];

	switch (GetType())
	{
	case Type::Null:
		switch (type)
		{
		case Type::String:
			CreateString(String(L"null"), ppValue);
			break;
		}
		break;

	case Type::Bool:
		switch (type)
		{
		case Type::Double:
			CreateDouble(AsBool() ? 1.0 : 0.0, ppValue);
			break;

		case Type::Float:
			CreateFloat(AsBool() ? 1.0f : 0.0f, ppValue);
			break;

		case Type::Int:
			CreateInt(AsBool() ? 1 : 0, ppValue);
			break;

		case Type::String:
			CreateString(AsBool() ? String(L"true") : String(L"false"), ppValue);
			break;
		}
		break;

	case Type::Double:
		switch (type)
		{
		case Type::Bool:
			CreateBool(AsDouble() != 0, ppValue);
			break;

		case Type::Float:
			CreateFloat((float)AsDouble(), ppValue);
			break;

		case Type::Int:
			CreateInt((int)AsDouble(), ppValue);
			break;

		case Type::String:
			_snwprintf_s(buf, _countof(buf), _TRUNCATE, L"%g", AsDouble());
			CreateString(String(buf), ppValue);
			break;
		}
		break;

	case Type::Float:
		switch (type)
		{
		case Type::Bool:
			CreateBool(AsFloat() != 0, ppValue);
			break;

		case Type::Double:
			CreateDouble((double)AsFloat(), ppValue);
			break;

		case Type::Int:
			CreateInt((int)AsFloat(), ppValue);
			break;

		case Type::String:
			_snwprintf_s(buf, _countof(buf), _TRUNCATE, L"%g", AsFloat());
			CreateString(String(buf), ppValue);
			break;
		}
		break;

	case Type::Int:
		switch (type)
		{
		case Type::Bool:
			CreateBool(AsInt() != 0, ppValue);
			break;

		case Type::Double:
			CreateDouble((double)AsInt(), ppValue);
			break;

		case Type::Float:
			CreateFloat((float)AsInt(), ppValue);
			break;

		case Type::String:
			_snwprintf_s(buf, _countof(buf), _TRUNCATE, L"%d", AsInt());
			CreateString(String(buf), ppValue);
			break;
		}
		break;

	case Type::Point:
		switch (type)
		{
		case Type::String:
			_snwprintf_s(buf, _countof(buf), _TRUNCATE, L"(%d,%d)", AsPoint().x, AsPoint().y);
			CreateString(String(buf), ppValue);
			break;
		}
		break;

	case Type::PointF:
		switch (type)
		{
		case Type::String:
			_snwprintf_s(buf, _countof(buf), _TRUNCATE, L"(%g,%g)", AsPointF().x, AsPointF().y);
			CreateString(String(buf), ppValue);
			break;
		}
		break;

	case Type::Rect:
		switch (type)
		{
		case Type::String:
			_snwprintf_s(buf, _countof(buf), _TRUNCATE, L"(%d,%d,%d,%d)",
				AsRect().left, AsRect().top, AsRect().right, AsRect().bottom);
			CreateString(String(buf), ppValue);
			break;
		}
		break;

	case Type::RectF:
		switch (type)
		{
		case Type::String:
			_snwprintf_s(buf, _countof(buf), _TRUNCATE, L"(%g,%g,%g,%g)",
				AsRectF().left, AsRectF().top, AsRectF().right, AsRectF().bottom);
			CreateString(String(buf), ppValue);
			break;
		}
		break;

	case Type::String:
		switch (type)
		{
		case Type::Bool:
			if (AsString().empty() || AsString() == L"false" || AsString() == L"no" || AsString() == L"0")
			{
				CreateBool(false, ppValue);
			}
			else if (AsString() == L"true" || AsString() == L"yes" || AsString() == L"1")
			{
				CreateBool(true, ppValue);
			}
			break;

		case Type::Double:
			{
				const wchar_t *start = AsString().c_str();
				wchar_t *end = nullptr;
				double val = wcstod(start, &end);

				if (end > start && !*end)
				{
					CreateDouble(val, ppValue);
				}
			} break;

		case Type::Float:
			{
				const wchar_t *start = AsString().c_str();
				wchar_t *end = nullptr;
				double val = wcstod(start, &end);

				if (end > start && !*end)
				{
					CreateFloat((float)val, ppValue);
				}
			} break;

		case Type::Int:
			{
				const wchar_t *start = AsString().c_str();
				wchar_t *end = nullptr;
				long val = wcstol(start, &end, 10);

				if (end > start && !*end)
				{
					CreateInt((int)val, ppValue);
				}
			} break;

		case Type::Guid:
			{
				GUID guid;
				if (StringToGuid(AsString(), guid))
				{
					CreateGuid(guid, ppValue);
				}
			} break;
		}
		break;

	case Type::Object:
		switch (type)
		{
		case Type::Bool:
			CreateBool(AsObject() != nullptr, ppValue);
			break;
		}
		break;

	case Type::Guid:
		switch (type)
		{
		case Type::String:
			CreateString(StringFromGuid(AsGuid()), ppValue);
			break;
		}
		break;

	case Type::Data:
		switch (type)
		{
		case Type::SavedData:
			{
				ff::ComPtr<ff::ISavedData> savedData;
				if (ff::CreateLoadedDataFromMemory(AsData(), false, &savedData))
				{
					CreateSavedData(savedData, ppValue);
				}
			}
			break;
		}
		break;

	case Type::SavedData:
		switch (type)
		{
		case Type::Data:
			{
				ff::ComPtr<ff::ISavedData> savedData;
				if (AsSavedData()->Clone(&savedData))
				{
					ff::ComPtr<ff::IData> data = savedData->Load();
					if (data)
					{
						CreateData(data, ppValue);
					}
				}
			}
			break;
		}
		break;

	case Type::Dict:
		switch (type)
		{
		case Type::Data:
		case Type::SavedData:
		case Type::SavedDict:
			{
				ff::ComPtr<ff::IData> data;
				ff::ComPtr<ff::ISavedData> savedData;

				if (ff::SaveDict(AsDict(), true, false, &data))
				{
					if (type == Type::Data)
					{
						CreateData(data, ppValue);
					}
					else if (ff::CreateLoadedDataFromMemory(data, true, &savedData))
					{
						if (type == Type::SavedData)
						{
							CreateSavedData(savedData, ppValue);
						}
						else
						{
							CreateSavedDict(savedData, ppValue);
						}
					}
				}
			}
			break;
		}
		break;

	case Type::SavedDict:
		switch (type)
		{
		case Type::Data:
			{
				ff::ComPtr<ff::ISavedData> savedData;
				if (AsSavedData()->Clone(&savedData))
				{
					ff::ComPtr<ff::IData> data = savedData->Load();
					if (data)
					{
						CreateData(data, ppValue);
					}
				}
			}
			break;

		case Type::SavedData:
			CreateSavedData(AsSavedData(), ppValue);
			break;

		case Type::Dict:
			{
				ff::ComPtr<ff::ISavedData> savedData;
				if (AsSavedData()->Clone(&savedData))
				{
					ff::ComPtr<ff::IData> data = savedData->Load();
					ff::ComPtr<ff::IDataReader> dataReader;
					Dict dict;

					if (data && ff::CreateDataReader(data, 0, &dataReader) && ff::LoadDict(dataReader, dict))
					{
						CreateDict(std::move(dict), ppValue);
					}
				}
			}
			break;
		}
		break;

	case Type::Resource:
		AsResource()->GetValue()->Convert(type, ppValue);
		break;

	case Type::IntVector:
		switch (type)
		{
		case Type::Point:
			if (AsIntVector().Size() == 2)
			{
				PointInt point(
					AsIntVector().GetAt(0),
					AsIntVector().GetAt(1));
				CreatePoint(point, ppValue);
			}
			break;

		case Type::Rect:
			if (AsIntVector().Size() == 4)
			{
				RectInt rect(
					AsIntVector().GetAt(0),
					AsIntVector().GetAt(1),
					AsIntVector().GetAt(2),
					AsIntVector().GetAt(3));
				CreateRect(rect, ppValue);
			}
			break;
		}
		break;

	case Type::FloatVector:
		switch (type)
		{
		case Type::PointF:
			if (AsFloatVector().Size() == 2)
			{
				PointFloat point(
					AsFloatVector().GetAt(0),
					AsFloatVector().GetAt(1));
				CreatePointF(point, ppValue);
			}
			break;

		case Type::RectF:
			if (AsFloatVector().Size() == 4)
			{
				RectFloat rect(
					AsFloatVector().GetAt(0),
					AsFloatVector().GetAt(1),
					AsFloatVector().GetAt(2),
					AsFloatVector().GetAt(3));
				CreateRectF(rect, ppValue);
			}
			break;
		}
		break;

	case Type::ValueVector:
		switch (type)
		{
		case Type::Point:
			if (AsValueVector().Size() == 2)
			{
				ValuePtr newValues[2];
				const Vector<ValuePtr> &values = AsValueVector();
				if (values[0]->Convert(Type::Int, &newValues[0]) &&
					values[1]->Convert(Type::Int, &newValues[1]))
				{
					CreatePoint(PointInt(newValues[0]->AsInt(), newValues[1]->AsInt()), ppValue);
				}
			}
			break;

		case Type::PointF:
			if (AsValueVector().Size() == 2)
			{
				ValuePtr newValues[2];
				const Vector<ValuePtr> &values = AsValueVector();
				if (values[0]->Convert(Type::Float, &newValues[0]) &&
					values[1]->Convert(Type::Float, &newValues[1]))
				{
					CreatePointF(PointFloat(newValues[0]->AsFloat(), newValues[1]->AsFloat()), ppValue);
				}
			}
			break;

		case Type::Rect:
			if (AsValueVector().Size() == 4)
			{
				ValuePtr newValues[4];
				const Vector<ValuePtr> &values = AsValueVector();
				if (values[0]->Convert(Type::Int, &newValues[0]) &&
					values[1]->Convert(Type::Int, &newValues[1]) &&
					values[2]->Convert(Type::Int, &newValues[2]) &&
					values[3]->Convert(Type::Int, &newValues[3]))
				{
					CreateRect(RectInt(
						newValues[0]->AsInt(),
						newValues[1]->AsInt(),
						newValues[2]->AsInt(),
						newValues[3]->AsInt()), ppValue);
				}
			}
			break;

		case Type::RectF:
			if (AsValueVector().Size() == 4)
			{
				ValuePtr newValues[4];
				const Vector<ValuePtr> &values = AsValueVector();
				if (values[0]->Convert(Type::Float, &newValues[0]) &&
					values[1]->Convert(Type::Float, &newValues[1]) &&
					values[2]->Convert(Type::Float, &newValues[2]) &&
					values[3]->Convert(Type::Float, &newValues[3]))
				{
					CreateRectF(RectFloat(
						newValues[0]->AsFloat(),
						newValues[1]->AsFloat(),
						newValues[2]->AsFloat(),
						newValues[3]->AsFloat()), ppValue);
				}
			}
			break;

		case Type::StringVector:
			{
				bool valid = true;
				Vector<String> newValues;
				const Vector<ValuePtr> &values = AsValueVector();
				for (ValuePtr oldValue : values)
				{
					ValuePtr newValue;
					valid = oldValue->Convert(Type::String, &newValue);
					if (valid)
					{
						newValues.Push(newValue->AsString());
					}
					else
					{
						break;
					}
				}

				if (valid)
				{
					CreateStringVector(std::move(newValues), ppValue);
				}
			}
			break;

		case Type::IntVector:
			{
				bool valid = true;
				Vector<int> newValues;
				const Vector<ValuePtr> &values = AsValueVector();
				for (ValuePtr oldValue : values)
				{
					ValuePtr newValue;
					valid = oldValue->Convert(Type::Int, &newValue);
					if (valid)
					{
						newValues.Push(newValue->AsInt());
					}
					else
					{
						break;
					}
				}

				if (valid)
				{
					CreateIntVector(std::move(newValues), ppValue);
				}
			}
			break;

		case Type::DoubleVector:
			{
				bool valid = true;
				Vector<double> newValues;
				const Vector<ValuePtr> &values = AsValueVector();
				for (ValuePtr oldValue : values)
				{
					ValuePtr newValue;
					valid = oldValue->Convert(Type::Double, &newValue);
					if (valid)
					{
						newValues.Push(newValue->AsDouble());
					}
					else
					{
						break;
					}
				}

				if (valid)
				{
					CreateDoubleVector(std::move(newValues), ppValue);
				}
			}
			break;

		case Type::FloatVector:
			{
				bool valid = true;
				Vector<float> newValues;
				const Vector<ValuePtr> &values = AsValueVector();
				for (ValuePtr oldValue : values)
				{
					ValuePtr newValue;
					valid = oldValue->Convert(Type::Float, &newValue);
					if (valid)
					{
						newValues.Push(newValue->AsFloat());
					}
					else
					{
						break;
					}
				}

				if (valid)
				{
					CreateFloatVector(std::move(newValues), ppValue);
				}
			}
			break;
		}
		break;
	}

	if (*ppValue)
	{
		return true;
	}

	return false;
}
Esempio n. 22
0
bool Compiler::Compile( const std::string& f, VM::Data& data )
{
	// System call
	AddFunction( VM::SYS_PRINT, TYPE_VOID, "print", "s" );
	AddFunction( VM::SYS_TOSTR, TYPE_STRING, "str", "i" );

	AddFunction( VM::SYS_FLOAT_TO_INT, TYPE_INTEGER, "FtoI", "f" );		// int FtoI( float );
	AddFunction( VM::SYS_INT_TO_FLOAT, TYPE_FLOAT, "ItoF", "i" );		// float ItoF( int );

	AddFunction( VM::SYS_SIN, TYPE_FLOAT, "sin", "f" );					// float sin( rad );
	AddFunction( VM::SYS_COS, TYPE_FLOAT, "cos", "f" );					// float cos( rad );
	AddFunction( VM::SYS_ATAN2, TYPE_FLOAT, "atan2", "ff" );			// float atan2( y, x );

	AddFunction( VM::SYS_DEG_TO_RAD, TYPE_FLOAT, "DegToRad", "f" );		// float DegToRad();

	AddFunction( VM::SYS_GET_PLAYER_POSX, TYPE_FLOAT, "GetPlayerPosX", "" );				// float GetPlayerPosX();
	AddFunction( VM::SYS_GET_PLAYER_POSY, TYPE_FLOAT, "GetPlayerPosY", "" );				// float GetPlayerPosY();
	AddFunction( VM::SYS_GET_RANDOM_F, TYPE_FLOAT, "GetRandF", "" );							// float GatRand();
	AddFunction( VM::SYS_ADD_SCORE, TYPE_VOID, "AddScore", "i" );							// void AddScore( score );

	AddFunction( VM::SYS_PLAY_SE, TYPE_VOID, "PlaySE", "i" );			// void PlaySE( id );
	AddFunction( VM::SYS_STOP_SE, TYPE_VOID, "StopSE", "i" );			// void StopSE( id );
	AddFunction( VM::SYS_PLAY_BGM, TYPE_VOID, "PlayBGM", "i" );	// void PlayBGM( id );
	AddFunction( VM::SYS_STOP_BGM, TYPE_VOID, "StopBGM", "i" );	// void StopBGM( id );

	// System call for enemy.
	AddFunction( VM::SYS_ENEMY_GET_POSX, TYPE_FLOAT, "GetEnemyPosX", "" );				// float GetEnemyPosX();
	AddFunction( VM::SYS_ENEMY_GET_POSY, TYPE_FLOAT, "GetEnemyPosY", "" );				// float GetEnemyPosY();
	AddFunction( VM::SYS_ENEMY_GET_HP, TYPE_INTEGER, "GetEnemyHP", "" );					// int GetEnemyHP();
	AddFunction( VM::SYS_ENEMY_GET_SPEED, TYPE_INTEGER, "GetEnemySpeed", "" );				// int GetEnemySpeed();
	AddFunction( VM::SYS_ENEMY_GET_COUNTER, TYPE_INTEGER, "GetEnemyCounter", "" );			// int GetEnemyCounter();
	AddFunction( VM::SYS_ENEMY_GET_COUNTER_F, TYPE_FLOAT, "GetEnemyCounterF", "" );			// float GetEnemyCounterF();
	AddFunction( VM::SYS_ENEMY_SET_ANGLE, TYPE_INTEGER, "GetEnemyAngle", "" );				// int GetEnemyAngle();
	AddFunction( VM::SYS_ENEMY_SET_POS, TYPE_VOID, "SetEnemyPos", "ff" );					// void SetEnemyPos( x, y );
	AddFunction( VM::SYS_ENEMY_SET_ANGLE, TYPE_VOID, "SetEnemyAngle", "i" );				// void SetEnemyAngle( angle );
	AddFunction( VM::SYS_ENEMY_SET_SPEED, TYPE_VOID, "SetEnemySpeed", "i" );				// void SetEnemySpeed( speed );
	AddFunction( VM::SYS_ENEMY_SET_HP, TYPE_VOID, "SetEnemyHP", "i" );						// void SetEnemyHP( hp );
	AddFunction( VM::SYS_ENEMY_SET_IMAGE, TYPE_VOID, "SetEnemyImgID", "i" );				// void SetEnemyImage( texture_id );
	AddFunction( VM::SYS_ENEMY_SET_COLLISION_RADIUS, TYPE_VOID, "SetEnemyCollisionRadius", "f" );		// void SetEnemyCollisionRadius( radius );
	AddFunction( VM::SYS_ENEMY_SET_SCORE, TYPE_VOID, "SetEnemyScore", "i" );							// void SetEnemyScore( score );
	AddFunction( VM::SYS_ENEMY_CREATE_SHOT_1, TYPE_VOID, "CreateEnemyShot1", "fffffi" );	// void CreateEnemyShot1( x, y, speed, angle, radius, texture_id );
	AddFunction( VM::SYS_ENEMY_CREATE_EFFECT_1, TYPE_VOID, "CreateEffect1", "ffi" );		// void CreateEffect1( x, y, texture_id );
	AddFunction( VM::SYS_ENEMY_SET_BOSS_FLAG, TYPE_VOID, "SetEnemyBossFlag", "i" );			// void SetEnemyBossFlag( flag );

	// System call for stage.
	AddFunction( VM::SYS_STAGE_ADD_ENEMY, TYPE_VOID, "AddEnemy", "i" );					// void AddEnemy( script_id );
	AddFunction( VM::SYS_STAGE_ADD_ENEMY_INIPOS, TYPE_VOID, "AddEnemyIniPos", "iff" );	// void AddEnemyIniPos( script_id, x, y );
	AddFunction( VM::SYS_STAGE_GET_FRAME, TYPE_INTEGER, "GetFrame", "" );				// int GetFrame();
	AddFunction( VM::SYS_STAGE_SET_FRAME, TYPE_VOID, "SetFrame", "i" );					// void SetFrame( frame );
	AddFunction( VM::SYS_UPDATE, TYPE_VOID, "Update", "" );								// void Update();

	// Global variables.
	m_Variables.push_back( ValueTable() );
	m_Variables[ 0 ].SetGlobal();

	// HALT operation is first operation.
	OpHalt();

	m_File = f;
	ScanBegin();						// Initialize scanner.
	yy::Parser parser( *this );			// Build parser.
	int result = parser.parse();		// Analyze grammer.
	ScanEnd();							// End scanner.

	if( result != 0 ){
		return false;
	}

	int codeSize = LabelSetting();		// Set address to label.
	CreateData( data, codeSize );		// Create binary.

	return m_ErrorCount == 0;
}
ribi::QtToolTestApproximatorXyzMainDialog::QtToolTestApproximatorXyzMainDialog(QWidget *parent) noexcept :
  QtHideAndShowDialog(parent),
  ui(new Ui::QtToolTestApproximatorXyzMainDialog),
  m_approximator(),
  m_data(CreateData())
{
  #ifndef NDEBUG
  Test();
  #endif
  ui->setupUi(this);

  //Set up the plots and curves
  GetPlot(0)->setTitle("Approximator, for z = 0.0");
  GetPlot(1)->setTitle("Approximator, for z = 0.5");
  GetPlot(2)->setTitle("Approximator, for z = 1.0");
  for (auto i=0; i!=m_n_curves; ++i)
  {
    const auto plot = GetPlot(i);
    plot->setAxisTitle(QwtPlot::xBottom,"X");
    plot->setAxisTitle(QwtPlot::yLeft,"Y");
    #ifdef _WIN32
    plot->setCanvasBackground(QBrush(QColor(255,255,255)));
    #else
    plot->setCanvasBackground(QColor(255,255,255));
    #endif

    const auto curve_values = GetCurveValues(i);
    assert(curve_values);
    curve_values->setTitle("Points");
    curve_values->attach(plot.get());
    curve_values->setStyle(QwtPlotCurve::Dots);
    curve_values->setPen(QPen(QColor(255,0,0),5));

    const auto curve_approximation = GetCurveApproximation(i);
    assert(curve_approximation);
    curve_approximation->setTitle("Approximation");
    curve_approximation->attach(plot.get());
    curve_approximation->setStyle(QwtPlotCurve::Dots);
    curve_approximation->setPen(QPen(QColor(0,0,255),3));

    //Add grid
    {
      QwtPlotGrid * const grid = new QwtPlotGrid;
      grid->setPen(QPen(QColor(128,128,128)));
      grid->attach(plot.get());
    }
    //Add zoomer
    {
      new QwtPlotZoomer(plot->canvas());
    }
    //Add legend
    {
      QwtLegend * const legend = new QwtLegend;
      legend->setFrameStyle(QFrame::Box|QFrame::Sunken);
      plot->insertLegend(legend, QwtPlot::RightLegend);
    }

    plot->setAxisScale(
      QwtPlot::xBottom,
      static_cast<double>(ui->box_int_x->minimum()),
      static_cast<double>(ui->box_int_x->maximum())
    );
    plot->setAxisScale(
      QwtPlot::yLeft,
      static_cast<double>(ui->box_double_y->minimum()),
      static_cast<double>(ui->box_double_y->maximum())
    );

    //Add to dialog
    assert(ui->verticalLayout->layout());
    ui->verticalLayout->layout()->addWidget(plot.get());
  }




  //Add some nice testing values
  ui->box_int_x->setValue(ui->box_int_x->minimum() / 2);
  ui->box_double_y->setValue(ui->box_double_y->maximum() / 2.0);
  on_button_clicked();

  ui->box_int_x->setValue(ui->box_int_x->minimum() / 4);
  ui->box_double_y->setValue(ui->box_double_y->minimum() / 2.0);
  on_button_clicked();

  ui->box_int_x->setValue(ui->box_int_x->maximum() / 4);
  ui->box_double_y->setValue(ui->box_double_y->maximum() / 2.0);
  on_button_clicked();

  ui->box_int_x->setValue(ui->box_int_x->maximum() / 2);
  ui->box_double_y->setValue(ui->box_double_y->minimum() / 2.0);
  on_button_clicked();

  ui->box_int_x->setValue(0);
  ui->box_double_y->setValue(0.0);
}