Esempio n. 1
0
int main(int argc, const char * argv[])
{
	vector < Passenger > passengersA;
	vector < Passenger > passengersB;
	
	passengersB.push_back(Passenger("Saffron",200,50
									,Coordinate(20,15,12,"Delphi System"),"I travel very light"));
	
	passengersB.push_back(Passenger("Mrs. Reynolds",150,120
									,Coordinate(2,2,2,"Europa Colony"),"Just trying to get back my husband!"));
	
	passengersB.push_back(Passenger("Yolanda",500,100
									,Coordinate(20,15,12,"Delphi System"),"I am a courier of sensitive items"));
	
	passengersB.push_back(Passenger("Tracey Smith ",200,50
									,Coordinate(20,15,12,"Delphi System"),"Just a guy"));
	
	passengersA.push_back(Passenger("Magistrate Higgins ",600,120
									,Coordinate(2,2,2,"Europa Colony"),"I am very important person"));
	
	passengersA.push_back(Passenger("Stitch Hessian",100,100
									,Coordinate(100,72,32,"3rd moon of Persephone"),"Just get me there"));
	
	
	
	Coordinate earth(0,0,0,"Earth");
	Coordinate europa(2,2,2,"Europa Colony");
	
	vector< CargoBin > cargo;
	cargo.push_back(*new CargoBin(ACR.WARP,10));
	cargo.push_back(*new CargoBin(ACR.ISOLC,10));
	
	vector< SpaceThing > stations;
	stations.push_back( *new SpaceThing("Far Point Station",100,100,cargo,europa,passengersB) );
	stations.push_back( *new SpaceThing("Mars Research Station",100,100,cargo,europa,passengersB) );
	stations.push_back( *new SpaceThing("Earth Space Command Station",100,100,cargo,europa,passengersB) );
	
//=====================================everything above line is dummy data, replace with an object factory
	
	//SpaceFactory factory = SpaceFactory("/Users/Neil/Dropbox/webster/COSC4260/IAWSCA/SpaceFactory/");
	//vector< SpaceThing > stations(randomStations(5));
	//Dosn't work. Don't know why. Memory error in buy. Can't hunt it down. Brain is fried, out of time.
	
	Ship ship(interface,"HMS Out Of Time",1000,2000,cargo,earth,passengersA);
	
	bool close;
	
	string choices[] = {//TODO: map menu options to function pointers??
		"TRADE CARGO", //1
		"LOAD PASSENGERS", //2
		"SET COURSE", //3
		"DOCK", //4
		"MANAGE CARGO", //5
		"VIEW PASSENGERS", //6
	};
	
	interface.message("Welcome to your space ship",true);
	vector < string >  mainMenu(begin_address(choices),end_address(choices));
	
	while (!close) {
		
		ship.displayHUD();
		
		int choice = interface.showMenu("\n\nMAIN MENU", mainMenu,"Please choose an action");
		
		switch (choice){
			case 1: ship.buy();
				break;
			case 2: ship.loadPassengers();
				break;
			case 3: ship.setNewCourse();
				break;
			case 4: ship.dock(stations);
				//stations = randomStations(5);
				break;
			case 5: ship.manageInventory();
				break;
			case 6:	ship.viewPassengers();
				break;
			case 7: close = interface.prompt("Are you sure you want to quit","Yes","No");
				break;
		}
	}
	quit();
    return 0;
}
Esempio n. 2
0
void Bptree::search_section(Table_info table,Attribute attribute,bool left_open,std::string left,bool right_open,std::string right,Address* begin,Address* end)
{
    uuid_t uu;
    int i;
    uuid_generate( uu );
    printf("\n");
    uuid_string_t  strc;
    uuid_unparse_upper(uu,strc);
    Address begin_address(table.database,strc,0);
    disk.create_file(begin_address);
    get_root(table, attribute);
    Address header_address(table.database,filename,0);
    Address_byte first_address;
    Block header;
    buffer->read_data(header_address, &header);
    header.get_block_data(ADDRESS_SIZE*2, ADDRESS_SIZE, first_address.byte);
    Address now_address(table.database,filename,first_address.address);
    Bptree_node *now_node=new_node();
    now_node->read_from(now_address);
    Key_type *left_key,*right_key;
    Block address_file_block;
    buffer->write_data(begin_address, &address_file_block);
    bool no_left=(left=="inf");
    bool no_right=(right=="inf");
    switch (attribute.type)
    {
        case SQL_INT:left_key=new Int_key;break;
        case SQL_FLOAT:left_key=new Float_key;break;
        case SQL_STRING:left_key=new String_key(attribute.size);break;
    }
    switch (attribute.type)
    {
        case SQL_INT:right_key=new Int_key;break;
        case SQL_FLOAT:right_key=new Float_key;break;
        case SQL_STRING:right_key=new String_key(attribute.size);break;
    }
    left_key->assign(left);
    right_key->assign(right);
    int now_int;
    if (!no_left)
    {
        search(table, attribute, left);
        if (left_open)
        {
            now_address=bigger_than_start_address;
            now_int=bigger_than_start_int;
        }
        else
        {
            now_address=not_smaller_than_start_address;
            now_int=not_smaller_than_start_int;
        }
    }
    else
    {
        now_int=0;
    }
    Address end_address;
    int end_int;
    if (!no_right)
    {
        search(table, attribute, right);
        if (right_open)
        {
            end_address=smaller_than_end_address;
            end_int=smaller_than_end_int;
        }
        else
        {
            end_address=not_bigger_than_end_address;
            end_int=not_bigger_than_end_int;
        }

    }
    else
    {
        end_address=Address(table.table_name,filename,0);
        end_int=0;
    }
    now_node->read_from(now_address);
    Address_byte temp_address;
    temp_address.address=begin_address.address_int();
    bool new_flag=true;
    *begin=Address(table.database,strc,0);
    *end=*begin;
    while(true)
    {
        Address tmp_address(table.database,strc,temp_address.address);
        if (now_address.file_offset==end_address.file_offset && now_int==end_int)
        {
            *end=tmp_address;
            break;
        }
        Block block;
        if (!new_flag)
        {
            buffer->read_data(tmp_address,&block);
        }
        else
        {
            new_flag=false;
        }
        Address_byte to_write_address;
        to_write_address.address=now_node->link[now_int].address_int();
        block.fill_block_data(tmp_address.block_offset, ADDRESS_SIZE, to_write_address.byte);
        buffer->write_data(tmp_address, &block);
        if (now_int+1==now_node->number)
        {
            now_address=now_node->link[now_node->max_count];
            now_int=0;
            if (now_address.file_offset!=0)
                now_node->read_from(now_address);
        }
        else
        {
            now_int++;
        }
        temp_address.address+=ADDRESS_SIZE;
        if (temp_address.address % BLOCK_SIZE==0)
        {
            new_flag=true;
        }
    }
    delete now_node;
    delete right_key;
    delete left_key;
    
}