//----------------------------------------------------------------- // main.C.sample // This file is an example for a main.C Demeter main file. // It provides sample code fragments showing how to use some of the // Demeter runtime libraries. To have a quick test of your environment // rename this file to main.C and compile the environment. //----------------------------------------------------------------- #include "UNKNOWN.h" /* * GEN_DIR is a global variable containing the path of the generation * environment. This path is used to find the cd-print and cd-parse * class dictionaries. * Do NOT delete the following statement. */ char* GEN_DIR = getenv( "GEN_DIR" ); int main( int argc, char* argv[], char* envp[] ) { //---------------------------------------- // Parsing an object //---------------------------------------- // specify file to parse in const int MAXPATH = 256; char Dem_input[MAXPATH]; // Input file is first argument if( argc >= 2 ) strcpy( Dem_input, argv[1] ); else { strcpy( Dem_input, "demeter-input" ); // default input } // parse it in cout << "Parsing in object in: " << Dem_input << ". \n"; CdGraph* iCdGraph = new CdGraph(); iCdGraph = ( CdGraph* ) iCdGraph -> g_parse( Dem_input ); if ( iCdGraph == NULL ) { cerr << "Parser error." << endl; exit(1); } cout << endl; //---------------------------------------- // Drawing an object //---------------------------------------- cout << "Drawing the parsed object:\n"; iCdGraph -> g_draw(); cout << "\nEnd of drawing.\n" << endl; //---------------------------------------- // Copying an object //---------------------------------------- cout << "Copying the object.\n"; CdGraph* nCdGraph = ( CdGraph* ) iCdGraph -> g_copy(); cout << endl; //---------------------------------------- // Displaying the copied object as a tree //---------------------------------------- cout << "Displaying the copied object as a tree:\n"; nCdGraph -> g_displayAsTree(); cout << "\nEnd of display.\n" << endl; //---------------------------------------- // Comparing two objects //---------------------------------------- cout << "Comparing the two objects:\n"; if ( iCdGraph -> g_equal( nCdGraph ) == 1 ) cout << "copied and original object are equal\n" << endl; else cout << "copied and original object are NOT equal\n" << endl; //---------------------------------------- // Printing an object //---------------------------------------- cout << "Pretty printing the parsed object:\n"; ofstream outFile( "demeter-output" ); cout << iCdGraph << endl; iCdGraph -> g_print( outFile ); outFile.close(); cout << "\nEnd of printing.\n" << endl; //---------------------------------------- // Selftest of generic parser/printer //---------------------------------------- cout << "Selftest of generic parser/printer:\n"; CdGraph* iCdGraphprinted = new CdGraph(); iCdGraphprinted = (CdGraph*)iCdGraphprinted->g_parse( "demeter-output" ); if( iCdGraph->g_equal( iCdGraphprinted ) == 1 ) { cout << "g_parse and g_parse( g_print( g_parse ) ) are equal.\n" << "Selftest passed.\n"; } else { cout << "g_parse and g_parse( g_print( g_parse ) ) are NOT equal.\n" << "Selftest failed.\n"; } cout << endl; //---------------------------------------- // Your own code follows after this //---------------------------------------- Vertex_List* result = //iMeal -> cost(); iCdGraph -> find_assoc( new Vertex( new DemIdent ("Z") )); cout << "\n*** associated vertices of Z ***\n" << result << endl; cout << "\nPARSING expected"; Vertex_List* expected = new Vertex_List(); if( argc >= 3 ) expected = (Vertex_List*)expected->g_parse( argv[2] ); else expected = (Vertex_List*)expected->g_parse( "expected" ); if ( expected == NULL ) { cerr << "Parser error." << endl; exit(1); } cout << endl; if( result->g_equal( expected ) ) cout << "SUCCESS"; else cout << "FAILURE"; cout << endl; result -> g_delete(); result = iCdGraph -> find_assoc( new Vertex( new DemIdent ("Z") )); cout << "associated vertices of Z"; result -> g_print(); cout << "\n*** FINISHED ***" << endl; return (0); }