20 #ifndef JDFTX_COMMAND_COMMAND_H 21 #define JDFTX_COMMAND_COMMAND_H 23 #include <electronic/common.h> 97 Command(
string name,
string path);
111 virtual std::pair<string,string> replace(
ParamList& pl)
const=0;
126 template<
typename GetDescription>
127 string addDescriptions(
string optionList,
const GetDescription& getDescription,
string spacer=
"\n+ ")
134 getline(iss, name,
'|');
136 nameWidth = std::max(name.length(),nameWidth);
139 iss.seekg(0, std::ios::beg);
144 getline(iss, name,
'|');
146 if(!name.length())
break;
148 string desc = getDescription(name);
150 if(name.length()<nameWidth)
151 name.resize(nameWidth,
' ');
152 ret += spacer +
name;
153 if(desc.length()) ret +=
": " + desc;
173 : nameMap(nameMap), descMap(descMap)
181 { Enum type = Enum();
182 bool nameFound = nameMap.getEnum(name.c_str(), type);
184 return descMap.getString(type);
192 template<
typename Enum>
211 #endif // JDFTX_COMMAND_COMMAND_H std::map< string, DeprecatedCommand * > & getDeprecatedMap()
Retrieve the map from deprecated command names to objects.
LinkDescription(const EnumStringMap< Enum > &nameMap, const EnumStringMap< Enum > &descMap)
Definition: command.h:172
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:160
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:166
Base class for a deprecated command which will translate old syntax into the new command that replace...
Definition: command.h:104
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:193
string operator()(const string &name) const
Look name up in nameMap, and return the corresponding description in descMap.
Definition: command.h:180
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:127
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.