/*--------------- R e a d P w l F c n F i l e ( ) --------------- PURPOSE Read in a pwlFcn file. INPUT PARAMETERS cmdLine -- the execute command command line. pwlFcn -- the pwlFcn list. */ void ReadPwlFcnFile(string cmdLine, DblLinkedList &pwlFcn) { ifstream pwlFcnStream; // The input stream string pwlFcnFile; // The input file name // Ask for the file name and then open the file. pwlFcnFile = GetFileName(cmdLine); if (pwlFcnFile.length() == 0) return; pwlFcnStream.open(pwlFcnFile.c_str()); if (!pwlFcnStream.is_open()) { cout << "*** ERROR: No such file " << pwlFcnFile << endl; return; } // Read in the entire pwlFcn file. while (pwlFcnStream.peek() != EOF) { Point point; // Next input point pwlFcnStream >> point; pwlFcn.InsertItem(point); } pwlFcnStream.close(); pwlFcn.Rewind(); }
/*--------------- I n s e r t P o i n t ( ) --------------- PURPOSE Insert a new point in the pwlFcn before the current point. INPUT PARAMETERS cmdLine -- the execute command command line. pwlFcn -- the pwlFcn list. */ void InsertPoint(string cmdLine, DblLinkedList &pwlFcn) { const unsigned MinCmdSize = 2; // To check for an empty insert command Point point; // New pwlFcn point istringstream cmdStream(cmdLine.erase(0,1)); // Command stream // Ignore if empty add parameters. if (cmdLine.length() < MinCmdSize) return; // Read the new point and insert it into the pwlFcn. cmdStream.clear(); cmdStream >> point; if (cmdStream.fail() && !cmdStream.eof()) { cout << "Usage: I x y" << endl; cmdStream.clear(); return; } pwlFcn.InsertItem(point); }