Skip to content
Snippets Groups Projects
Commit fec8f683 authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Improved template generator

Patch adapted from Toni Giorgino.

use "plumed gentemplate --list" to print list of templates
use "plumed gentemplate --include-optional --action PIPPO" to include
 optional keywords for directive PIPPO
parent 845486d0
No related branches found
No related tags found
No related merge requests found
...@@ -96,10 +96,10 @@ bool ActionRegister::printManual( const std::string& action ){ ...@@ -96,10 +96,10 @@ bool ActionRegister::printManual( const std::string& action ){
} }
} }
bool ActionRegister::printTemplate( const std::string& action ){ bool ActionRegister::printTemplate( const std::string& action, bool include_optional ){
if( check(action) ){ if( check(action) ){
Keywords keys; mk[action](keys); Keywords keys; mk[action](keys);
keys.print_template(action); keys.destroyData(); keys.print_template(action, include_optional); keys.destroyData();
return true; return true;
} else { } else {
return false; return false;
......
...@@ -76,7 +76,7 @@ public: ...@@ -76,7 +76,7 @@ public:
/// Print out the keywords for an action in html ready for input into the manual /// Print out the keywords for an action in html ready for input into the manual
bool printManual(const std::string& action); bool printManual(const std::string& action);
/// Print out a template command for an action /// Print out a template command for an action
bool printTemplate(const std::string& action); bool printTemplate(const std::string& action, bool include_optional);
void remove(creator_pointer); void remove(creator_pointer);
~ActionRegister(); ~ActionRegister();
}; };
......
...@@ -38,7 +38,7 @@ namespace PLMD { ...@@ -38,7 +38,7 @@ namespace PLMD {
gentemplate is a tool that you can use to construct template inputs for the various gentemplate is a tool that you can use to construct template inputs for the various
actions actions
The templates generated by this tool are primarily for use with Toni Giordino's vmd gui. It may be The templates generated by this tool are primarily for use with Toni Giorgino's vmd gui. It may be
useful however to use this tool as a quick aid memoir. useful however to use this tool as a quick aid memoir.
\par Examples \par Examples
...@@ -69,6 +69,8 @@ PLUMED_REGISTER_CLTOOL(CLToolGenTemplate,"gentemplate") ...@@ -69,6 +69,8 @@ PLUMED_REGISTER_CLTOOL(CLToolGenTemplate,"gentemplate")
void CLToolGenTemplate::registerKeywords( Keywords& keys ){ void CLToolGenTemplate::registerKeywords( Keywords& keys ){
CLTool::registerKeywords( keys ); CLTool::registerKeywords( keys );
keys.add("compulsory","--action","print the template for this particular action"); keys.add("compulsory","--action","print the template for this particular action");
keys.addFlag("--list",false,"print a list of the available actions");
keys.addFlag("--include-optional",false,"also print optional modifiers");
} }
CLToolGenTemplate::CLToolGenTemplate(const CLToolOptions& co ): CLToolGenTemplate::CLToolGenTemplate(const CLToolOptions& co ):
...@@ -80,15 +82,22 @@ CLTool(co) ...@@ -80,15 +82,22 @@ CLTool(co)
int CLToolGenTemplate::main(FILE* in, FILE*out,PlumedCommunicator& pc){ int CLToolGenTemplate::main(FILE* in, FILE*out,PlumedCommunicator& pc){
std::string action; std::string action;
if( !parse("--action",action) ) return 1; bool list_templates=false;
//std::cerr<<"LIST OF DOCUMENTED ACTIONS:\n"; parseFlag("--list",list_templates);
//std::cerr<<actionRegister()<<"\n";
//std::cerr<<"LIST OF DOCUMENTED COMMAND LINE TOOLS:\n"; if(list_templates) {
//std::cerr<<cltoolRegister()<<"\n\n"; std::cerr<<actionRegister()<<"\n";
if( !actionRegister().printTemplate(action) ){ return 0;
} else if(parse("--action",action)) {
bool include_optional;
parseFlag("--include-optional",include_optional);
if( !actionRegister().printTemplate(action,include_optional) ){
fprintf(stderr,"specified action is not registered\n"); fprintf(stderr,"specified action is not registered\n");
return 1; return 1;
} }
} else return 1;
return 0; return 0;
} }
......
...@@ -223,7 +223,7 @@ bool Keywords::reserved( const std::string & k ) const { ...@@ -223,7 +223,7 @@ bool Keywords::reserved( const std::string & k ) const {
return false; return false;
} }
void Keywords::print_template(const std::string& actionname) const { void Keywords::print_template(const std::string& actionname, bool include_optional) const {
unsigned nkeys=0; unsigned nkeys=0;
printf("%s",actionname.c_str()); printf("%s",actionname.c_str());
for(unsigned i=0;i<keys.size();++i){ for(unsigned i=0;i<keys.size();++i){
...@@ -242,7 +242,8 @@ void Keywords::print_template(const std::string& actionname) const { ...@@ -242,7 +242,8 @@ void Keywords::print_template(const std::string& actionname) const {
} }
nkeys=0; nkeys=0;
for(unsigned i=0;i<keys.size();++i){ for(unsigned i=0;i<keys.size();++i){
if ( (types.find(keys[i])->second).isCompulsory() ) nkeys++; if ( include_optional || \
(types.find(keys[i])->second).isCompulsory() ) nkeys++;
} }
if( nkeys>0 ){ if( nkeys>0 ){
for(unsigned i=0;i<keys.size();++i){ for(unsigned i=0;i<keys.size();++i){
...@@ -253,7 +254,10 @@ void Keywords::print_template(const std::string& actionname) const { ...@@ -253,7 +254,10 @@ void Keywords::print_template(const std::string& actionname) const {
} else { } else {
printf(" %s= ", keys[i].c_str() ); printf(" %s= ", keys[i].c_str() );
} }
} } else if (include_optional) {
// TG no defaults for optional keywords?
printf(" [%s]", keys[i].c_str() );
}
} }
} }
printf("\n"); printf("\n");
......
...@@ -120,7 +120,7 @@ public: ...@@ -120,7 +120,7 @@ public:
/// Print an html version of the documentation /// Print an html version of the documentation
void print_html( const bool isaction ) const ; void print_html( const bool isaction ) const ;
/// Print the template version for the documenation /// Print the template version for the documenation
void print_template( const std::string& actionname) const ; void print_template( const std::string& actionname, bool include_optional) const ;
/// Change the style of a keyword /// Change the style of a keyword
void reset_style( const std::string & k, const std::string & style ); void reset_style( const std::string & k, const std::string & style );
/// Add keywords from one keyword object to another /// Add keywords from one keyword object to another
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment