20 #ifndef JDFTX_COMMAND_COMMAND_H 21 #define JDFTX_COMMAND_COMMAND_H 23 #include <electronic/common.h> 97 Command(
string name,
string path);
114 template<
typename GetDescription>
115 string addDescriptions(
string optionList,
const GetDescription& getDescription,
string spacer=
"\n+ ")
122 getline(iss, name,
'|');
124 nameWidth = std::max(name.length(),nameWidth);
127 iss.seekg(0, std::ios::beg);
132 getline(iss, name,
'|');
134 if(!name.length())
break;
136 string desc = getDescription(name);
138 if(name.length()<nameWidth)
139 name.resize(nameWidth,
' ');
140 ret += spacer +
name;
141 if(desc.length()) ret +=
": " + desc;
161 : nameMap(nameMap), descMap(descMap)
169 { Enum type = Enum();
170 bool nameFound = nameMap.getEnum(name.c_str(), type);
172 return descMap.getString(type);
180 template<
typename Enum>
199 #endif // JDFTX_COMMAND_COMMAND_H LinkDescription(const EnumStringMap< Enum > &nameMap, const EnumStringMap< Enum > &descMap)
Definition: command.h:160
STL strings and streams with case insensitive comparison.
string nullDescription(const string &)
Null description function that can be used with addDescriptions(). This can be useful for simply refo...
Definition: command.h:148
virtual void printStatus(Everything &e, int iRep)=0
Print a command line that would result in the current status.
A template to ease option parsing (maps enums <–> strings)
Definition: Util.h:179
string name
Identifier for the command in the input file. Must be unique!
Definition: command.h:64
string subcategory
Subcategory of command under which to list the documentation.
Definition: command.h:69
void require(string)
utility to add a command to the requires list
bool isReadable(string fname)
Check if file is readable in an MPI friendly way. This function must be called from all processes...
string emptyParamError
Error message if command is manually issued with no parameters. Ddefault: empty i.e. allow empty parameter list.
Definition: command.h:76
Generate a description functor for addDescriptions() from an EnumStringMap.
Definition: command.h:154
bool allowMultiple
Whether this command can occur multiple times in an input file (default: false).
Definition: command.h:74
Helper class for parsing command lines in input file.
std::map< string, Command * > & getCommandMap()
Retrieve the map from command names to objects created during static initialization.
std::set< string > forbids
Names of other commands that this one is incompatibile with.
Definition: command.h:72
string comments
Detailed help for the command which goes into jdftx -t as well as the Doxygen manual. Please check formatting in both versions.
Definition: command.h:66
string category
Category of command under which to list the documentation.
Definition: command.h:68
Command(string name, string path)
void forbid(string)
utility to add a command to the forbids list
LinkDescription< Enum > linkDescription(const EnumStringMap< Enum > &nameMap, const EnumStringMap< Enum > &descMap)
Helper function to select appropriate LinkDescription<> by overloading.
Definition: command.h:181
string operator()(const string &name) const
Look name up in nameMap, and return the corresponding description in descMap.
Definition: command.h:168
void trim(string &s)
Remove leading and trailing spaces from a string.
Definition: string.h:45
Definition: Everything.h:41
string format
Usage syntax for the command (excluding the command name)
Definition: command.h:65
Wrapper to std::istringstream that eases parsing of input file command lines.
Definition: ParamList.h:30
Abstract base class for all commands.
Definition: command.h:61
std::set< string > requires
Names of other commands that this one requires; those commands will be processed before this one...
Definition: command.h:71
string addDescriptions(string optionList, const GetDescription &getDescription, string spacer="\n+ ")
Process the EnumStringMap::optionList() to add descriptions using an arbitrary functor.
Definition: command.h:115
string section
Which executable the command belongs to, and hence which section it must be documented under...
Definition: command.h:67
bool hasDefault
Whether this command has a default (default: false). If true, process() will be called with an empty ...
Definition: command.h:75
std::basic_string< char, ichar_traits > string
Case-insensitive string.
Definition: string.h:42
std::shared_ptr< SpeciesInfo > findSpecies(string id, Everything &e)
Find species matching an id (and create it from a wildcard if necessary)
#define assert(expr)
A custom assertion with stack trace (NOTE: enabled in release modes as well)
Definition: Util.h:100
virtual void process(ParamList &pl, Everything &e)=0
Process the command from its command line.