Skip to content

Commit

Permalink
Program and Process can be ordered (<)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Hannan committed Aug 7, 2011
1 parent ef22bed commit d10f1f3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/process.h
Expand Up @@ -12,7 +12,14 @@ namespace process {

const module::Module module ("10util", "10util/process.h");

struct Process {
class Process {
friend bool operator== (const Process& a, const Process& b) {return a.program == b.program && a.pid == b.pid;}
friend bool operator< (const Process& a, const Process& b) {return a.program < b.program || (a.program == b.program && a.pid < b.pid);}
friend bool operator!= (const Process& a, const Process& b) {return !(a == b);}
friend bool operator> (const Process& a, const Process& b) {return b < a;}
friend bool operator>= (const Process& a, const Process& b) {return !(a < b);}
friend bool operator<= (const Process& a, const Process& b) {return !(a > b);}
public:
program::Program program;
pid_t pid;
Process (program::Program program, pid_t pid) : program(program), pid(pid) {}
Expand Down
9 changes: 8 additions & 1 deletion src/program.h
Expand Up @@ -36,7 +36,14 @@ namespace program {
Options parseArgs (std::vector<std::string> args);

/** Program with options, ready to run */
struct Program {
class Program {
friend bool operator== (const Program& a, const Program& b) {return a.prepCommand == b.prepCommand && a.executable == b.executable && a.options == b.options;}
friend bool operator< (const Program& a, const Program& b) {return a.prepCommand < b.prepCommand || (a.prepCommand == b.prepCommand && (a.executable < b.executable || (a.executable == b.executable && a.options < b.options)));}
friend bool operator!= (const Program& a, const Program& b) {return !(a == b);}
friend bool operator> (const Program& a, const Program& b) {return b < a;}
friend bool operator>= (const Program& a, const Program& b) {return !(a < b);}
friend bool operator<= (const Program& a, const Program& b) {return !(a > b);}
public:
std::string prepCommand; // Executed before running program (must finish) upon fresh/clear start
std::string executable; // Program name, PATH is searched
Options options; // Command-line arguments supplied to executable
Expand Down

0 comments on commit d10f1f3

Please sign in to comment.