// // Copyright (c) 2004-2017 Benjamin Kaufmann // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to // deal in the Software without restriction, including without limitation the // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or // sell copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS // IN THE SOFTWARE. // // // NOTE: ProgramOptions is inspired by Boost.Program_options // see: www.boost.org/libs/program_options // #ifndef PROGRAM_OPTIONS_PROGRAM_OPTIONS_H_INCLUDED #define PROGRAM_OPTIONS_PROGRAM_OPTIONS_H_INCLUDED #include #include #include #include #include #include #include #include namespace Potassco { namespace ProgramOptions { //! Represents one program option. /*! * An Option consists of a description (long name, short name, description), * a (typed) value, and an optional default value. * * \note * When printing an option, occurrences of %D, %I and %A in its description are replaced * with the option's default value, implicit value and the argument name, * respectively. */ class Option : public detail::RefCountable { public: /*! * \pre longName != "" * \pre vd != 0 * \param longName name (and unique key) of the option * \param shortName possible alias name * \param description description of the option, used for printing help * \param value value object to be associated with this option */ Option(const std::string& longName, char shortName, const char* description, Value* value); ~Option(); const std::string& name() const { return name_; } char alias() const { return value_->alias(); } Value* value() const { return value_; } const char* description() const { return description_; } const char* argName() const { return value_->arg(); } bool assignDefault() const; std::size_t maxColumn() const; DescriptionLevel descLevel() const { return value_->level(); } private: std::string name_; // name (and unique key) of option const char* description_; // description of the option (used for --help) Value* value_; // the option's value manager }; typedef detail::IntrusiveSharedPtr