bool compare(const std::string &file1, const std::string &file2) { std::stringstream ss1, ss2; std::ifstream if1(file1.c_str(), std::ios::binary), if2(file2.c_str(), std::ios::binary); ss1 << if1.rdbuf(); ss2 << if2.rdbuf(); return ss1.str() == ss2.str(); }
int main(int argc, char *argv[]) { if0(); if1(); if2(); if3(); if4(); if5(); }
bool compareFileData(std::string fName1, std::string fName2) { bool bEquel = true; int data1 = -1, data2 = -1; std::ifstream if1(fName1.c_str()); std::ifstream if2(fName1.c_str()); if(!if1.is_open() || !if1.is_open()){ printf("Can't open file or file is not existed!\n"); return bEquel; } while(!if1.eof() && !if2.eof() && (bEquel == true)){ if1>>data1; if2>>data2; if(data1 != data2){ bEquel = false; } } return bEquel; }
void Entity::readMeshXml(){ QString path; rapidxml::xml_document<> doc; rapidxml::xml_node<> *root, *geometry, *subMeshes, *skeletonLink, *boneAssignments, *subMesh, *faces, *vertexBuffer, *child, *position, *normal, *texCoord; int i; path = qApp->applicationDirPath(); //path.remove( path.lastIndexOf("/"), path.length() - path.lastIndexOf("/") ); path += "/CGFinalWork/media/mesh/" + QString(fileName.c_str()); qDebug() << "Loading mesh: " << path; std::ifstream if2( path.toStdString().c_str(), std::ifstream::in); std::vector<char> buffer((std::istreambuf_iterator<char>(if2)), std::istreambuf_iterator<char>( )); buffer.push_back('\0'); doc.parse<0>(&buffer[0]); root = doc.first_node("mesh"); geometry = root->first_node("sharedgeometry"); subMeshes = root->first_node("submeshes"); skeletonLink = root->first_node("skeletonlink"); boneAssignments = root->first_node("boneassignments"); vertexBuffer = geometry->first_node("vertexbuffer"); vertexCount = atoi( geometry->first_attribute("vertexcount")->value() ); vertices = new QVector4D[ vertexCount ]; normals = new QVector3D[ vertexCount ]; textureCoordinates = new QVector2D[ vertexCount ]; i = 0; for ( child = vertexBuffer->first_node("vertex"); child; child = child->next_sibling()){ position = child->first_node("position"); normal = child->first_node("normal"); texCoord = child->first_node("texcoord"); vertices[i] = QVector4D( atof( position->first_attribute("x")->value() ), atof( position->first_attribute("y")->value() ), atof( position->first_attribute("z")->value() ), 1.0f ); normals[i] = QVector3D( atof( normal->first_attribute("x")->value() ), atof( normal->first_attribute("y")->value() ), atof( normal->first_attribute("z")->value() ) ); textureCoordinates[i] = QVector2D( atof( texCoord->first_attribute("u")->value() ), atof( texCoord->first_attribute("v")->value() ) ); i++; } subMesh = subMeshes->first_node("submesh"); faces = subMesh->first_node("faces"); facesCount = atoi( faces->first_attribute("count")->value() ); indices = new unsigned int[ facesCount * 3 ]; i = 0; for ( child = faces->first_node("face"); child; child = child->next_sibling()){ indices [ i * 3 ] = atoi( child->first_attribute("v1")->value() ); indices [ i * 3 + 1] = atoi( child->first_attribute("v2")->value() ); indices [ i * 3 + 2] = atoi( child->first_attribute("v3")->value() ); i++; } if( skeletonLink != NULL ){ skeletonFileName = skeletonLink->first_attribute("name")->value(); i = 0; for ( child = faces->first_node("vertexboneassignment"); child; child = child->next_sibling()){ int boneIndex = atoi( child->first_attribute("boneindex")->value() ); int vertexIndex = atoi( child->first_attribute("vertexindex")->value() ); float weight = atof( child->first_attribute("weight")->value() ); i++; } } materialName = subMesh->first_attribute("material")->value(); }
//检测无效的if分支 void ifErr() { if1(); if2(); if3(); }
int main( int argc, char ** argv ) { FILE * pFile; int i, do_continue; char in_file[MAX_STR+1], out_file[MAX_STR+1], line[MAX_STR+1]; do_continue = i = 0; pFile = NULL; do { printf("Input file? "); fgets( in_file, MAX_STR, stdin ); printf("Output file? "); fgets( out_file, MAX_STR, stdin ); sscanf( in_file, "%s\n", in_file ); sscanf( out_file, "%s\n", out_file ); pFile = fopen( in_file, "r" ); if( pFile == NULL ) return 1; fout = fopen( out_file, "w" ); if( fout == NULL ) return 2; if( init( pFile ) ) goto unable_to_parse; do { fprintf( fout, "c#%d ", cycle ); wb(); mem3(); mem2(); mem1(); ex(); id(); if2(); if1(); /* pretend all stages are happening simultaneously */ fprintf( fout, "\n"); /* move everything down the pipeline */ if( !MEM3_stall ) { WB = MEM3; WB_count = MEM3_count; } if( !MEM2_stall ) { MEM3 = MEM2; MEM3_count = MEM2_count; } if( !MEM1_stall ) { MEM2 = MEM1; MEM2_count = MEM1_count; } if( !EX_stall ) { MEM1 = EX; MEM1_count = EX_count; } if( !ID_stall ) { EX = ID; EX_count = ID_count; } else MEM1 = EMPTY; if( !IF2_stall ) { ID = IF2; ID_count = IF2_count; } if( !IF1_stall ) { IF2 = IF1; IF2_count = IF1_count; ++inst_cycle; } if( flush ) { IF1 = EMPTY; IF2 = EMPTY; ID = EMPTY; EX = EMPTY; flush = FALSE; --inst_cycle; } ++cycle; Registers[0] = 0; /* reset R0 if it was accidently set */ } while( ( (IF1 != EMPTY) || (IF2 != EMPTY) || (ID != EMPTY) || (EX != EMPTY) || (MEM1 != EMPTY) || (MEM2 != EMPTY) || (MEM3 != EMPTY) || (WB != EMPTY) ) ); /* print end status */ print_regs( fout ); print_mem( fout ); unable_to_parse: for( i = 0; i < instcount; ++i ) free( Instructions[i] ); fclose( pFile ); fclose( fout ); printf("would you like to run again? "); fgets( line, MAX_STR, stdin ); do_continue = ( line[0] == 'y' || line[0] == 'Y' ) ? 1 : 0; } while( do_continue ); goto end; for( i = 0; i < instcount; ++i ) free( Instructions[i] ); fclose( pFile ); fclose( fout ); end: return 0; }