/* Leer el contenido de un archivo e interpretarlo como un grafo. Es decir, un conjunto de vertices y arcos. Ademas el archivo puede contener informacion sobre objetos, para ser utilizada en el problema de la mochila. De los vertices se lee un identificador (ID) y un nombre. De los arcos se lee la distancia que representan, y el vertice de salida y llegada. De los objetos se lee el nombre, el peso y el beneficio. Se recibe un string con el nombre del archivo que se leerá. */ bool graph::readFromFile(string fileName) { // abrir el archivo en modo lectura fstream file; file.open(fileName.c_str(), ios_base::in); /* Cargar un grafo de un nuevo archivo provoca que los objetos anteriores sean eliminados y sustituidos por los datos leidos del archivo. */ clearStarts(); // Comprobar que el archivo se abrió correctamente if (file.is_open()) { /* Se comprueba el largo del archivo moviendo el puntero de lectura hasta el final del archivo y leyendo la posicion actual */ int fileLen = 0; file.seekg(0, ios_base::end); fileLen = file.tellg(); /* Se lee el contenido del archivo en un arreglo de caracteres */ char fileContent[fileLen]; file.seekg(0); file.read(fileContent, fileLen); try { int last = 0, type = 0; for (int i = 0; i < fileLen; i++) { if (fileContent[i] == ':') { string line = ""; line.append(fileContent, last, i - last); last = i + 1; switch (type) { case 0: if (!processVert(line)) { clearStarts(); return false; } break; case 1: if (!processArc(line)) { clearStarts(); return false; } break; case 2: if (!processObj(line)) { clearStarts(); return false; } } type++; } } } catch (exception e) { clearStarts(); return false; } } return false; }
void DeltaProcess::print() { processObj()->print_value(); std->print(" "); switch (state()) { case initialized: std->print_cr("initialized"); break; case running: std->print_cr("running"); break; case yielded: std->print_cr("yielded"); break; case in_async_dll: std->print_cr("in asynchronous dll all");break; case yielded_after_async_dll: std->print_cr("yielded after asynchronous dll"); break; case preempted: std->print_cr("preempted"); break; case completed: std->print_cr("completed"); break; case boolean_error: std->print_cr("boolean error"); break; case lookup_error: std->print_cr("lookup error"); break; case primitive_lookup_error: std->print_cr("primitive lookup error"); break; case DLL_lookup_error: std->print_cr("DLL lookup error"); break; case NLR_error: std->print_cr("NLR error"); break; case stack_overflow: std->print_cr("stack overflow"); break; } }
int main(int argc, char** argv) { FILE *file; char *stringBuffer; glutInit(&argc, argv); stringBuffer = (char*) malloc(sizeof(char)); file = openFile(FILENAME); if (file == NULL) return 1; //user typed 'quit' processObj(file); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(640, 480); glutCreateWindow("ID_Assign1"); //glClearColor(1.0, 1.0, 1.0, 1.0); glutDisplayFunc(display); glutReshapeFunc(reshape); glutIdleFunc(idle); glutMainLoop(); return 0; }
DeltaProcess::~DeltaProcess() { processObj()->set_process(NULL); if (Processes::includes(this)) { Processes::remove(this); } }