// STLprint.cpp #include "STLprint.h" #include #include #include #include #include #include #include "ptr/Ptr.h" #include "ptr/SharedDeletePolicy.h" #include "STLprintTest.h" using std::string; using std::cout; using std::cerr; using std::endl; using std::vector; using std::list; using std::map; using std::less; typedef Ptr FPtr; //********************************************************************** int main( ) { string component = "STLprint"; string ok_prefix = component + " (I): "; string error_prefix = component + " test (E): "; cout << ok_prefix << "---------- Testing component " + component + ". ----------" << endl; // Make sure assert is enabled. bool assert_flag = false; assert ( ( assert_flag = true, assert_flag ) ); if ( ! assert_flag ) { cerr << "Assert is disabled" << endl; return 1; } //******************************************************************** cout << ok_prefix << "Vector of values." << endl; vector ints; ints.push_back(1); ints.push_back(2); ints.push_back(4); ints.push_back(9); ints.push_back(16); cout << endl; print_list("Integer",ints); cout << endl; //******************************************************************** cout << ok_prefix << "List of pointers." << endl; list floats; floats.push_back( FPtr(new MyFloat(1.23)) ); floats.push_back( FPtr(new MyFloat(2.46)) ); cout << endl; print_ptr_list("Float pointer",floats,cout); cout << endl; //******************************************************************** cout << ok_prefix << "Map of values." << endl; map > fmap; fmap[1] = 1.23; fmap[3] = 3.44; fmap[2] = 2.81; cout << endl; print_map("Float value", fmap, cout ); cout << endl; //******************************************************************** cout << ok_prefix << "Map of pointers." << endl; map > pmap; pmap["OnePointTwoThree"] = new MyFloat(1.23); pmap["TwoPointFourSeven"] = new MyFloat(2.47); pmap["EightPointNineZero"] = new MyFloat(8.90); cout << endl; print_ptr_map("Float pointer", pmap, cout ); cout << endl; //******************************************************************** cout << ok_prefix << "Map of lists of values." << endl; vector ints2; vector ints3 = ints; map, less > vlmap; cout << endl; vlmap["Original"] =ints; vlmap["Empty"] = ints2; vlmap["Copy"] = ints3; print_list_map("Integer",vlmap); cout << endl; //******************************************************************** cout << ok_prefix << "Map of lists of pointers." << endl; map, less > vpmap; cout << endl; vpmap["Original"] = floats; vpmap["Empty"] = list(); vpmap["Copy"] = floats; print_ptr_list_map("Integer",vpmap); cout << endl; //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }