JDFTx  1.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
command.h File Reference

Provides the base class and various helpers for defining commands in the input file. More...

#include <electronic/common.h>
#include <commands/ParamList.h>
#include <core/string.h>
#include <memory>
#include <set>

Classes

class  Command
 Abstract base class for all commands. More...
 
class  DeprecatedCommand
 Base class for a deprecated command which will translate old syntax into the new command that replaces it. More...
 
struct  LinkDescription< Enum >
 Generate a description functor for addDescriptions() from an EnumStringMap. More...
 

Functions

std::map< string, Command * > & getCommandMap ()
 Retrieve the map from command names to objects created during static initialization.
 
std::map< string,
DeprecatedCommand * > & 
getDeprecatedMap ()
 Retrieve the map from deprecated command names to objects.
 
template<typename GetDescription >
string addDescriptions (string optionList, const GetDescription &getDescription, string spacer="\n+ ")
 Process the EnumStringMap::optionList() to add descriptions using an arbitrary functor. More...
 
string nullDescription (const string &)
 Null description function that can be used with addDescriptions(). This can be useful for simply reformatting EnumStringMap::optionList()
 
template<typename Enum >
LinkDescription< Enum > linkDescription (const EnumStringMap< Enum > &nameMap, const EnumStringMap< Enum > &descMap)
 Helper function to select appropriate LinkDescription<> by overloading. More...
 
std::shared_ptr< SpeciesInfofindSpecies (string id, Everything &e)
 Find species matching an id (and create it from a wildcard if necessary) More...
 
bool isReadable (string fname)
 Check if file is readable in an MPI friendly way. This function must be called from all processes, the file will be checked on one process and the result broadcast to all processes. More...
 
void setAvailableFilename (string filenamePattern, string varName, string &target)
 
void setAvailableFilenames (string filenamePattern, Everything &e)
 Apply setAvailableFilename for all standard input variables (action of CommandInitialState)
 

Detailed Description

Provides the base class and various helpers for defining commands in the input file.

To create a new command, paste this code block into a cpp file, replace all occurences of dummy with something suitable, add the documentation strings (format and comment) and the parse code. See any of the existing commands for examples of using ParamList effectively. Note that there is no need to edit any global list of commands, this happens automatically during static initialization, just create an object of the new derived Command class at file scope. However, for coherent documentation, edit doc/commands.dox and link to the command in the appropriate section.

    struct CommandDummy : public Command
    {
            CommandDummy() : Command("dummy")
            {
                    format = "";
                    comments = "";
            }

            void process(ParamList& pl, Everything& e)
            {
            }

            void printStatus(Everything& e, int iRep)
            {
            }
    }
    commandDummy;

Function Documentation

template<typename GetDescription >
string addDescriptions ( string  optionList,
const GetDescription &  getDescription,
string  spacer = "\n+ " 
)

Process the EnumStringMap::optionList() to add descriptions using an arbitrary functor.

Template Parameters
GetDescriptionFunction/functor with the signature string GetDescription(const string&).
Parameters
optionListList of strings separated by pipe characters as returned by EnumStringMap::optionList()
getDescriptionA function/functor that returns the description given an option from optionList
spacerSpacer to insert before each option/description pair
Returns
string containing the options along with their descriptions
std::shared_ptr<SpeciesInfo> findSpecies ( string  id,
Everything e 
)

Find species matching an id (and create it from a wildcard if necessary)

Parameters
idPsuedopotential species identifier string (typically chemical symbol)
eReference to Everything
Returns
Smart pointer to SpeciesInfo corresponding to id.
bool isReadable ( string  fname)

Check if file is readable in an MPI friendly way. This function must be called from all processes, the file will be checked on one process and the result broadcast to all processes.

Parameters
fnameFile name to check for
Returns
Whether file is readable
template<typename Enum >
LinkDescription<Enum> linkDescription ( const EnumStringMap< Enum > &  nameMap,
const EnumStringMap< Enum > &  descMap 
)

Helper function to select appropriate LinkDescription<> by overloading.

Template Parameters
EnumThe template parameter of EnumStringMap
Parameters
nameMapLink between enum members to corresponding name strings
descMapLink between enum members to corresponding description strings
void setAvailableFilename ( string  filenamePattern,
string  varName,
string target 
)

Set target to the filename for reading variable varName from file with pattern specified by filenamePattern if that file exists and is readable