void task1p3(std::ifstream & inputfile, std::ofstream & outputfile) { std::string line; while ( getline (inputfile,line) ) { if (line.size() > MAX_LINE_SIZE) { printToOutput(outputfile,"LINE is Big!!"); } if (puzzle(line)) { printToOutput(outputfile,"YES"); } else { printToOutput(outputfile,"NO"); } } }
//============================================================================== // Checks For an openGL Error and Exits if One Occured //============================================================================== void Utility::exitOnGLError(std::string errorMessage) { GLenum errorValue = glGetError(); if(errorValue != GL_NO_ERROR) { switch(errorValue) { case GL_INVALID_ENUM: printToOutput(std::string("OpenGL Error: Invalid Enum -- ") + errorMessage + '\n'); break; case GL_INVALID_VALUE: printToOutput(std::string("OpenGL Error: Invalid Value -- ") + errorMessage + '\n'); break; case GL_INVALID_OPERATION: printToOutput(std::string("OpenGL Error: Invalid Operation -- ") + errorMessage + '\n'); break; case GL_INVALID_FRAMEBUFFER_OPERATION: printToOutput(std::string("OpenGL Error: Invalid Framebuffer Operation -- ") + errorMessage + '\n'); break; case GL_OUT_OF_MEMORY: printToOutput(std::string("OpenGL Error: Out of Memory -- ") + errorMessage + '\n'); break; case GL_STACK_UNDERFLOW: printToOutput(std::string("OpenGL Error: Stack Underflow -- ") + errorMessage + '\n'); break; case GL_STACK_OVERFLOW: printToOutput(std::string("OpenGL Error: Stack Overflow -- ") + errorMessage + '\n'); break; } exit(EXIT_FAILURE); } }
//------------------------------------------------------------------------------ // processRecordImp //------------------------------------------------------------------------------ void PrintSelected::processRecordImp(const DataRecordHandle* const handle) { if (handle == nullptr) return; // cannot continue const pb::DataRecord* dataRecord = handle->getRecord(); if (dataRecord == nullptr) return; // cannot continue // using reflection: // save to: const google::protobuf::Message* recMsg recMsg = dataRecord; //const google::protobuf::Message& root = *recMsg; const google::protobuf::Descriptor* descriptor = recMsg->GetDescriptor(); const google::protobuf::Reflection* reflection = recMsg->GetReflection(); const google::protobuf::FieldDescriptor* idField = descriptor->FindFieldByName("id"); unsigned int id = reflection->GetUInt32(*recMsg, idField); foundSelected = false; // Process time message processMessage( &dataRecord->time()); // Process the event message const google::protobuf::Message* processMsg = nullptr; std::string msgCat = ""; std::string msgType = ""; switch (msgToken) { case REID_FILE_ID: { processMsg = &dataRecord->file_id_msg(); msgCat = "FILE "; msgType = "ID "; static bool firstTime = true; if ((firstTime) || isFileEmpty()) printHeader = true; firstTime = false; break; } case REID_NEW_PLAYER: { processMsg = &dataRecord->new_player_event_msg(); msgCat = "PLAYER "; msgType = "NEW "; static bool firstTime = true; if ((firstTime) || isFileEmpty()) printHeader = true; firstTime = false; break; } case REID_PLAYER_REMOVED: { processMsg = &dataRecord->player_removed_event_msg(); msgCat = "PLAYER "; msgType = "REMOVED "; static bool firstTime = true; if (firstTime || isFileEmpty()) printHeader = true; firstTime = false; break; } case REID_PLAYER_DATA: { processMsg = &dataRecord->player_data_msg(); msgCat = "PLAYER "; msgType = "DATA "; static bool firstTime = true; if (firstTime || isFileEmpty()) { printHeader = true; } firstTime = false; break; } case REID_PLAYER_DAMAGED: { processMsg = &dataRecord->player_damaged_event_msg(); msgCat = "PLAYER "; msgType = "DAMAGED "; static bool firstTime = true; if (firstTime || isFileEmpty()) printHeader = true; firstTime = false; break; } case REID_PLAYER_COLLISION: { processMsg = &dataRecord->player_collision_event_msg(); msgCat = "PLAYER "; msgType = "COLLISION"; static bool firstTime = true; if (firstTime || isFileEmpty()) printHeader = true; firstTime = false; break; } case REID_PLAYER_CRASH: { processMsg = &dataRecord->player_crash_event_msg(); msgCat = "PLAYER "; msgType = "CRASH "; static bool firstTime = true; if (firstTime || isFileEmpty()) printHeader = true; firstTime = false; break; } case REID_PLAYER_KILLED: { processMsg = &dataRecord->player_killed_event_msg(); msgCat = "PLAYER "; msgType = "KILLED "; static bool firstTime = true; if (firstTime || isFileEmpty()) printHeader = true; firstTime = false; break; } case REID_WEAPON_RELEASED: { processMsg = &dataRecord->weapon_release_event_msg(); msgCat = "WEAPON "; msgType = "RELEASED "; static bool firstTime = true; if (firstTime || isFileEmpty()) printHeader = true; firstTime = false; break; } case REID_WEAPON_HUNG: { processMsg = &dataRecord->weapon_hung_event_msg(); msgCat = "WEAPON "; msgType = "HUNG "; static bool firstTime = true; if (firstTime || isFileEmpty()) printHeader = true; firstTime = false; break; } case REID_WEAPON_DETONATION: { processMsg = &dataRecord->weapon_detonation_event_msg(); msgCat = "WEAPON "; msgType = "DETONATE"; static bool firstTime = true; if (firstTime || isFileEmpty()) printHeader = true; firstTime = false; break; } case REID_GUN_FIRED: { processMsg = &dataRecord->gun_fired_event_msg(); msgCat = "GUN "; msgType = "FIRED "; static bool firstTime = true; if (firstTime || isFileEmpty()) printHeader = true; firstTime = false; break; } case REID_NEW_TRACK: { processMsg = &dataRecord->new_track_event_msg(); msgCat = "TRACK "; msgType = "NEW "; static bool firstTime = true; if (firstTime || isFileEmpty()) printHeader = true; firstTime = false; break; } case REID_TRACK_REMOVED: { processMsg = &dataRecord->track_removed_event_msg(); msgCat = "TRACK "; msgType = "REMOVED "; static bool firstTime = true; if (firstTime || isFileEmpty()) printHeader = true; firstTime = false; break; } case REID_TRACK_DATA: { processMsg = &dataRecord->track_data_msg(); msgCat = "TRACK "; msgType = "DATA "; static bool firstTime = true; if (firstTime || isFileEmpty()) printHeader = true; firstTime = false; break; } default: break; } // Process the message and see if the conditions are found if (!timeOnly && (processMsg != nullptr)) { processMessage(processMsg); } // If the condition has been found and this is the message we want, print it std::stringstream soutFields; std::stringstream soutVals; if (foundSelected && timeOnly) { // print the message, whatever it is, because it matches the time criteria std::string msgName = getEventMsgName(recMsg); // This also sets the event message if (eventMsg != nullptr) { soutFields << std::left << std::setw(32) << msgName << "\t" << "HEADER" << "\t"; soutVals << std::left << std::setw(32) << msgName << "\t" "VALUES" << "\t"; soutFields << std::left << std::setw(12)<< "exec time " << "\t"; soutFields << std::left << std::setw(12)<< "sim time " << "\t"; soutFields << std::left << std::setw(12)<< "utc time "<< "\t" ; std::string timeStr = ""; timeStr = printTimeMsg(dataRecord->time().exec_time()); soutVals << std::left << std::setw(12) << timeStr << "\t"; timeStr = printTimeMsg(dataRecord->time().sim_time()); soutVals << std::left << std::setw(12) << timeStr << "\t"; timeStr = printTimeMsg(dataRecord->time().utc_time()); soutVals << std::left << std::setw(12) << timeStr << "\t"; // soutVals << std::left << std::setw(12) << dataRecord->time().sim_time() << "\t"; // soutVals << std::left << std::setw(12) << dataRecord->time().exec_time() << "\t"; // soutVals << std::left << std::setw(12) << dataRecord->time().utc_time() << "\t"; // printMessage(soutFields, soutVals, recMsg); // Use this to include time and message ID printMessage(soutFields, soutVals, eventMsg); printToOutput( soutFields.str().c_str() ); printToOutput( soutVals.str().c_str() ); } } else if (foundSelected && (id == msgToken)) { // Print the message name soutFields << msgCat << "\t" << "HEADER" << "\t"; soutVals << msgCat << "\t" << msgType << "\t"; // Print the time // const pb::Time* timeMsg = &dataRecord->time(); // printMessage(soutFields, soutVals, timeMsg); // print out the time message soutFields << std::left << std::setw(12)<< "exec time " << "\t"; soutFields << std::left << std::setw(12)<< "sim time " << "\t"; soutFields << std::left << std::setw(12)<< "utc time "<< "\t" ; std::string timeStr = ""; timeStr = printTimeMsg(dataRecord->time().exec_time()); soutVals << std::left << std::setw(12) << timeStr << "\t"; timeStr = printTimeMsg(dataRecord->time().sim_time()); soutVals << std::left << std::setw(12) << timeStr << "\t"; timeStr = printTimeMsg(dataRecord->time().utc_time()); soutVals << std::left << std::setw(12) << timeStr << "\t"; // Print out the event message // print the message, whatever it is, because it matches the time criteria std::string msgName = getEventMsgName(recMsg); // This also sets event message if (eventMsg != nullptr) { printMessage(soutFields, soutVals, eventMsg); } // if (processMsg != 0) printMessage(soutFields, soutVals, processMsg); // print out the event message // Print to output: if (printHeader) { printHeader = false; printToOutput( soutFields.str().c_str() ); } printToOutput( soutVals.str().c_str() ); } }
//------------------------------------------------------------------------------ // Print the data //------------------------------------------------------------------------------ void PrintPlayer::processRecordImp(const DataRecordHandle* const handle) { if (handle == 0) return; // cannot continue const Pb::DataRecord* dataRecord = handle->getRecord(); if (dataRecord == 0) return; // cannot continue // Get the time msg const Pb::Time* timeMsg = 0; if (dataRecord->has_time()) { timeMsg = &dataRecord->time(); } // Get message id unsigned int messageId = dataRecord->id(); enum MsgType { NEW, DATA, REMOVED, DAMAGE, COLLISION, CRASH, KILL, UNKNOWN }; MsgType msgType = UNKNOWN; std::string msgTypeStr = ""; const Pb::PlayerId* playerIdMsg = 0; const Pb::PlayerState* playerStMsg = 0; switch (messageId) { // events: case REID_NEW_PLAYER : { if (dataRecord->has_new_player_event_msg()) { msgType = NEW; msgTypeStr = "NEW"; const Pb::NewPlayerEventMsg* msg = &dataRecord->new_player_event_msg(); playerIdMsg = &msg->id(); playerStMsg = &msg->state(); std::string playerName = playerIdMsg->name(); // example } break; } case REID_PLAYER_REMOVED : { if (dataRecord->has_player_removed_event_msg()) { msgType = REMOVED; msgTypeStr = "REMOVED"; const Pb::PlayerRemovedEventMsg* msg = &dataRecord->player_removed_event_msg(); playerIdMsg = &msg->id(); playerStMsg = &msg->state(); } break; } case REID_PLAYER_DATA : { if (dataRecord->has_player_data_msg()) { msgType = DATA; msgTypeStr = "DATA"; const Pb::PlayerDataMsg* msg = &dataRecord->player_data_msg(); playerIdMsg = &msg->id(); playerStMsg = &msg->state(); } break; } case REID_PLAYER_DAMAGED : { if (dataRecord->has_player_damaged_event_msg()) { msgType = DAMAGE; msgTypeStr = "DAMAGE"; const Pb::PlayerDamagedEventMsg* msg = &dataRecord->player_damaged_event_msg(); playerIdMsg = &msg->id(); playerStMsg = &msg->state(); } break; } case REID_PLAYER_COLLISION : { if (dataRecord->has_player_collision_event_msg()) { msgType = COLLISION; msgTypeStr = "COLLISION"; const Pb::PlayerCollisionEventMsg* msg = &dataRecord->player_collision_event_msg(); playerIdMsg = &msg->id(); playerStMsg = &msg->state(); } break; } case REID_PLAYER_CRASH : { if (dataRecord->has_player_crash_event_msg()) { msgType = CRASH; msgTypeStr = "CRASH"; const Pb::PlayerCrashEventMsg* msg = &dataRecord->player_crash_event_msg(); playerIdMsg = &msg->id(); playerStMsg = &msg->state(); } break; } case REID_PLAYER_KILLED : { if (dataRecord->has_player_killed_event_msg()) { msgType = KILL; msgTypeStr = "KILL"; const Pb::PlayerCrashEventMsg* msg = &dataRecord->player_crash_event_msg(); playerIdMsg = &msg->id(); playerStMsg = &msg->state(); } break; } default: { // not a message handled here. msgType = UNKNOWN; return; break; } } // if message handled, continue if (msgType != UNKNOWN) { bool printIt = (name == 0); if (!printIt) { if (playerIdMsg != 0 && playerIdMsg->has_name()) { const char* sname = playerIdMsg->name().c_str(); printIt = (*name == sname); } } if (printIt) { std::stringstream sout; // Print the Message Type sout << "PLAYER " << msgTypeStr << " "; // Print the Player ID data if (playerIdMsg->has_id()) sout << playerIdMsg->id() << "; "; if (playerIdMsg->has_name()) sout << playerIdMsg->name() << "; "; if (playerIdMsg->has_fed_name()) sout << playerIdMsg->fed_name() << "; "; // Angles: if (playerStMsg->has_angles()) { if ((playerStMsg->angles().has_x()) && (playerStMsg->angles().has_y()) && (playerStMsg->angles().has_z())) { sout << playerStMsg->angles().x() << ", " << playerStMsg->angles().y() << ", " << playerStMsg->angles().z() << "; "; } } // Velocity: if (playerStMsg->has_vel()) { if ((playerStMsg->vel().has_x()) && (playerStMsg->vel().has_y()) && (playerStMsg->vel().has_z())) { sout << playerStMsg->vel().x() << ", " << playerStMsg->vel().y() << ", " << playerStMsg->vel().z() << "; "; } } // Position: if (playerStMsg->has_pos()) { if ((playerStMsg->pos().has_x()) && (playerStMsg->pos().has_y()) && (playerStMsg->pos().has_z())) { sout << playerStMsg->pos().x() << ", " << playerStMsg->pos().y() << ", " << playerStMsg->pos().z() << "; "; } } printToOutput( sout.str().c_str() ); } } }