//////////////////////////////////////////////////////////////////////////////// /// 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 triagens { namespace basics { //////////////////////////////////////////////////////////////////////////////// /// @brief ProgramOptionsDescription //////////////////////////////////////////////////////////////////////////////// class ProgramOptionsDescription { friend class ProgramOptions; public: //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription(); //////////////////////////////////////////////////////////////////////////////// /// @brief constructor //////////////////////////////////////////////////////////////////////////////// explicit ProgramOptionsDescription(const std::string& name); //////////////////////////////////////////////////////////////////////////////// /// @brief copy constructor //////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription(const ProgramOptionsDescription&); //////////////////////////////////////////////////////////////////////////////// /// @brief assignment constructor //////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator=(const ProgramOptionsDescription&); public: //////////////////////////////////////////////////////////////////////////////// /// @brief changes the name //////////////////////////////////////////////////////////////////////////////// void setName(const std::string& name); //////////////////////////////////////////////////////////////////////////////// /// @brief adds a new visible or hidden section //////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(ProgramOptionsDescription&, bool hidden = false); //////////////////////////////////////////////////////////////////////////////// /// @brief adds a new flag //////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(const std::string& name, const std::string& text); //////////////////////////////////////////////////////////////////////////////// /// @brief adds a string argument //////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(const std::string& name, std::string* value, const std::string& text); //////////////////////////////////////////////////////////////////////////////// /// @brief adds a string vector argument //////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(const std::string& name, std::vector* value, const std::string& text); //////////////////////////////////////////////////////////////////////////////// /// @brief adds an int32_t argument //////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(const std::string& name, int32_t* value, const std::string& text); //////////////////////////////////////////////////////////////////////////////// /// @brief adds an int32_t vector argument //////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(const std::string& name, std::vector* value, const std::string& text); //////////////////////////////////////////////////////////////////////////////// /// @brief adds an int64_t argument //////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(const std::string& name, int64_t* value, const std::string& text); //////////////////////////////////////////////////////////////////////////////// /// @brief adds an int64_t vector argument //////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(const std::string& name, std::vector* value, const std::string& text); //////////////////////////////////////////////////////////////////////////////// /// @brief adds an uint32_t argument //////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(const std::string& name, uint32_t* value, const std::string& text); //////////////////////////////////////////////////////////////////////////////// /// @brief adds an uint32_t vector argument //////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(const std::string& name, std::vector* value, const std::string& text); //////////////////////////////////////////////////////////////////////////////// /// @brief adds an uint64_t argument //////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(const std::string& name, uint64_t* value, const std::string& text); //////////////////////////////////////////////////////////////////////////////// /// @brief adds an uint64_t vector argument //////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(const std::string& name, std::vector* value, const std::string& text); //////////////////////////////////////////////////////////////////////////////// /// @brief adds a double argument //////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(const std::string& name, double* value, const std::string& text); //////////////////////////////////////////////////////////////////////////////// /// @brief adds a double vector argument //////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(const std::string& name, std::vector* value, const std::string& text); //////////////////////////////////////////////////////////////////////////////// /// @brief adds a boolean argument //////////////////////////////////////////////////////////////////////////////// ProgramOptionsDescription& operator()(const std::string& name, bool* value, const std::string& text); //////////////////////////////////////////////////////////////////////////////// /// @brief adds a time_t argument //////////////////////////////////////////////////////////////////////////////// #if __WORDSIZE == 32 ProgramOptionsDescription& operator()(const std::string& name, time_t* value, const std::string& 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(const std::set& help, std::map& names) const; //////////////////////////////////////////////////////////////////////////////// /// @brief returns the usage message for given sections //////////////////////////////////////////////////////////////////////////////// std::string usageString(const std::set& help, const std::map& names, size_t oWidth) const; //////////////////////////////////////////////////////////////////////////////// /// @brief constructs the usage string //////////////////////////////////////////////////////////////////////////////// std::string usageString(const std::map& names, size_t oWidth) const; //////////////////////////////////////////////////////////////////////////////// /// @brief checks if the name is an option, defines short/long mapping //////////////////////////////////////////////////////////////////////////////// std::string check(const std::string& name); //////////////////////////////////////////////////////////////////////////////// /// @brief checks if the name is an option, defines short/long mapping //////////////////////////////////////////////////////////////////////////////// std::string check(const std::string& 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