// CommandLine.h #ifndef CommandLine_H #define CommandLine_H // David Adams // September 2002 // // Describes a command line as a name (command) plus a list of // arguments. // // XML format: // // CommandLine // name = myexe // CommandLineArgument // value = arg1 // CommandLineArgument // value = arg2 #include #include #include class XmlElement; class Text; class CommandLine { public: // typedefs typedef std::string Name; typedef Name Argument; typedef std::vector ArgumentList; typedef std::vector CargList; private: // data // Name. Name m_name; // Arguments. ArgumentList m_args; // Name plus arguments. CargList m_argv; public: // static functions // Return the XML name. static const char* xml_name() { return "CommandLine"; } // Return the DTD. static const Text& dtd(); public: // functions // Default constructor. // Creates invalid command line. CommandLine(); // Constructor from command and arguments. CommandLine(Name name, ArgumentList args); // Constructor from null-terminated char* array. explicit CommandLine(const char* const* argv); // Constructor from non-terminated char* array argv // of length narg. CommandLine(int narg, const char* const* argv); // Constructor from XML. CommandLine(const XmlElement& ele); // Validity check. bool is_valid() const; // Return the name. Name name() const; // Return the as a C-string. const char* cname() const; // Return the argument list. const ArgumentList& arguments() const; // Return a pointer to an an array of char* holding the // name followed by the arguments. // This is the form used in unix exec commands. // Valid as long as this object is not deleted. const char* const* argv() const; // Same as above except array is char instaead of // const char. This allows a devious user to // corrrupt the array but is the type required // for POSIX exec commands. char* const* unsafe_argv() const; // Write to xml. // Caller is responsible for managing the returned object. const XmlElement* xml() const; }; // Output stream. std::ostream& operator<<(std::ostream& lhs, const CommandLine& rhs); // Equality. bool operator==(const CommandLine& lhs, const CommandLine rhs); // Inequality. bool operator!=(const CommandLine& lhs, const CommandLine rhs); #endif