void GameSelectionWindow::handleGameSelection() { GameChoiceWidget* newlySelected = (GameChoiceWidget*) QObject::sender(); if (m_selectedGameWidget == NULL || m_selectedGameWidget->getGameId() != newlySelected->getGameId()) { if (m_selectedGameWidget != NULL) m_selectedGameWidget->drawUnselected(); m_selectedGameWidget = newlySelected; m_selectedGameWidget->drawSelected(); GameController::ExscitechGame game = m_selectedGameWidget->getGameId(); std::string newGameTitle = GameInfoManager::getGameTitle(game); m_gameInfoTitle->setText(newGameTitle.c_str()); QString gameInstructions = ""; std::string newGameInstructionsPath = GameInfoManager::getGameInstructionsPath(game); std::ifstream inFile(newGameInstructionsPath.c_str()); if (inFile) { std::string fileString((std::istreambuf_iterator<char>(inFile)), std::istreambuf_iterator<char>()); gameInstructions.append(fileString.c_str()); } else { gameInstructions.append(ms_noGameInstructionsText.c_str()); } m_gameInfoInstructionDisplay->setHtml(gameInstructions); m_gamePlayButton->setEnabled(true); } }
void fe_ctl_load_list_from_string( PHttpFilteringEngineCtl ptr, const char* listString, const size_t listStringLength, const uint8_t listCategory, const bool flushExisting, uint32_t* rulesLoaded, uint32_t* rulesFailed ) { #ifndef NDEBUG assert(ptr != nullptr && u8"In fe_ctl_load_list_from_file(...) - Supplied HttpFilteringEngineCtl ptr is nullptr!"); assert(listString != nullptr && u8"In fe_ctl_load_list_from_file(...) - Supplied list string ptr is nullptr!"); #endif bool callSuccess = false; try { if (ptr != nullptr && listString != nullptr) { std::string fileString(listString, listStringLength); reinterpret_cast<te::httpengine::HttpFilteringEngineControl*>(ptr)->LoadFilteringListFromString(fileString, listCategory, flushExisting, rulesLoaded, rulesFailed); callSuccess = true; } } catch (std::exception& e) { reinterpret_cast<te::httpengine::HttpFilteringEngineControl*>(ptr)->ReportError(e.what()); } assert(callSuccess == true && u8"In fe_ctl_load_list_from_string(...) - Caught exception and failed to set category."); }
//return string from file //return empty string if file couldn't be opened std::string readFileToString(std::string fileName){ std::cout << fileName << std::endl; std::ifstream file(fileName.c_str()); if(file.is_open()){ file.seekg(0, std::ios::end); size_t size = file.tellg(); std::string fileString(size, ' '); file.seekg(0); file.read(&fileString[0], size); return fileString; } else { std::cout << "Error in World.cpp::init(), can't open map!" << std::endl; return std::string(""); } }
int GetLineNumberFromByteOffset(const std::string& fileName, int byteOffset) { std::ifstream file(fileName.c_str()); int numLines = 0; if(file.is_open()) { std::string fileString((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); for(int i = 0; i < byteOffset; ++i) { if(fileString[i] == '\n') numLines++; } } return numLines; }
Map::Map(Room* const room, const char* mapName, sf::Texture* const texture) : room(room), layersCount(0), tilesetTexture(texture) { // loading the map std::ifstream file; file.open(mapName); std::stringstream fileBuffer; fileBuffer << file.rdbuf(); file.close(); std::string fileString(fileBuffer.str()); rapidxml::xml_document<> doc; doc.parse<0>(&(fileString[0])); rapidxml::xml_node<>* map = doc.first_node("map"); width = static_cast<float>(atoi(map->first_attribute("width")->value())); height = static_cast<float>(atoi(map->first_attribute("height")->value())); // in TILES layersCount = atoi(map->first_node("properties")->first_node("property")->first_attribute("value")->value()); level.resize(layersCount); levelDraw.resize(layersCount); ///////////////// NOW WRE'R GETTING ALL LAYERS ONE BY ONE /////////////////////// rapidxml::xml_node<>* currentLayer = map->first_node("layer"); for (int l = 0; l < layersCount; l++) { rapidxml::xml_node<>* currentData = currentLayer->first_node("data"); layerParse(currentData, l); currentLayer = currentLayer->next_sibling("layer"); } }
void glCheckError(const char* file, unsigned int line) { // Get the last error GLenum errorCode = glGetError(); if (errorCode != GL_NO_ERROR) { std::string fileString(file); std::string error = "unknown error"; std::string description = "no description"; // Decode the error code switch (errorCode) { case GL_INVALID_ENUM : { error = "GL_INVALID_ENUM"; description = "an unacceptable value has been specified for an enumerated argument"; break; } case GL_INVALID_VALUE : { error = "GL_INVALID_VALUE"; description = "a numeric argument is out of range"; break; } case GL_INVALID_OPERATION : { error = "GL_INVALID_OPERATION"; description = "the specified operation is not allowed in the current state"; break; } case GL_STACK_OVERFLOW : { error = "GL_STACK_OVERFLOW"; description = "this command would cause a stack overflow"; break; } case GL_STACK_UNDERFLOW : { error = "GL_STACK_UNDERFLOW"; description = "this command would cause a stack underflow"; break; } case GL_OUT_OF_MEMORY : { error = "GL_OUT_OF_MEMORY"; description = "there is not enough memory left to execute the command"; break; } case GL_INVALID_FRAMEBUFFER_OPERATION_EXT : { error = "GL_INVALID_FRAMEBUFFER_OPERATION_EXT"; description = "the object bound to FRAMEBUFFER_BINDING_EXT is not \"framebuffer complete\""; break; } } // Log the error err() << "An internal OpenGL call failed in " << fileString.substr(fileString.find_last_of("\\/") + 1) << " (" << line << ") : " << error << ", " << description << std::endl; } }