Simpatico  v1.10
CommandManager.cpp
1 /*
2 * Simpatico - Simulation Package for Polymeric and Molecular Liquids
3 *
4 * Copyright 2010 - 2017, The Regents of the University of Minnesota
5 * Distributed under the terms of the GNU General Public License.
6 */
7 
8 #include "CommandManager.h"
9 
10 namespace McMd
11 {
12 
13  using namespace Util;
14 
15  // Constructor.
17  : Manager<Command>(true)
18  { setClassName("CommandManager"); }
19 
20 
21  // Destructor.
23  {}
24 
25  bool
26  CommandManager::readCommand(std::string name, std::istream& in)
27  {
28  // Attempt to match one of the standard commands
29  bool success = readStandardCommand(name, in);
30  if (success) {
31  return true;
32  }
33 
34  // Attempt to match a customized command
35  for (int i = 0; i < size(); ++i) {
36  Command& command = (*this)[i];
37  if (command.match(name)) {
38  command.execute(in);
39  // Success: Match and execution
40  return true;
41  }
42  }
43 
44  // Failure: If this point was reach, no match was found
45  return false;
46  }
47 
48  bool
49  CommandManager::readStandardCommand(std::string name, std::istream& in)
50  { return false; }
51 
52 }
virtual bool readStandardCommand(std::string name, std::istream &in)
Attempt to read a standard built-in command, execute if recognized.
CommandManager()
Constructor.
virtual void execute(std::istream &in)=0
Execute this command.
Template container for pointers to objects with a common base class.
Definition: Manager.h:38
Utility classes for scientific computation.
Definition: accumulators.mod:1
Command is an object that can be invoked from the command script.
Definition: Command.h:40
virtual bool match(std::string name)
Compare a string to the name of this command.
Definition: Command.cpp:32
Single-processor Monte Carlo (MC) and molecular dynamics (MD).
virtual ~CommandManager()
Destructor.
void setClassName(const char *className)
Set class name string.
int size() const
Get logical size.
bool readCommand(std::string name, std::istream &in)
Attempt to read a command line, execute if recognized.