// This file is identical to the "taskstub.h" file available before // November 20, except for the documentation, which has been updated. // The classes below are intended for use in the topological sort // algorithm. Note that it is possible to make classes that you // derive from "task_stub" private to classes you derive from // "taskset_stub". // Although sets of tasks can be implemented simply as linked // lists of tasks, without needing a separate class, two classes // have been provided to emphasize the abstract difference between // the class for which "topsort" is appropriate and the class // for which "incr_unmet", etc., are appropriate #include #include #include #include // If your C++ implementation has the ANSI standard "bool", you // needn't use "boolean" typedef int boolean; #define TRUE 1 #define FALSE 0 // task identifiers are just character strings typedef char * taskid; //////////////////////////// CLASSES //////////////////////////////// // The "task_stub" class has 2 data members -- a task identifier "name" // and an integer representing the number of unmet prerequisites // There are member functions to increment or decrement the // number of unmet prerequistes of a task, add an element (or "constraint") to // the postrequisite list of a task, and and to decrement the number of // unmet prerequisites of each task for which the given task // is a prerequisite. class task_stub { protected: taskid name; // name of task int unmet; // # of unmet prereqs virtual void incr_unmet()=0; virtual void decr_unmet()=0; virtual void decr_list_unmet()=0; task_stub(taskid taskname) {int len=strlen(taskname); name=new char[1+len]; assert(name); strcpy(name,taskname); unmet=0; } }; // In the "taskset_stub" class is represented as a headed linked // list of tasks. There is no constructor; constructors for // derived classes should takes an "istream" as argument. A // "topsort" function applies to tasksets and adds the output // sequence of task identifiers to an output stream (ostream). class taskset_stub { protected: virtual boolean bad(void)=0; // tests for ill-formed taskset virtual void topsort(ostream &)=0; };