#pragma once /////////////////////////////////////////////////////////////////////// // CodeUtilities.h - small, generally useful, helper classes // // ver 1.3 // // Language: C++, Visual Studio 2017 // // Application: Most Projects, CSE687 - Object Oriented Design // // Author: Ammar Salmon, TA, CSE687 // // Source: Jim Fawcett, Syracuse University, CST 4-187 // // jfawcett@twcny.rr.com // /////////////////////////////////////////////////////////////////////// /* * Package Operations: * ------------------- * This package provides classes: * - ProcessCmdLine extracts path, options, patterns, and a number from command line * - Converter converts T to and from strings * - Box converts primitive type to instance of a class * - PersistFactory adds toXml() method to T * * Build Process: * -------------- * Required Files: * CodeUtilities.h * * Maintenance History: * -------------------- * ver 1.3 : 16 Aug 2018 * - added default usage text * ver 1.2 : 11 Aug 2018 * - added ProcessCmdLine::hasOption method * - fixed bugs in ProcessCmdLine::showCmdLine * and ProcessCmdLine::showOptions * ver 1.1 : 10 Aug 2018 * - added ProcessCmdLine class * ver 1.0 : 12 Jan 2018 * - first release * - refactored from earlier Utilities.h * * Notes: * ------ * - Designed to provide all functionality in header file. * - Implementation file only needed for test and demo. * * Planned Additions and Changes: * ------------------------------ * - none yet */ #include #include #include #include #include namespace Utilities { ///////////////////////////////////////////////////////////////////// // preface function // - used to add a string preface to an output, e.g., "\n " inline void preface(const std::string& msg = "", bool doReturn = true, std::ostream& out = std::cout, const std::string& prefix = " ") { if (doReturn) out << "\n" << prefix << msg; } inline std::string defaultUsage() { std::string usage; usage += "\n Command Line: path [/option]* [/pattern]* [integer]"; usage += "\n path is relative or absolute path where processing begins"; usage += "\n [/option]* are one or more options of the form /s, /r, etc."; usage += "\n [pattern]* are one or more pattern strings used for matching"; usage += "\n [integer] is the maximum number of items to process"; usage += "\n"; return usage; } ///////////////////////////////////////////////////////////////////// // ProcessCmdLine class // - extracts path, patterns, options, number class ProcessCmdLine { public: using Usage = std::string; using Path = std::string; using Option = int; using Options = std::vector