Ejemplo n.º 1
0
void ConsoleUI::find_something()
{
    string search_table = "";
    string s = "";
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Do you want to search for a Scientist or a Computer?" << endl;
    cout << "(1) Scientist" << endl;
    cout << "(2) Computer" << endl;
    cout << endl << " -> ";
    cin >> search_table;
    while ((search_table != "1") && (search_table != "2"))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;
        cout << "Invalid input! Please try again:" << endl;
        cout << "Do you want to search for a Scientist or a Computer?" << endl;
        cout << "(1) Scientist" << endl;
        cout << "(2) Computer" << endl;
        cout << endl << " -> ";
        cin >> search_table;
    }
    if (search_table == "1")
    {
        find_scientists();
    }
    else if (search_table == "2")
    {
        find_computers();
    }
}
Ejemplo n.º 2
0
void ConsoleUI::sort_something()
{
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << " What would you like to sort?" << endl;
    cout << " (1) Scientists" << endl;
    cout << " (2) Computers" << endl;
    string value = "";
    cout << endl << " -> ";
    cin >> value;
    while ((value != "1") && (value != "2"))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;

        cout << "Invalid input! Please try again:" << endl;
        cout << "What would you like to sort?" << endl;
        cout << "(1) Scientists" << endl;
        cout << "(2) Computers" << endl;
        cout << endl << " -> ";
        cin >> value;
    }
    if (value == "1")
    {
        sort_scientists();
    }
    else if (value == "2")
    {
        sort_computers();
    }
}
Ejemplo n.º 3
0
void ConsoleUI::find_scientists()
{
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Insert your search string:" << endl;
    string searchstring = "";
    cout << endl << " -> ";
    cin >> searchstring;
    list <Scientist> searchList = dbService.search_scientists(searchstring);
    clear_screen();
    if (searchList.size() == 0)
    {
        cout << "No results with the string: " << searchstring << "." << endl;
        cout << endl;
    }
    else
    {
        cout << "Search results for " << searchstring << " in Scientists:\n";

        cout << readFileToString("../templates/basicline.txt");
        cout << "  " << setw(8) << left <<  "ID" << setw(20) << left << "First Name" << setw(20) << left << "Last Name" << setw(10) << left << "Gender" << setw(8) << left << "Born" << setw(8) << left << "Died" << endl;
        cout << readFileToString("../templates/basicline.txt") << endl;

        for (list <Scientist>::iterator temp = searchList.begin(); temp != searchList.end(); temp++ )
        {
            cout << "  " << setw(8) << temp->get_id() << setw(20) << temp->get_firstname() << setw(20) << left << temp->get_lastname() << setw(10) << left << temp->get_gender() << setw(8) << left << temp->get_birth() << setw(8) << left << temp->get_death() << endl;
        }
        cout << readFileToString("../templates/basicline.txt") << endl;
    }

}
Ejemplo n.º 4
0
void ConsoleUI::add_something()
{
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << " Insert a number for what you would like to add: " << endl;
    cout << " (1) Computer" << endl;
    cout << " (2) Scientist" << endl;
    int val = 0;
    cout << endl << " -> ";
    cin >> val;
    while ((val != 1) && (val != 2))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;
        cout << endl << "Invalid input, please try again:" << endl;

        cout << "Insert a number for what you would like to add: " << endl;
        cout << "(1) Computer" << endl;
        cout << "(2) Scientist" << endl;

        cout << endl << " -> ";
        cin >> val;
    }
    if (val == 1)
    {
        add_computer();
    }
    else if (val == 2)
    {
        add_scientist();
    }
}
Ejemplo n.º 5
0
void ConsoleUI::find_computers()
{
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Insert your search string:" << endl;
    string searchstring = "";
    cout << endl << " -> ";
    cin >> searchstring;
    list <Computer> searchList = dbService.search_computers(searchstring);
    clear_screen();
    if (searchList.size() == 0)
    {
        cout << "No results with the string: " << searchstring << "." << endl;
        cout << endl;
    }
    else
    {
        cout << "Search results for " << searchstring << " in Computers:\n";
        cout << readFileToString("../templates/basicline.txt");
        cout << "  " << setw(8) << left << "ID" << setw(20) << left << "Name" << setw(20) << left << "Type" << setw(12) << left << "yearBuilt" << setw(12) << left << "wasBuilt" << endl;
        cout << readFileToString("../templates/basicline.txt") << endl;
        for (list <Computer>::iterator temp = searchList.begin(); temp != searchList.end(); temp++ )
        {
            cout << "  " << setw(8) << left << temp->get_id() << setw(20) << left << temp->get_name() << setw(20) << left << temp->get_type() << setw(12) << left << temp->get_yearBuilt() << setw(12) << left << temp->get_wasBuilt() << endl;
        }
        cout << readFileToString("../templates/basicline.txt") << endl;
    }
}
Ejemplo n.º 6
0
void ConsoleUI::print_allscientists()
{
    cout << "\t\t\t\t" << "Scientists:\n\n";
    cout << readFileToString("../templates/basicline.txt");
    cout << "  " << setw(8) << left <<  "ID" << setw(20) << left << "First name" << setw(20) << left << "Last name" << setw(10) << left << "Gender" << setw(8) << left << "Born" << setw(8) << left << "Died" << endl;
    cout << readFileToString("../templates/basicline.txt") << endl;
    list <Scientist> Slist = dbService.get_allScientists();
    for (list <Scientist>::iterator temp = Slist.begin(); temp != Slist.end(); temp++ )
    {
        cout << "  " << setw(8) << temp->get_id() << setw(20) << temp->get_firstname() << setw(20) << left << temp->get_lastname() << setw(10) << left << temp->get_gender() << setw(8) << left << temp->get_birth() << setw(8) << left << temp->get_death() << endl;
    }
    cout << readFileToString("../templates/basicline.txt") << endl;
}
Ejemplo n.º 7
0
void ConsoleUI::menu(string& inp)
{
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << " -> ";
    cin >> inp;
    while ((inp != "add") && (inp != "sort") && (inp != "find") && (inp != "print") && (inp != "quit") && (inp != "connect"))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;
        cout << "\t\t     " << "Invalid input, please try again:" << endl;
        cout << " -> ";
        cin >> inp;
    }
}
Ejemplo n.º 8
0
void ConsoleUI::sort_scientists()
{
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    int col, mod;
    cout << "Sort by..." << endl;
    cout << "(1) First Name" << endl;
    cout << "(2) Last Name" << endl;
    cout << "(3) Gender" << endl;
    cout << "(4) Year of Birth" << endl;
    cout << "(5) Year of Death" << endl;
    cout << endl << " -> ";
    cin >> col;
    while ((col != 1) && (col != 2) && (col != 3) && (col != 4) && (col != 5))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;

        cout << "Invalid input! Please try again:" << endl;
        cout << "Sort by..." << endl;
        cout << "(1) First Name" << endl;
        cout << "(2) Last Name" << endl;
        cout << "(3) Gender" << endl;
        cout << "(4) Year of Birth" << endl;
        cout <<  "(5) Year of Death" << endl;
        cout << endl << " -> ";
        cin >> col;
    }
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "(1) Ascending" << endl;
    cout << "(2) Descending" << endl;
    cout << endl << " -> ";
    cin >> mod;
    while ((mod != 1) && (mod != 2))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;

        cout << "Not valid, please choose again." << endl;
        cout << "(1) Ascending" << endl;
        cout << "(2) Descending" << endl;
        cout << endl << " -> ";
        cin >> mod;
    }
    list <Scientist> scientistOrder = dbService.sort_scientists(col,mod);
    clear_screen();
    print_sorted_scientists(scientistOrder, col, mod);
}
Ejemplo n.º 9
0
int luaL_loadfilex (LuaThread *L, const char *filename,
                                             const char *mode) {
  THREAD_CHECK(L);

  std::string filename2;
  if (filename == NULL) {
    filename = "stdin";
    filename2 = "=stdin";
  }
  else {
    filename2 = "@" + std::string(filename);
  }
  
  std::string buffer;
  if(readFileToString(filename,buffer)) {
    Zio z;
    z.init(buffer.c_str(), buffer.size());
    skipHeader(z);
    return lua_load(L, &z, filename2.c_str(), mode);
  }
  else {
    lua_pushstring(L, filename2.c_str());
    return errfile(L, "open", L->stack_.getTopIndex());
  }

}
Ejemplo n.º 10
0
MyString
MultiLogFiles::fileNameToLogicalLines(const MyString &filename,
			StringList &logicalLines)
{
	MyString	result("");

	MyString fileContents = readFileToString(filename);
	if (fileContents == "") {
		result = "Unable to read file: " + filename;
		dprintf(D_ALWAYS, "MultiLogFiles: %s\n", result.Value());
		return result;
	}

		// Split the file string into physical lines.
		// Note: StringList constructor removes leading whitespace from lines.
	StringList physicalLines(fileContents.Value(), "\r\n");
	physicalLines.rewind();

		// Combine lines with continuation characters.
	MyString	combineResult = CombineLines(physicalLines, '\\',
				filename, logicalLines);
	if ( combineResult != "" ) {
		result = combineResult;
		return result;
	}
	logicalLines.rewind();

	return result;
}
Ejemplo n.º 11
0
void ConsoleUI::sort_computers()
{
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    int col, mod;
    cout << "Sort by..." << endl;
    cout << "(1) Name" << endl;
    cout << "(2) Type" << endl;
    cout << "(3) Year Built" << endl;
    cout << "(4) Was Built" << endl;
    cout << endl << " -> ";
    cin >> col;
    while ((col != 1) && (col != 2) && (col != 3) && (col != 4))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;

        cout << "Invalid input! Please try again:" << endl;
        cout << "Sort by..." << endl;
        cout << "(1) Name" << endl;
        cout << "(2) Type" << endl;
        cout << "(3) Year Built" << endl;
        cout << "(4) Was Built" << endl;
        cout << endl << " -> ";
        cin >> col;
    }
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "(1) Ascending" << endl;
    cout << "(2) Descending" << endl;
    cout << endl << " -> ";
    cin >> mod;
    while ((mod != 1) && (mod != 2))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;
        cout << "Invalid input! Please try again:" << endl;
        cout << "(1) Ascending" << endl;
        cout << "(2) Descending" << endl;
        cout << endl << " -> ";
        cin >> mod;
    }
    list <Computer> computerOrder = dbService.sort_computers(col,mod);
    clear_screen();
    print_sorted_computers(computerOrder, col, mod);
}
Ejemplo n.º 12
0
void ConsoleUI::add_computer()
{
    Computer c = Computer();
    string name_, type_, yearBuilt_, wasBuilt_;
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Name of Computer:" << endl;
    cout << endl << " -> ";
    cin >> name_;
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Type of Computer:" << endl;
    cout << endl << " -> ";
    cin >> type_;
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "When was the computer built? [YYYY]" << endl;
    cout << endl << " -> ";
    cin >> yearBuilt_;
    while (!is_digits(yearBuilt_))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;

        cout << "Invalid input! Please try again:" << endl;
        cout << "When was the computer built? [YYYY]" << endl;
        cin >> yearBuilt_;
    }
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Was the computer built? [Y/N]" << endl;
    cout << endl << " -> ";
    cin >> wasBuilt_;
    while ((wasBuilt_ != "Y") && (wasBuilt_ != "N") && (wasBuilt_ != "y") && (wasBuilt_ != "n"))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;
        cout << "Invalid input! Please try again:" << endl;
        cout << "Was the computer built? [Y/N]" << endl;
        cout << endl << " -> ";
        cin >> wasBuilt_;
    }
    if ((wasBuilt_ == "Y") || (wasBuilt_ == "y"))
    {
        c.set_wasBuilt("Yes");
    }
    else if ((wasBuilt_ == "N") || (wasBuilt_ == "n"))
    {
        c.set_wasBuilt("No");
    }
    fix_string(name_);
    fix_string(type_);
    c.set_name(name_);
    c.set_type(type_);
    c.set_yearBuilt(yearBuilt_);
    dbService.addC(c);
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "\t\t     " << "Computer has been added to the list! \n\n\n\n\n\n\n" << endl;
}
Ejemplo n.º 13
0
	void AddScreenshotData(MultipartFormDataEncoder &postdata, std::string filename)
	{
		std::string data;
		if (!filename.empty() && readFileToString(false, filename.c_str(), data))
			postdata.Add("screenshot", data, "screenshot.jpg", "image/jpeg");

		const std::string iconFilename = "disc0:/PSP_GAME/ICON0.PNG";
		std::vector<u8> iconData;
		if (pspFileSystem.ReadEntireFile(iconFilename, iconData) >= 0) {
			postdata.Add("icon", iconData, "icon.png", "image/png");
		}
	}
Ejemplo n.º 14
0
void ConsoleUI::start()
{
    string inp;
    clear_screen();
    cout << readFileToString("../templates/welcome.txt") << endl;
    menu(inp);
    while(inp != "quit")
    {
        if (inp == "add")
        {
            add_something();
        }
        if (inp == "print")
        {
            print_all();
        }
        if (inp == "sort")
        {
            sort_something();
        }
        if (inp == "find")
        {
            find_something();
        }
        if (inp == "connect")
        {
            connect_something();
        }
        pause_screen();
        clear_screen();
        menu(inp);
    }
    if(inp == "quit")
    {
        clear_screen();
        cout << readFileToString("../templates/goodbye.txt") << endl;
        cout << endl;
        cout << "\t\t\t     " << "Program has ended. \n\n\n\n\n\n\n\n";
    }
}
Ejemplo n.º 15
0
simulation::WorldPtr DartLoader::parseWorld(
  const common::Uri& _uri,
  const common::ResourceRetrieverPtr& _resourceRetriever)
{
  const common::ResourceRetrieverPtr resourceRetriever
    = getResourceRetriever(_resourceRetriever);

  std::string content;
  if (!readFileToString(resourceRetriever, _uri, content))
    return nullptr;

  return parseWorldString(content, _uri, _resourceRetriever);
}
Ejemplo n.º 16
0
/**
 * @function parseSkeleton
 */
dynamics::Skeleton* DartLoader::parseSkeleton(std::string _urdfFileName) {

    boost::shared_ptr<urdf::ModelInterface> skeletonModelPtr = urdf::parseURDF(readFileToString(_urdfFileName));
    if(!skeletonModelPtr)
        return NULL;

    // Change path to a Unix-style path if given a Windows one
    // Windows can handle Unix-style paths (apparently)
    std::replace(_urdfFileName.begin(), _urdfFileName.end(), '\\' , '/' );
    std::string skelDirectory = _urdfFileName.substr(0, _urdfFileName.rfind("/") + 1);

    return modelInterfaceToSkeleton(skeletonModelPtr.get(), skelDirectory);
}
Ejemplo n.º 17
0
void ConsoleUI::print_allconnections()
{
    cout << "\t\t\t\t" << "Connections:\n\n";
    cout << readFileToString("../templates/basicline.txt");
    cout << "  " << setw(13) << left << "First name" << setw(13) << left << "Last name" << setw(15) << left << "Computer name" << setw(15) << left << "Computer type" << setw(10) << left << "Year built" << setw(10) << left << " Was built" << endl;
    cout << readFileToString("../templates/basicline.txt") << endl;
    list <Connect> Clist = dbService.get_allconnections();
    string yes_or_no;
    for (list <Connect>::iterator temp = Clist.begin(); temp != Clist.end(); temp++ )
    {
        if (temp->get_comp_wasBuilt() == "1")
        {
            yes_or_no = "Yes";
        }
        else
        {
            yes_or_no = "No";
        }
        cout << "  " << setw(13) << left << temp->get_firstname() << setw(13) << left << temp->get_lastname() << setw(15) << left << temp->get_comp_name() << setw(15) << left << temp->get_comp_type() << setw(11) << left << temp->get_comp_yearBuilt() << setw(10) << left << yes_or_no << endl;
    }
    cout << readFileToString("../templates/basicline.txt") << endl;
}
Ejemplo n.º 18
0
void ConsoleUI::print_allcomputers()
{
    cout << "\t\t\t\t"<< "Computers:\n\n";
    cout << readFileToString("../templates/basicline.txt");
    cout << "  " << setw(8) << left << "ID" << setw(20) << left << "Name" << setw(20) << left << "Type" << setw(15) << left << "Year built" << setw(12) << left << "Was built" << endl;
    cout << readFileToString("../templates/basicline.txt") << endl;
    list <Computer> Clist = dbService.get_allComputers();
    string yes_or_no;
    for (list <Computer>::iterator temp = Clist.begin(); temp != Clist.end(); temp++ )
    {
        if (temp->get_wasBuilt() == "Yes")
        {
            yes_or_no = "Yes";
        }
        else if ((temp->get_wasBuilt() == "No"))
        {
            yes_or_no = "No";
        }
        cout << "  " << setw(8) << left << temp->get_id() << setw(20) << left << temp->get_name() << setw(20) << left << temp->get_type() << setw(15) << left << temp->get_yearBuilt() << setw(12) << left << yes_or_no << endl;
    }
    cout << readFileToString("../templates/basicline.txt") << endl;
}
Ejemplo n.º 19
0
void ConsoleUI::print_sorted_scientists(list <Scientist> scientistOrder, int col, int mod)
{
    cout << "List ordered by ";
    switch (col)
    {
    case 1:
        cout << "First Name, ";
        break;
    case 2:
        cout << "Last Name, ";
        break;
    case 3:
        cout << "Gender, ";
        break;
    case 4:
        cout << "Year of Birth, ";
        break;
    case 5:
        cout << "Year of Death, ";
        break;
    }
    if (mod == 1)
    {
        cout << "ascending:" << endl;
    }
    else if (mod == 2)
    {
        cout << "descending:" << endl;
    }
    cout << readFileToString("../templates/basicline.txt") << endl;
    cout << "  " << setw(8) << left <<  "ID" << setw(20) << left << "First Name" << setw(20) << left << "Last Name" << setw(10) << left << "Gender" << setw(8) << left << "Born" << setw(8) << left << "Died" << endl;
    cout << readFileToString("../templates/basicline.txt") << endl;
    for (list <Scientist>::iterator temp = scientistOrder.begin(); temp != scientistOrder.end(); temp++ )
    {
        cout << "  " << setw(8) << temp->get_id() << setw(20) << temp->get_firstname() << setw(20) << left << temp->get_lastname() << setw(10) << left << temp->get_gender() << setw(8) << left << temp->get_birth() << setw(8) << left << temp->get_death() << endl;
    }
    cout << readFileToString("../templates/basicline.txt") << endl;
}
Ejemplo n.º 20
0
void ConsoleUI::print_sorted_computers(list <Computer> computersOrder, int col, int mod)
{
    clear_screen();
    cout << "List ordered by ";
    switch (col)
    {
    case 1:
        cout << "name, ";
        break;
    case 2:
        cout << "type, ";
        break;
    case 3:
        cout << "built year, ";
        break;
    case 4:
        cout << "whether it was built or not, ";
        break;
    }
    if (mod == 1)
    {
        cout << "ascending:" << endl;
    }
    else if (mod == 2)
    {
        cout << "descending:" << endl;
    }
    cout << readFileToString("../templates/basicline.txt");
    cout << "  " << setw(8) << left << "ID" << setw(20) << left << "Name" << setw(20) << left << "Type" << setw(12) << left << "yearBuilt" << setw(12) << left << "wasBuilt" << endl;
    cout << readFileToString("../templates/basicline.txt") << endl;
    for (list <Computer>::iterator temp = computersOrder.begin(); temp != computersOrder.end(); temp++ )
    {
        cout << "  " << setw(8) << left << temp->get_id() << setw(20) << left << temp->get_name() << setw(20) << left << temp->get_type() << setw(12) << left << temp->get_yearBuilt() << setw(12) << left << temp->get_wasBuilt() << endl;
    }
    cout << readFileToString("../templates/basicline.txt") << endl;
}
Ejemplo n.º 21
0
/**
 * @function parseWorld
 */
simulation::World* DartLoader::parseWorld(std::string _urdfFileName) {

    std::string xmlString = readFileToString(_urdfFileName);

    // Change path to a Unix-style path if given a Windows one
    // Windows can handle Unix-style paths (apparently)
    std::replace(_urdfFileName.begin(), _urdfFileName.end(), '\\' , '/');
    std::string worldDirectory = _urdfFileName.substr(0, _urdfFileName.rfind("/") + 1);
    
    urdf::World* worldInterface = urdf::parseWorldURDF(xmlString, worldDirectory);
    if(!worldInterface)
        return NULL;

    // Store paths from world to entities
    parseWorldToEntityPaths(xmlString);

    simulation::World* world = new simulation::World();

    for(unsigned int i = 0; i < worldInterface->models.size(); ++i) {
      std::string skeletonDirectory = worldDirectory + mWorld_To_Entity_Paths.find(worldInterface->models[i].model->getName())->second;
      dynamics::Skeleton* skeleton = modelInterfaceToSkeleton(worldInterface->models[i].model.get(), skeletonDirectory);

      if(!skeleton) {
        std::cout << "[ERROR] Robot " << worldInterface->models[i].model->getName() << " was not correctly parsed. World is not loaded. Exiting!" << std::endl;
        return NULL; 
      }

      // Initialize position and RPY
      dynamics::Joint* rootJoint = skeleton->getRootBodyNode()->getParentJoint();
      Eigen::Isometry3d transform = toEigen(worldInterface->models[i].origin);

      if(dynamic_cast<dynamics::FreeJoint*>(rootJoint)) {
          Eigen::Vector6d coordinates;
          coordinates << math::logMap(transform.linear()), transform.translation();
          rootJoint->set_q(coordinates);
      }
      else {
          rootJoint->setTransformFromParentBodyNode(transform);
      }

      world->addSkeleton(skeleton);
    }
    return world;
}
Ejemplo n.º 22
0
dynamics::SkeletonPtr DartLoader::parseSkeleton(
  const common::Uri& _uri,
  const common::ResourceRetrieverPtr& _resourceRetriever)
{
  const common::ResourceRetrieverPtr resourceRetriever
    = getResourceRetriever(_resourceRetriever);

  std::string content;
  if (!readFileToString(resourceRetriever, _uri, content))
    return nullptr;

  // Use urdfdom to load the URDF file.
  const ModelInterfacePtr urdfInterface = urdf::parseURDF(content);
  if(!urdfInterface)
  {
    dtwarn << "[DartLoader::readSkeleton] Failed loading URDF file '"
           << _uri.toString() << "'.\n";
    return nullptr;
  }

  return modelInterfaceToSkeleton(urdfInterface.get(), _uri, resourceRetriever);
}
Ejemplo n.º 23
0
void ConsoleUI::connect_something()
{
    clear_screen();
    print_allscientists();
    int sci_id;
    string sci_id_str;
    cout << endl << "Insert ID of Scientist that you want to connect:" << endl;
    cout << endl << " -> ";
    cin >> sci_id_str;
    while (!is_digits(sci_id_str))
    {
        cout << "Not a valid input! Please try again:" << endl;
        cout << endl << "Insert ID of Scientist that you want to connect:" << endl;
        cout << endl << " -> ";
        cin >> sci_id_str;
    }
    sci_id = atoi(sci_id_str.c_str());
    clear_screen();
    print_allcomputers();
    cout << endl << "Insert ID of Computer that you want to connect:" << endl;
    cout << endl << " -> ";
    int comp_id;
    string comp_id_str;
    cin >> comp_id_str;
    while (!is_digits(comp_id_str))
    {
        cout << "Not a valid input! Please try again:" << endl;
        cout << endl << "Insert ID of Computer that you want to connect:" << endl;
        cout << endl << " -> ";
        cin >> comp_id_str;
    }
    comp_id = atoi(comp_id_str.c_str());
    dbService.addID(sci_id,comp_id);
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "\t\t     " << "The connection has been added to the list! \n\n\n\n\n" << endl;
}
Ejemplo n.º 24
0
bool CompareOutput(const std::string &bootFilename, const std::string &output, bool verbose)
{
	std::string expect_filename = ExpectedFromFilename(bootFilename);
	std::ifstream expect_f;
	expect_f.open(expect_filename.c_str(), std::ios::in);
	if (!expect_f.fail())
	{
		BufferedLineReaderFile expected(expect_f);
		BufferedLineReader actual(output);

		bool failed = false;
		while (expected.HasLines())
		{
			if (expected.Compare(actual))
				continue;

			if (!failed)
			{
				TeamCityPrint("##teamcity[testFailed name='%s' message='Output different from expected file']\n", teamCityName.c_str());
				failed = true;
			}

			// This is a really dirt simple comparing algorithm.

			// Perhaps it was an extra line?
			if (expected.Peek(0) == actual.Peek(1) || !expected.HasLines())
				printf("+ %s\n", actual.Consume().c_str());
			// A single missing line?
			else if (expected.Peek(1) == actual.Peek(0) || !actual.HasLines())
				printf("- %s\n", expected.Consume().c_str());
			else
			{
				printf("O %s\n", actual.Consume().c_str());
				printf("E %s\n", expected.Consume().c_str());
			}
		}

		while (actual.HasLines())
		{
			// If it's a blank line, this will pass.
			if (actual.Compare(expected))
				continue;

			printf("+ %s\n", actual.Consume().c_str());
		}
		expect_f.close();

		if (verbose)
		{
			if (!failed)
			{
				printf("++++++++++++++ The Equal Output +++++++++++++\n");
				printf("%s", output.c_str());
				printf("+++++++++++++++++++++++++++++++++++++++++++++\n");
			}
			else
			{
				printf("============== output from failed %s:\n", GetTestName(bootFilename).c_str());
				printf("%s", output.c_str());
				printf("============== expected output:\n");
				std::string fullExpected;
				if (readFileToString(true, expect_filename.c_str(), fullExpected))
					printf("%s", fullExpected.c_str());
				printf("===============================\n");
			}
		}

		return !failed;
	}
	else
	{
		fprintf(stderr, "Expectation file %s not found\n", expect_filename.c_str());
		TeamCityPrint("##teamcity[testIgnored name='%s' message='Expects file missing']\n", teamCityName.c_str());
		return false;
	}
}
Ejemplo n.º 25
0
	virtual void run() {
		if (!info_->LoadFromPath(gamePath_))
			return;

		std::string filename = gamePath_;
		{
			lock_guard lock(info_->lock);
			info_->fileType = Identify_File(info_->GetFileLoader());
		}

		switch (info_->fileType) {
		case FILETYPE_PSP_PBP:
		case FILETYPE_PSP_PBP_DIRECTORY:
			{
				FileLoader *pbpLoader = info_->GetFileLoader();
				std::unique_ptr<FileLoader> altLoader;
				if (info_->fileType == FILETYPE_PSP_PBP_DIRECTORY) {
					pbpLoader = ConstructFileLoader(pbpLoader->Path() + "/EBOOT.PBP");
					altLoader.reset(pbpLoader);
				}

				PBPReader pbp(pbpLoader);
				if (!pbp.IsValid()) {
					if (pbp.IsELF()) {
						goto handleELF;
					}
					ERROR_LOG(LOADER, "invalid pbp %s\n", pbpLoader->Path().c_str());
					return;
				}

				// First, PARAM.SFO.
				std::vector<u8> sfoData;
				if (pbp.GetSubFile(PBP_PARAM_SFO, &sfoData)) {
					lock_guard lock(info_->lock);
					info_->paramSFO.ReadSFO(sfoData);
					info_->ParseParamSFO();
				}

				// Then, ICON0.PNG.
				if (pbp.GetSubFileSize(PBP_ICON0_PNG) > 0) {
					lock_guard lock(info_->lock);
					pbp.GetSubFileAsString(PBP_ICON0_PNG, &info_->iconTextureData);
				} else {
					// Read standard icon
					DEBUG_LOG(LOADER, "Loading unknown.png because a PBP was missing an icon");
					ReadVFSToString("unknown.png", &info_->iconTextureData, &info_->lock);
				}
				info_->iconDataLoaded = true;

				if (info_->wantFlags & GAMEINFO_WANTBG) {
					if (pbp.GetSubFileSize(PBP_PIC0_PNG) > 0) {
						lock_guard lock(info_->lock);
						pbp.GetSubFileAsString(PBP_PIC0_PNG, &info_->pic0TextureData);
						info_->pic0DataLoaded = true;
					}
					if (pbp.GetSubFileSize(PBP_PIC1_PNG) > 0) {
						lock_guard lock(info_->lock);
						pbp.GetSubFileAsString(PBP_PIC1_PNG, &info_->pic1TextureData);
						info_->pic1DataLoaded = true;
					}
				}
				if (info_->wantFlags & GAMEINFO_WANTSND) {
					if (pbp.GetSubFileSize(PBP_SND0_AT3) > 0) {
						lock_guard lock(info_->lock);
						pbp.GetSubFileAsString(PBP_SND0_AT3, &info_->sndFileData);
						info_->sndDataLoaded = true;
					}
				}
			}
			break;

		case FILETYPE_PSP_ELF:
handleELF:
			// An elf on its own has no usable information, no icons, no nothing.
			{
				lock_guard lock(info_->lock);
				info_->id = "ELF000000";
				info_->id_version = "ELF000000_1.00";
				info_->paramSFOLoaded = true;
			}

			// Read standard icon
			DEBUG_LOG(LOADER, "Loading unknown.png because there was an ELF");
			ReadVFSToString("unknown.png", &info_->iconTextureData, &info_->lock);
			info_->iconDataLoaded = true;
			break;

		case FILETYPE_PSP_SAVEDATA_DIRECTORY:
		{
			SequentialHandleAllocator handles;
			VirtualDiscFileSystem umd(&handles, gamePath_.c_str());

			// Alright, let's fetch the PARAM.SFO.
			std::string paramSFOcontents;
			if (ReadFileToString(&umd, "/PARAM.SFO", &paramSFOcontents, 0)) {
				lock_guard lock(info_->lock);
				info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size());
				info_->ParseParamSFO();
			}

			ReadFileToString(&umd, "/ICON0.PNG", &info_->iconTextureData, &info_->lock);
			info_->iconDataLoaded = true;
			if (info_->wantFlags & GAMEINFO_WANTBG) {
				ReadFileToString(&umd, "/PIC1.PNG", &info_->pic1TextureData, &info_->lock);
				info_->pic1DataLoaded = true;
			}
			break;
		}

		case FILETYPE_PPSSPP_SAVESTATE:
		{
			info_->SetTitle(SaveState::GetTitle(gamePath_));

			lock_guard guard(info_->lock);

			// Let's use the screenshot as an icon, too.
			std::string screenshotPath = ReplaceAll(gamePath_, ".ppst", ".jpg");
			if (File::Exists(screenshotPath)) {
				if (readFileToString(false, screenshotPath.c_str(), info_->iconTextureData)) {
					info_->iconDataLoaded = true;
				}
			}
			break;
		}

		case FILETYPE_PSP_DISC_DIRECTORY:
			{
				info_->fileType = FILETYPE_PSP_ISO;
				SequentialHandleAllocator handles;
				VirtualDiscFileSystem umd(&handles, gamePath_.c_str());

				// Alright, let's fetch the PARAM.SFO.
				std::string paramSFOcontents;
				if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", &paramSFOcontents, 0)) {
					lock_guard lock(info_->lock);
					info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size());
					info_->ParseParamSFO();
				}

				ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->iconTextureData, &info_->lock);
				info_->iconDataLoaded = true;
				if (info_->wantFlags & GAMEINFO_WANTBG) {
					ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info_->pic0TextureData, &info_->lock);
					info_->pic0DataLoaded = true;
					ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info_->pic1TextureData, &info_->lock);
					info_->pic1DataLoaded = true;
				}
				if (info_->wantFlags & GAMEINFO_WANTSND) {
					ReadFileToString(&umd, "/PSP_GAME/SND0.AT3", &info_->sndFileData, &info_->lock);
					info_->pic1DataLoaded = true;
				}
				break;
			}

		case FILETYPE_PSP_ISO:
		case FILETYPE_PSP_ISO_NP:
			{
				info_->fileType = FILETYPE_PSP_ISO;
				SequentialHandleAllocator handles;
				// Let's assume it's an ISO.
				// TODO: This will currently read in the whole directory tree. Not really necessary for just a
				// few files.
				BlockDevice *bd = constructBlockDevice(info_->GetFileLoader());
				if (!bd)
					return;  // nothing to do here..
				ISOFileSystem umd(&handles, bd, "/PSP_GAME");

				// Alright, let's fetch the PARAM.SFO.
				std::string paramSFOcontents;
				if (ReadFileToString(&umd, "/PSP_GAME/PARAM.SFO", &paramSFOcontents, nullptr)) {
					lock_guard lock(info_->lock);
					info_->paramSFO.ReadSFO((const u8 *)paramSFOcontents.data(), paramSFOcontents.size());
					info_->ParseParamSFO();

					if (info_->wantFlags & GAMEINFO_WANTBG) {
						ReadFileToString(&umd, "/PSP_GAME/PIC0.PNG", &info_->pic0TextureData, &info_->lock);
						info_->pic0DataLoaded = true;
						ReadFileToString(&umd, "/PSP_GAME/PIC1.PNG", &info_->pic1TextureData, &info_->lock);
						info_->pic1DataLoaded = true;
					}
					if (info_->wantFlags & GAMEINFO_WANTSND) {
						ReadFileToString(&umd, "/PSP_GAME/SND0.AT3", &info_->sndFileData, &info_->lock);
						info_->pic1DataLoaded = true;
					}
				}

				// Fall back to unknown icon if ISO is broken/is a homebrew ISO, override is allowed though
				if (!ReadFileToString(&umd, "/PSP_GAME/ICON0.PNG", &info_->iconTextureData, &info_->lock)) {
					DEBUG_LOG(LOADER, "Loading unknown.png because no icon was found");
					ReadVFSToString("unknown.png", &info_->iconTextureData, &info_->lock);
				}
				info_->iconDataLoaded = true;
				break;
			}

			case FILETYPE_ARCHIVE_ZIP:
				info_->paramSFOLoaded = true;
				{
					ReadVFSToString("zip.png", &info_->iconTextureData, &info_->lock);
					info_->iconDataLoaded = true;
				}
				break;

			case FILETYPE_ARCHIVE_RAR:
				info_->paramSFOLoaded = true;
				{
					ReadVFSToString("rargray.png", &info_->iconTextureData, &info_->lock);
					info_->iconDataLoaded = true;
				}
				break;

			case FILETYPE_ARCHIVE_7Z:
				info_->paramSFOLoaded = true;
				{
					ReadVFSToString("7z.png", &info_->iconTextureData, &info_->lock);
					info_->iconDataLoaded = true;
				}
				break;

			case FILETYPE_NORMAL_DIRECTORY:
			default:
				info_->paramSFOLoaded = true;
				break;
		}

		info_->hasConfig = g_Config.hasGameConfig(info_->id);

		if (info_->wantFlags & GAMEINFO_WANTSIZE) {
			lock_guard lock(info_->lock);
			info_->gameSize = info_->GetGameSizeInBytes();
			info_->saveDataSize = info_->GetSaveDataSizeInBytes();
			info_->installDataSize = info_->GetInstallDataSizeInBytes();
		}
		info_->pending = false;
		info_->DisposeFileLoader();
	}
Ejemplo n.º 26
0
// static
std::string TextReader::readFileToString(const std::string &filename)
{
    return readFileToString(filename.c_str());
}
Ejemplo n.º 27
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{

    CRLog::setFileLogger( "crengine.log" );
    CRLog::setLogLevel( CRLog::LL_TRACE );

 	// TODO: Place code here.
	MSG msg;
	HACCEL hAccelTable;

	//make_dither_table();

	//TestWol();
/*
    LVStreamRef zipfile = LVOpenFileStream( L"zip_test.zip", LVOM_READ );
    if (!zipfile.isNull())
    {
        LVContainerRef zip = LVOpenArchieve( zipfile );
        if (!zip.isNull())
        {
            LVStreamRef log = LVOpenFileStream("ziptest.log", LVOM_WRITE);
            for (int i=0; i<zip->GetObjectCount(); i++)
            {
                const LVContainerItemInfo * item = zip->GetObjectInfo(i);
                if (item)
                {
                    //
                    *log << UnicodeToLocal( item->GetName() );
                    *log << lString8::itoa( (int)item->GetSize() );

                    LVStreamRef unpstream = zip->OpenStream( item->GetName(), LVOM_READ );
                    if (!unpstream.isNull())
                    {
                        *log << "\n arc stream opened ok \n";
                        LVStreamRef outstream = LVOpenFileStream( item->GetName(), LVOM_WRITE );
                        if ( !outstream.isNull() )
                        {
                            int copiedBytes = (int)LVPumpStream( outstream, unpstream );
                            *log << " copied " << lString8::itoa(copiedBytes) << " bytes\n";
                        }
                        else
                        {
                            *log << " error opening out stream\n";
                        }
                    }
                }
            }
        }
    }
*/
	lString8 exe_dir;
	char exe_fn[MAX_PATH+1];
	GetModuleFileNameA( NULL, exe_fn, MAX_PATH );
	int last_slash = -1;
	int i;
	for (i=0; exe_fn[i]; i++)
		if (exe_fn[i]=='\\' || exe_fn[i]=='/')
			last_slash = i;
	if (last_slash>0)
		exe_dir = lString8( exe_fn, last_slash );

	// init hyphenation manager
	initHyph( (exe_dir + "\\russian_EnUS_hyphen_(Alan).pdb").c_str() );

    lString8 fontDir = exe_dir;
    fontDir << "\\fonts";

    // init bitmap font manager
    InitFontManager( fontDir );


    // Load font definitions into font manager
    // fonts are in files font1.lbf, font2.lbf, ... font32.lbf
#if (USE_FREETYPE==1)
        LVContainerRef dir = LVOpenDirectory( LocalToUnicode(fontDir).c_str() );
        if ( !dir.isNull() )
        for ( i=0; i<dir->GetObjectCount(); i++ ) {
            const LVContainerItemInfo * item = dir->GetObjectInfo(i);
            lString16 fileName = item->GetName();
            if ( !item->IsContainer() && fileName.length()>4 && lString16(fileName, fileName.length()-4, 4)==L".ttf" ) {
                lString8 fn = UnicodeToLocal(fileName);
                printf("loading font: %s\n", fn.c_str());
                if ( !fontMan->RegisterFont(fn) ) {
                    printf("    failed\n");
                }
            }
        }
        //fontMan->RegisterFont(lString8("arial.ttf"));
#else
#if (USE_WIN32_FONTS==0)

    #define MAX_FONT_FILE 32
    for (i=0; i<MAX_FONT_FILE; i++)
    {
        char fn[32];
        sprintf( fn, "font%d.lbf", i );
        fontMan->RegisterFont( lString8(fn) );
    }
#endif
#endif
    //LVCHECKPOINT("WinMain start");
    text_view = new LVDocView;

    // stylesheet can be placed to file fb2.css
    // if not found, default stylesheet will be used
    lString8 css = readFileToString( (exe_dir + "\\fb2.css").c_str() );
    if (css.length() > 0)
        text_view->setStyleSheet( css );

    //LVCHECKPOINT("WinMain before loads");

    if (!fontMan->GetFontCount())
    {
        //error
        char str[1000];
#if (USE_FREETYPE==1)
        sprintf(str, "Cannot open font file(s) fonts/*.ttf \nCannot work without font\nPlace some TTF files to font\\ directory" );
#else
        sprintf(str, "Cannot open font file(s) font#.lbf \nCannot work without font\nUse FontConv utility to generate .lbf fonts from TTF" );
#endif
        MessageBoxA( NULL, str, "CR Engine :: Fb2Test -- fatal error!", MB_OK);
        return 1;
    }

    lString8 cmdline(lpCmdLine);
    cmdline.trim();
    if ( cmdline == "test_format" ) {
        testFormatting();
        return 1;
    }
    if (cmdline.empty())
    {
        cmdline = OpenFileDialog( NULL );
        //cmdline = "example2.fb2";
    }

    if ( cmdline.empty() )
        return 2;
    if ( !text_view->LoadDocument( cmdline.c_str() ))
    {
        //error
        char str[100];
        sprintf(str, "Cannot open document file %s", cmdline.c_str());
        MessageBoxA( NULL, str, "CR Engine :: Fb2Test -- fatal error!", MB_OK);
        return 1;
    }

    //LVCHECKPOINT("WinMain after loads");

	// Initialize global strings
	MyRegisterClass(hInstance);

	// Perform application initialization:
	if (!InitInstance (hInstance, nCmdShow))
	{
		return FALSE;
	}


	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_FONTTEST);

	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0))
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

    delete text_view;

    ShutdownFontManager();

	return msg.wParam;
}
Ejemplo n.º 28
0
void OpenClRayTracer::initialize() {
	OpenClContexts openClContexts;
	

#ifndef RUN_ON_CPU
	openClContexts.initializeInteropGpu();
	cl::Device device = openClContexts.getGpuDevice(0);
	this->context = openClContexts.getGpuContext(0);
#else
	openClContexts.initializeCpu();
	cl::Device device = openClContexts.getCpuDevice(0);
	this->context = openClContexts.getCpuContext(0);
#endif
	


	cl::Program::Sources sources;

	std::string vertexShaderSource = readFileToString("kernels/vertexShader.cl");
	std::string aabbSource = readFileToString("kernels/aabb.cl");
	std::string rayTracerSource = readFileToString("kernels/oldKernels/rayTracer.cl");
	std::string rayTracerKernelSource = readFileToString("kernels/oldKernels/rayTracerMain.cl");
	std::string debugSource = readFileToString("kernels/debug.cl");
#ifdef ADVANCED_RENDERER
	std::string perspectiveRayGeneratorSource = readFileToString("kernels/newKernels/1_perspectiveRayGenerator.cl");
	std::string rayGeneratorSource = readFileToString("kernels/newKernels/2A_rayGenerator.cl");
	std::string rayTraceAdvancedSource = readFileToString("kernels/newKernels/2B_rayTracer.cl");
	std::string treeTraverserSource = readFileToString("kernels/newKernels/3_treeTraverser.cl");
	std::string colorToPixelSource = readFileToString("kernels/newKernels/4_colorToPixel.cl");
#endif



	sources.push_back({ vertexShaderSource.c_str(), vertexShaderSource.length() });
	sources.push_back({ aabbSource.c_str(), aabbSource.length() });
	//sources.push_back({ rayTracerSource.c_str(), rayTracerSource.length() });
	sources.push_back({ rayTracerKernelSource.c_str(), rayTracerKernelSource.length() });
	sources.push_back({ debugSource.c_str(), debugSource.length() });
#ifdef ADVANCED_RENDERER
	sources.push_back({ perspectiveRayGeneratorSource.c_str(), perspectiveRayGeneratorSource.length() });
	sources.push_back({ rayTraceAdvancedSource.c_str(), rayTraceAdvancedSource.length() });
	sources.push_back({ rayGeneratorSource.c_str(), rayGeneratorSource.length() });
	sources.push_back({ treeTraverserSource.c_str(), treeTraverserSource.length() });
	sources.push_back({ colorToPixelSource.c_str(), colorToPixelSource.length() });
#endif

	writeSourcesToFile(sources, "kernels/output/allKernels.cl");

	cl::Program program(context, sources);



	std::cout << "---------------- Compilation status ----------------" << std::endl;
	std::string compileMessage;
	char programPathBuffer[256];
	getcwd(programPathBuffer, 256);
	std::string programPath = programPathBuffer;
	std::string stuff = device.getInfo<CL_DEVICE_OPENCL_C_VERSION>();
	std::string supported_extensions = device.getInfo<CL_DEVICE_EXTENSIONS>();
	std::cout << supported_extensions << std::endl;


	std::cout << "Path: \"" << programPath << "\"" << std::endl;







	// KOLLA PÅ						-CL-STD=CL2.0












#ifdef ADVANCED_RENDERER
	std::string extraOptions = "-cl-std=CL2.2 "/*-s \"" + programPath + "kernels/newKernels/3_treeTraverser.cl\" "*/;
#else
	std::string extraOptions = "";// "-cl-std=CL2.0";// "-cl-std=c++";// "-cl-std=CL2.0";// "-cl-unsafe-math-optimizations -cl-fast-relaxed-math";
#endif
	std::string compilerFlags = /*-O0 -g*/" -I " + programPath + " " + extraOptions;
	std::cout << compilerFlags << std::endl;
	try {
		std::cout << "Build started..." << std::endl;
		program.build({ device }, compilerFlags.c_str());
	}catch(cl::Error e){
		glfwDestroyWindow(renderer.getWindow());
		std::cout << "Prepping error message..." << std::endl;
		compileMessage = program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(device);
		std::cout << "Failed to compile with status " << e.err() << ": " << compileMessage << std::endl;
		system("pause");
		exit(1);
	}
	
	compileMessage = program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(device);
	std::cout << compileMessage << std::endl;
	
	cl_int status = CL_SUCCESS;
	
	queue = cl::CommandQueue(context, device, NULL, &status);

	vertexShaderKernel = cl::Kernel(program, "vertexShader", &status);
	aabbKernel = cl::Kernel(program, "aabb", &status);
	rayTraceKernel = cl::Kernel(program, "rayTracer", &status);
	debugKernel = cl::Kernel(program, "debug", &status);


#ifdef ADVANCED_RENDERER
	perspectiveRayGeneratorKernel = cl::Kernel(program, "perspectiveRayGenerator", &status);
	rayTraceAdvancedKernel = cl::Kernel(program, "rayTraceAdvanced", &status);
	rayGeneratorKernel = cl::Kernel(program, "rayGenerator", &status);
	treeTraverserKernel = cl::Kernel(program, "treeTraverser", &status);
	colorToPixelKernel = cl::Kernel(program, "colorToPixel", &status);
#endif
if (status != CL_SUCCESS) {
	std::cout << "Failed to create kernels" << std::endl;
	exit(1);
}

#ifndef RUN_ON_CPU
resultImages[0] = cl::ImageGL(context, CL_MEM_WRITE_ONLY, GL_TEXTURE_2D, 0, openGlTextureID, &status);
if (status != CL_SUCCESS) {
	std::cout << "Failed to create OpenCL image from OpenGL texture" << std::endl;
	exit(1);
}
#else
resultImages[0] = cl::Buffer(context, CL_MEM_WRITE_ONLY, sizeof(float4) * width * height);
if (status != CL_SUCCESS) {
	std::cout << "Failed to create OpenCL image from OpenGL texture" << std::endl;
	exit(1);
}
#endif // !RUN_ON_CPU


}
Ejemplo n.º 29
0
void ConsoleUI::add_scientist()
{
    Scientist s = Scientist();
    string firstname_, lastname_, gender_, birth_, death_;
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Name of Scientist: [FirstName LastName]" << endl;
    cout << endl << " -> ";
    cin >> firstname_ >> lastname_;
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Gender of scientist: \n(1) male \n(2) female" << endl;
    cout << endl << " -> ";
    cin >> gender_;
    while ((gender_ != "1") && (gender_ != "2"))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;

        cout << "Invalid input! Please try again:" << endl;
        cout << "Gender of scientist: \n(1) male \n(2) female" << endl;
        cout << endl << " -> ";
        cin >> gender_;
    }
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Birth year of scientist:" << endl;
    cout << endl << " -> ";
    cin >> birth_;
    while (!is_digits(birth_))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;

        cout << "Invalid input! Please try again:" << endl;
        cout << "Birth year of scientist:" << endl;
        cout << endl << " -> ";
        cin >> birth_;
    }
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "Scientist's Year of death: " << endl;
    cout << endl << " -> ";
    cin >> death_;
    while (!is_digits(death_) || (atoi(death_.c_str()) < atoi(birth_.c_str())))
    {
        clear_screen();
        cout << readFileToString("../templates/commands.txt") << endl;

        if (!is_digits(death_))
        {
            cout << "Invalid input! Please try again:" << endl;
        }
        else if (atoi(death_.c_str()) < atoi(birth_.c_str()))
        {
            cout << "Year of death should be AFTER year of birth! Please ry again:" << endl;
        }
        cout << "Scientist's Year of death:" << endl;
        cout << endl << " -> ";
        cin >> death_;
    }
    if (gender_ == "1")
    {
        s.set_gender("Male");
    }
    else if (gender_ == "2")
    {
        s.set_gender("Female");
    }
    fix_string(firstname_);
    fix_string(lastname_);
    s.set_firstname(firstname_);
    s.set_lastname(lastname_);
    s.set_birth(birth_);
    s.set_death(death_);
    dbService.addS(s);
    clear_screen();
    cout << readFileToString("../templates/commands.txt") << endl;
    cout << "\t\t     " << "Scientist has been added to the list!\n\n\n\n\n\n\n" << endl;
}