//////////////////////////////////////////////////////////////////////////////// /// DISCLAIMER /// /// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany /// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// /// Copyright holder is ArangoDB GmbH, Cologne, Germany /// /// @author Dr. Frank Celler //////////////////////////////////////////////////////////////////////////////// #ifndef LIB_BASICS_PROGRAM_OPTIONS_DESCRIPTION_H #define LIB_BASICS_PROGRAM_OPTIONS_DESCRIPTION_H 1 #include "Basics/Common.h" #include struct TRI_json_t; namespace arangodb { namespace basics { //////////////////////////////////////////////////////////////////////////////// /// @brief ProgramOptionsDescription //////////////////////////////////////////////////////////////////////////////// class ProgramOptionsDescription { friend class ProgramOptions; public: ProgramOptionsDescription(); explicit ProgramOptionsDescription(std::string const& name); ////////////////////////////////////////////////////////////////////////////// /// @brief copy constructor ////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription(const ProgramOptionsDescription&); ////////////////////////////////////////////////////////////////////////////// /// @brief assignment constructor ////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator=(const ProgramOptionsDescription&); public: ////////////////////////////////////////////////////////////////////////////// /// @brief changes the name ////////////////////////////////////////////////////////////////////////////// void setName(std::string const& name); ////////////////////////////////////////////////////////////////////////////// /// @brief adds a new visible or hidden section ////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(ProgramOptionsDescription&, bool hidden = false); ////////////////////////////////////////////////////////////////////////////// /// @brief adds a new flag ////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(std::string const& name, std::string const& text); ////////////////////////////////////////////////////////////////////////////// /// @brief adds a string argument ////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(std::string const& name, std::string* value, std::string const& text); ////////////////////////////////////////////////////////////////////////////// /// @brief adds a string vector argument ////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(std::string const& name, std::vector* value, std::string const& text); ////////////////////////////////////////////////////////////////////////////// /// @brief adds an int32_t argument ////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(std::string const& name, int32_t* value, std::string const& text); ////////////////////////////////////////////////////////////////////////////// /// @brief adds an int32_t vector argument ////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(std::string const& name, std::vector* value, std::string const& text); ////////////////////////////////////////////////////////////////////////////// /// @brief adds an int64_t argument ////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(std::string const& name, int64_t* value, std::string const& text); ////////////////////////////////////////////////////////////////////////////// /// @brief adds an int64_t vector argument ////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(std::string const& name, std::vector* value, std::string const& text); ////////////////////////////////////////////////////////////////////////////// /// @brief adds an uint32_t argument ////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(std::string const& name, uint32_t* value, std::string const& text); ////////////////////////////////////////////////////////////////////////////// /// @brief adds an uint32_t vector argument ////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(std::string const& name, std::vector* value, std::string const& text); ////////////////////////////////////////////////////////////////////////////// /// @brief adds an uint64_t argument ////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(std::string const& name, uint64_t* value, std::string const& text); ////////////////////////////////////////////////////////////////////////////// /// @brief adds an uint64_t vector argument ////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(std::string const& name, std::vector* value, std::string const& text); ////////////////////////////////////////////////////////////////////////////// /// @brief adds a double argument ////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(std::string const& name, double* value, std::string const& text); ////////////////////////////////////////////////////////////////////////////// /// @brief adds a double vector argument ////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(std::string const& name, std::vector* value, std::string const& text); ////////////////////////////////////////////////////////////////////////////// /// @brief adds a boolean argument ////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(std::string const& name, bool* value, std::string const& text); //////////////////////////////////////////////////////////////////////////////// /// @brief adds a time_t argument //////////////////////////////////////////////////////////////////////////////// #if __WORDSIZE == 32 ProgramOptionsDescription& operator()(std::string const& name, time_t* value, std::string const& text); #endif ////////////////////////////////////////////////////////////////////////////// /// @brief adds positional arguments ////////////////////////////////////////////////////////////////////////////// void arguments(std::vector*); ////////////////////////////////////////////////////////////////////////////// /// @brief returns the usage message ////////////////////////////////////////////////////////////////////////////// std::string usage() const; ////////////////////////////////////////////////////////////////////////////// /// @brief returns the usage message for given sections ////////////////////////////////////////////////////////////////////////////// std::string usage(std::set help) const; ////////////////////////////////////////////////////////////////////////////// /// @brief returns a list of help options ////////////////////////////////////////////////////////////////////////////// std::set helpOptions() const; ////////////////////////////////////////////////////////////////////////////// /// @brief get default value for an option ////////////////////////////////////////////////////////////////////////////// struct TRI_json_t* getDefault(std::string const&) const; private: ////////////////////////////////////////////////////////////////////////////// /// @brief option types ////////////////////////////////////////////////////////////////////////////// enum option_type_e { OPTION_TYPE_FLAG, OPTION_TYPE_STRING, OPTION_TYPE_VECTOR_STRING, OPTION_TYPE_INT32, OPTION_TYPE_VECTOR_INT64, OPTION_TYPE_INT64, OPTION_TYPE_VECTOR_INT32, OPTION_TYPE_UINT32, OPTION_TYPE_VECTOR_UINT32, OPTION_TYPE_UINT64, OPTION_TYPE_VECTOR_UINT64, OPTION_TYPE_DOUBLE, OPTION_TYPE_VECTOR_DOUBLE, OPTION_TYPE_BOOL, OPTION_TYPE_TIME }; private: ////////////////////////////////////////////////////////////////////////////// /// @brief computes all names ////////////////////////////////////////////////////////////////////////////// void fillAllNames(std::set const& help, std::map& names) const; ////////////////////////////////////////////////////////////////////////////// /// @brief returns the usage message for given sections ////////////////////////////////////////////////////////////////////////////// std::string usageString(std::set const& help, std::map const& names, size_t oWidth) const; ////////////////////////////////////////////////////////////////////////////// /// @brief constructs the usage string ////////////////////////////////////////////////////////////////////////////// std::string usageString(std::map const& names, size_t oWidth) const; ////////////////////////////////////////////////////////////////////////////// /// @brief checks if the name is an option, defines short/long mapping ////////////////////////////////////////////////////////////////////////////// std::string check(std::string const& name); ////////////////////////////////////////////////////////////////////////////// /// @brief checks if the name is an option, defines short/long mapping ////////////////////////////////////////////////////////////////////////////// std::string check(std::string const& name, void* value); private: ////////////////////////////////////////////////////////////////////////////// /// @brief name of the section ////////////////////////////////////////////////////////////////////////////// std::string _name; ////////////////////////////////////////////////////////////////////////////// /// @brief help options ////////////////////////////////////////////////////////////////////////////// std::set _helpOptions; ////////////////////////////////////////////////////////////////////////////// /// @brief sub-descriptions ////////////////////////////////////////////////////////////////////////////// std::vector _subDescriptions; ////////////////////////////////////////////////////////////////////////////// /// @brief hidden sub-descriptions ////////////////////////////////////////////////////////////////////////////// std::vector _hiddenSubDescriptions; ////////////////////////////////////////////////////////////////////////////// /// @brief defined option names ////////////////////////////////////////////////////////////////////////////// std::vector _optionNames; ////////////////////////////////////////////////////////////////////////////// /// @brief type of an option ////////////////////////////////////////////////////////////////////////////// std::map _optionTypes; ////////////////////////////////////////////////////////////////////////////// /// @brief short name of an option ////////////////////////////////////////////////////////////////////////////// std::map _long2short; ////////////////////////////////////////////////////////////////////////////// /// @brief help text of an option ////////////////////////////////////////////////////////////////////////////// std::map _helpTexts; ////////////////////////////////////////////////////////////////////////////// /// @brief default of an option ////////////////////////////////////////////////////////////////////////////// std::map _defaultTexts; ////////////////////////////////////////////////////////////////////////////// /// @brief current text of an option ////////////////////////////////////////////////////////////////////////////// std::map> _currentTexts; ////////////////////////////////////////////////////////////////////////////// /// @brief value of an option ////////////////////////////////////////////////////////////////////////////// std::map _values; ////////////////////////////////////////////////////////////////////////////// /// @brief all string options ////////////////////////////////////////////////////////////////////////////// std::map _stringOptions; ////////////////////////////////////////////////////////////////////////////// /// @brief all vector string options ////////////////////////////////////////////////////////////////////////////// std::map*> _vectorStringOptions; ////////////////////////////////////////////////////////////////////////////// /// @brief all int32 options ////////////////////////////////////////////////////////////////////////////// std::map _int32Options; ////////////////////////////////////////////////////////////////////////////// /// @brief all vector int32 options ////////////////////////////////////////////////////////////////////////////// std::map*> _vectorInt32Options; ////////////////////////////////////////////////////////////////////////////// /// @brief all int64 options ////////////////////////////////////////////////////////////////////////////// std::map _int64Options; ////////////////////////////////////////////////////////////////////////////// /// @brief all vector int64 options ////////////////////////////////////////////////////////////////////////////// std::map*> _vectorInt64Options; ////////////////////////////////////////////////////////////////////////////// /// @brief all uint32 options ////////////////////////////////////////////////////////////////////////////// std::map _uint32Options; ////////////////////////////////////////////////////////////////////////////// /// @brief all vector uint32 options ////////////////////////////////////////////////////////////////////////////// std::map*> _vectorUInt32Options; ////////////////////////////////////////////////////////////////////////////// /// @brief all uint64 options ////////////////////////////////////////////////////////////////////////////// std::map _uint64Options; ////////////////////////////////////////////////////////////////////////////// /// @brief all vector uint64 options ////////////////////////////////////////////////////////////////////////////// std::map*> _vectorUInt64Options; ////////////////////////////////////////////////////////////////////////////// /// @brief all double options ////////////////////////////////////////////////////////////////////////////// std::map _doubleOptions; ////////////////////////////////////////////////////////////////////////////// /// @brief all vector double options ////////////////////////////////////////////////////////////////////////////// std::map*> _vectorDoubleOptions; ////////////////////////////////////////////////////////////////////////////// /// @brief all boolean options ////////////////////////////////////////////////////////////////////////////// std::map _boolOptions; //////////////////////////////////////////////////////////////////////////////// /// @brief all time options //////////////////////////////////////////////////////////////////////////////// #if __WORDSIZE == 32 std::map _timeOptions; #endif ////////////////////////////////////////////////////////////////////////////// /// @brief all positional arguments ////////////////////////////////////////////////////////////////////////////// std::vector* _positionals; }; } } #endif