Example #1
0
	std::string RawData::readString(size_t len) {
        std::vector<uint8_t> strVector;
        strVector.resize(len);
        readInto(&strVector[0], len);

        std::string ret(strVector.begin(), strVector.end());

        return ret;
	}
Example #2
0
	void RawData::read(std::string& outbuffer, int32_t size) {
		if ((size < 0) || ((size + m_index_current) > getDataLength())) {
			size = getDataLength() - m_index_current;
		}
		if (size == 0) {
			outbuffer = "";
			return;
		}

        outbuffer.resize(size);

        // read directly into string
        readInto(reinterpret_cast<uint8_t*>(&outbuffer[0]), size);
	}
Example #3
0
	std::vector<uint8_t> RawData::getDataInBytes() {
        // get the total file size
		uint32_t size = getDataLength();

        // create output vector
        std::vector<uint8_t> target;

        // resize vector to file size
        target.resize(size);

        // read bytes directly into vector
        readInto(&target[0], target.size());

		return target;
	}
Example #4
0
bool NormalFile::read(FileReaderState* &internalState, int64_t offset, ssize_t length, const unsigned char* &data /* out */, ssize_t &datasize /* out */, std::string &error /* out */) {
    NormalFileReaderState *state;
    if (nullptr == internalState) {
        internalState = state = new NormalFileReaderState();
    } else {
        state = dynamic_cast<NormalFileReaderState*>(internalState);
        assert(nullptr != state);
    }

    if (length > (ssize_t) sizeof(state->buf)) length = sizeof(state->buf);

    if (!readInto(internalState, offset, length, state->buf, error)) return false;

    data = state->buf;
    datasize = length;

    return true;
}
Example #5
0
int  main()
{

    LinkedList    list1;
	LinkedList	  list2;
    initList(&list1);
    showList(&list1);

	if(isEmpty(&list1))
	{
		insertItem(&list1,20);
		insertItem(&list1,50);
		insertItem(&list1,30);
		insertItem(&list1,10);
		insertItem(&list1,70);
	}
    showList(&list1);
	
	if(isEmpty(&list1))
	{
		printf("\nERROR: List is Empty\n");
		showList(&list1);
	}
	else
		showList(&list1);
	
	if(isMember(&list1,10))
		printf("\nValue 10 is in List1\n");
	else
		printf("\nValue 10 is NOT in List1\n");
	
	if(isMember(&list1,25))
		printf("\nValue 25 is in List1\n");
	else
		printf("\nValue 25 is NOT in List1\n");
	
	if(isMember(&list1,50))
		printf("\nValue 50 is in List1\n");
	else
		printf("\nValue 50 is NOT in List1\n");
	
	if(isMember(&list1,70))
		printf("\nValue 70 is in List1\n");
	else
		printf("\nValue 70 is NOT in List1\n");
// Part 7
	removeItem(&list1, 30);
	removeItem(&list1, 20);
	removeItem(&list1, 70);
// Part 8
	if(isEmpty(&list1))
	{
		printf("\nERROR: List is Empty\n");
		showList(&list1);
	}
	else
		showList(&list1);
// Part 10
	insertItem(&list1,80);
	insertItem(&list1,0);
	insertItem(&list1,35);	

// Part 11
	if(isEmpty(&list1))
	{
		printf("\nERROR: List is Empty\n");
		showList(&list1);
	}
	else
		showList(&list1);
// Part12
	removeItem(&list1, 40);
	removeItem(&list1, 10);

// Part 13
	if(isEmpty(&list1))
	{
		printf("\nERROR: List is Empty\n");
		showList(&list1);
	}
	else
		showList(&list1);

// Part 14
	removeItem(&list1, 80);
	removeItem(&list1, 50);
	removeItem(&list1, 35);	
	removeItem(&list1, 0);	
	
// Part 15
	if(isEmpty(&list1))
	{
		printf("\nERROR: List is Empty\n");
		showList(&list1);
	}
	else
		showList(&list1);
	

// Part 16 - 18
	initList(&list2);
	readInto(&list2);
	showList(&list2);

	return 0;
};
Example #6
0
//right-click the project and go to "Properties"
//C/C++ Build -> Settings -> Tool Settings -> GCC C++ Compiler -> Miscellaneous -> Other Flags. Put -std=c++0x at the end
int main()
{
	int userChoice;			// IN           - User(s) menu selection
	int mainChoice;			// IN			- User(s) main menu selection
	int adminLogin;			// IN 			- User(s) admin menu selection
	menu userSelection; 	//                INPUT (ENUM TYPE).
	mainMenu mainSelection; //				  INPUT (ENUM TYPE).
	ifstream adminFile;
	adminFile.open("AdminInfo.txt");		//CALC - Opens input file
	string username;
	string password;
	string seanUsername;
	string seanPassword;
	string stevenUsername;
	string stevenPassword;
	bool validLogin;		// CALC - Checks if adminLogin is valid

	srand(time(0));
	//Creates a vector containing the stadium class
	vector<stadium> S;
	//Creates a vector containing all items avaliable to purchase
	vector<item> I;
	//initializes items;
	initializeStore(I);
	//Reads input into the vector
	readInput(S);

	getline(adminFile, stevenUsername);
	getline(adminFile, stevenPassword);
	getline(adminFile, seanUsername);
	getline(adminFile, seanPassword);

	adminFile.close();

	// FUNCTION mainChoice - This function is designed to DISPLAY
	//                           the main menu to the user(s).
		UserChoice(mainChoice, 3, 6);

		// PROCESS
		mainSelection = mainMenu(mainChoice);

		// WHILE LOOP - MAIN BODY LOOP
		while (mainChoice != EXITMAIN)
		{
			// SWITCH STATEMENT -
			switch(mainSelection)
			{
				// CASE EXIT - Exit Case.
				case EXITMAIN:
						  	  break;// END OF CASE EXIT

				// CASE STADIUMNAME
				case STADIUMFINDER:
					// FUNCTION UserMenuChoice - This function is designed to DISPLAY
					//                           the menu to the user(s).
					UserChoice(userChoice, 0, 6);

					// PROCESS
					userSelection = menu(userChoice);

					// WHILE LOOP - MAIN BODY LOOP
					while (userChoice != EXIT)
					{
						// SWITCH STATEMENT -
						switch(userSelection)
						{
							// CASE EXIT - Exit Case.
							case EXIT:
									  	  break;// END OF CASE EXIT

							// CASE STADIUMNAME
							case STADIUMNAME:
							//SORT function to sort the vector by stadium
								OutputMLG(S, 0);
											break; // END OF CASE STADIUMNAME

							// CASE TEAMNAME
							case TEAMNAME:
								//SORT function to sort the vector by teamName
								OutputMLG(S, 1);
											break; // END OF CASE TEAMNAME

							// CASE GRASSTOP
							case GRASSTOP:
								//SORT function to sort the vector by stadium
								OutputMLG(S, 2);
											break; // END OF CASE GRASSTOP

							// CASE LEAGUETYPE
							case LEAGUETYPE:
								OutputMLG(S, 4);
											break; // END OF CASE LEAGUETYPE

							// CASE LEAGUETYPE
							case DATEOFCREATION:
								OutputMLG(S, 3);
											break; // END OF CASE LEAGUETYPE


							// CASE RANDOMSTADIUM
							case RANDOMSTADIUM:
								randomStadium(S);
											break; // END OF CASE RANDOMSTADIUM

							// CASE DEFAULT - Default case.
							default:
										break; // END OF CASE DEFAULT
						}// END OF SWITCH STATEMENT

						// FUNCTION UserChoice - This function is designed to display
						//                       and grab the menu choice from the user(s).
						UserChoice(userChoice, 0, 6);

						// PROCESS
						userSelection = menu(userChoice);

					}
				//SORT function to sort the vector by stadium
								break; // END OF CASE STADIUMNAME

				// CASE TRIPPLANNER
				case TRIPPLANNER:
					// FUNCTION - TripPlanner - Method that helps the user plan their
					//							travels, destination by destination
					tripPlanner(S);
					//SORT function to sort the vector by teamName
								break; // END OF CASE TEAMNAME

				// CASE SOUVENIRSHOP
				case SOUVENIRSHOP:
					storeMenu(I);

								break; // END OF CASE GRASSTOP

				// CASE DISTANCE MEASURE
				case DISTANCEMEASURE:
					StoryTen();
								break; // END OF CASE LEAGUETYPE

				// CASE LEAGUEVISIT
				case LEAGUEVISIT:
					LeagueVisit(S);
								break; // END OF CASE LEAGUETYPE

				// CASE ADMINLOGIN
				case ADMINLOGIN:
					if (validLogin == true)
					{
						cout << "\nYou are already logged in " << username << endl;
					}
					else
					{
						// USER INPUT - Input
						UserChoice(adminLogin, 4, 1);

						// CHECK IF USER WISHED TO PROCEED TO LOGIN
						if(adminLogin == 1)
						{

							while(validLogin == false)
							{
								cin.ignore(1000, '\n');
								cout << "\nEnter Username(Case Sensitive): ";
								getline(cin, username);


								cout << "\nEnter Password(Case Sensitive): ";
								getline(cin, password);


								if((username == seanUsername && password == seanPassword)||
								   (username == stevenUsername && password == stevenPassword))
								{
									cout << "\nWelcome " << username << endl;
									validLogin = true;
									break;
								}
								else
								{
									cout << "\nInvalid Login Information, please try again.\n";
								}
								// USER INPUT - Input
								UserChoice(adminLogin, 4, 1);

							}
						} // END OF IF STATEMENT
						adminMenu(S, I);
					}

					break; // END OF CASE LEAGUETYPE

				// CASE DEFAULT - Default case.
				default:
							break; // END OF CASE DEFAULT
			}// END OF SWITCH STATEMENT

			// FUNCTION mainChoice - This function is designed to DISPLAY
			//                           the main menu to the user(s).
			UserChoice(mainChoice, 3, 6);

			// PROCESS
			mainSelection = mainMenu(mainChoice);
		}
	readInto(S);
	return 0;
}