// Author: Matt Johnson // FileName: parsedTokens.h // Course: CS 284 - Operating Systems // Section: A // Instructor: Matt Johnson // // This is the header file which contains the class definition of the // parsedTokens class. The job of the parsedTokens class is to parse out the // command line and store the tokens. // // Current Version is 1.0. // // Revision History // ------------------------------------------------------------------------ // Version 0.1: // Spring Semester 2004 // - Created class. // Version 0.2: // Spring Semester 2004 // - Added the ability to execute a basic command from from the command line. // - Added a PrintTokens function which will output the data stored in the // object. // ------------------------------------------------------------------------ // Version 1.0: // September 15, 2004 // - Cleaned up class for use by students in CS 284. // - Class parses and stores the command line tokens. // ------------------------------------------------------------------------ #ifndef parsedTokens_h #define parsedTokens_h #include #include #include #include using std::vector; using std::string; class ParsedTokens { public: // PreConditions: None. // PostConditions: Object is created. ParsedTokens(); // PreConditions: None. // PostConditions: Object is destroyed. ~ParsedTokens(); // PreConditions: The char* argument must be a command line from the // shell. It should be properly formatted and delimited. // PostConditions: Tokens are removed and added to this container. void ParseAndAddTokens(char * commandLine); // PreConditions: None. // PostConditions: Internal iterator starts at the beginning of the // containter. void StartIterator(); // PreConditions: None. // PostConditions: The inToken argument has been set to the next token. // If the operation has succeeded, it will return true. // Otherwise, it will return false. bool GetNextToken(std::string &inToken); // PreConditions: The ostream object must be open and ready for writing. // PostConditions: Contents of the container will be sent to the ostream // object. void PrintTokens(std::ostream &ofile, char *args[] = 0); // PreConditions: None. // PostConditions: Container is empty. void Clear(); // PreConditions: None. // PostConditions: Returns the number of tokens stored. unsigned int GetNumTokens(); unsigned int GetNumPipes(); string operator[](unsigned int index); private: // PreConditions: None. // PostConditions: Function will return true or false, which will // indicate whether the input character is a delimiter. bool IsDelimiter(char ch); // PreConditions: User must specify whether to add the special character // to the container with the second bool argument. // PostConditions: Function will return true or false, which will // indicate whether the input character is a special // character. If the character is indeed a special // character, and the user specified true in the second // argument, that character will be added to the // container as a seperate token. bool IsSpecialCharacter(char ch, bool addToContainer); std::vector tokens_; unsigned int iterCount_; }; #endif