Frobby  0.9.5
Action.cpp
Go to the documentation of this file.
1 /* Frobby: Software for monomial ideal computations.
2  Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see http://www.gnu.org/licenses/.
16 */
17 #include "stdinc.h"
18 #include "Action.h"
19 
20 #include "error.h"
21 #include "NameFactory.h"
22 
23 #include "IrreducibleDecomAction.h"
24 #include "TransformAction.h"
25 #include "HelpAction.h"
26 #include "DynamicFrobeniusAction.h"
27 #include "GenerateIdealAction.h"
29 #include "FrobeniusAction.h"
30 #include "AnalyzeAction.h"
31 #include "LatticeFormatAction.h"
32 #include "IntersectionAction.h"
33 #include "AssociatedPrimesAction.h"
34 #include "AlexanderDualAction.h"
35 #include "HilbertAction.h"
36 #include "PolyTransformAction.h"
37 #include "HelpAction.h"
38 #include "TestAction.h"
39 #include "PrimaryDecomAction.h"
40 #include "OptimizeAction.h"
41 #include "MaximalStandardAction.h"
42 #include "LatticeAnalyzeAction.h"
43 #include "DimensionAction.h"
44 #include "EulerAction.h"
45 
46 Action::Action(const char* name,
47  const char* shortDescription,
48  const char* description,
49  bool acceptsNonParameterParam):
50  _name(name),
51  _shortDescription(shortDescription),
52  _description(description),
53  _acceptsNonParameter(acceptsNonParameterParam),
54  _printActions("time", "Display and time each subcomputation.", false) {
55 
57 }
58 
60 }
61 
62 namespace {
63  typedef NameFactory<Action> ActionFactory;
64 
65  ActionFactory getActionFactory() {
66  ActionFactory factory("action");
67 
68  nameFactoryRegister<HilbertAction>(factory);
69  nameFactoryRegister<EulerAction>(factory);
70  nameFactoryRegister<IrreducibleDecomAction>(factory);
71  nameFactoryRegister<PrimaryDecomAction>(factory);
72  nameFactoryRegister<AlexanderDualAction>(factory);
73  nameFactoryRegister<AssociatedPrimesAction>(factory);
74  nameFactoryRegister<MaximalStandardAction>(factory);
75  nameFactoryRegister<DimensionAction>(factory);
76  nameFactoryRegister<OptimizeAction>(factory);
77 
78  nameFactoryRegister<TransformAction>(factory);
79  nameFactoryRegister<PolyTransformAction>(factory);
80 
81  nameFactoryRegister<IntersectionAction>(factory);
82  nameFactoryRegister<GenerateIdealAction>(factory);
83  nameFactoryRegister<FrobeniusAction>(factory);
84  nameFactoryRegister<DynamicFrobeniusAction>(factory);
85  nameFactoryRegister<GenerateFrobeniusAction>(factory);
86  nameFactoryRegister<AnalyzeAction>(factory);
87  nameFactoryRegister<LatticeFormatAction>(factory);
88  nameFactoryRegister<LatticeAnalyzeAction>(factory);
89 
90  nameFactoryRegister<HelpAction>(factory);
91  nameFactoryRegister<TestAction>(factory);
92 
93  return factory;
94  }
95 }
96 
97 bool Action::displayAction() const {
98  return true;
99 }
100 
101 const Parameter& Action::getParam(const string& name) const {
102  return _params.getParam(name);
103 }
104 
105 void Action::getActionNames(vector<string>& names) {
106  getActionFactory().getNamesWithPrefix("", names);
107 }
108 
109 auto_ptr<Action> Action::createActionWithPrefix(const string& prefix) {
110  return createWithPrefix(getActionFactory(), prefix);
111 }
112 
113 const char* Action::getName() const {
114  return _name;
115 }
116 
117 const char* Action::getShortDescription() const {
118  return _shortDescription;
119 }
120 
121 const char* Action::getDescription() const {
122  return _description;
123 }
124 
126  return _acceptsNonParameter;
127 }
128 
129 void Action::processNonParameter(const char*) {
130  reportInternalError("Action::processNonParameter called.");
131 }
132 
133 void Action::obtainParameters(vector<Parameter*>& parameters) {
134  parameters.insert(parameters.end(), _params.begin(), _params.end());
135 }
136 
137 void Action::parseCommandLine(unsigned int tokenCount, const char** tokens) {
138  vector<Parameter*> tmp;
139  obtainParameters(tmp);
140  for (size_t i = 0; i < tmp.size(); ++i)
141  if (!_params.hasParam(tmp[i]->getName()))
142  _params.add(*tmp[i]);
143 
144  if (acceptsNonParameter() && tokenCount > 0 && tokens[0][0] != '-') {
145  processNonParameter(tokens[0]);
146  --tokenCount;
147  ++tokens;
148  }
149 
150  _params.parseCommandLine(tokenCount, tokens);
151 }
auto_ptr< AbstractProduct > createWithPrefix(const NameFactory< AbstractProduct > &factory, const string &prefix)
Creates the unique product that has the indicated prefix, or create the actual product that has name ...
Definition: NameFactory.h:154
const char * getName() const
Definition: Action.cpp:113
CliParams _params
Definition: Action.h:59
BoolParameter _printActions
Definition: Action.h:68
static auto_ptr< Action > createActionWithPrefix(const string &prefix)
Definition: Action.cpp:109
Action(const char *name, const char *shortDescription, const char *description, bool acceptsNonParameter)
Definition: Action.cpp:46
virtual void parseCommandLine(unsigned int tokenCount, const char **tokens)
Definition: Action.cpp:137
const char * getDescription() const
Definition: Action.cpp:121
bool acceptsNonParameter() const
Definition: Action.cpp:125
virtual void processNonParameter(const char *str)
Definition: Action.cpp:129
const char * _shortDescription
Definition: Action.h:64
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition: Action.cpp:133
virtual bool displayAction() const
Returns whether this action should be shown to the user by the help action.
Definition: Action.cpp:97
const char * _description
Definition: Action.h:65
static void getActionNames(vector< string > &names)
Definition: Action.cpp:105
const char * _name
Definition: Action.h:63
bool _acceptsNonParameter
Definition: Action.h:66
const Parameter & getParam(const string &name) const
Definition: Action.cpp:101
virtual ~Action()
Definition: Action.cpp:59
const char * getShortDescription() const
Definition: Action.cpp:117
const_iterator end() const
Definition: CliParams.h:36
bool hasParam(const string &name) const
Definition: CliParams.cpp:105
const_iterator begin() const
Definition: CliParams.h:35
void parseCommandLine(unsigned int tokenCount, const char **tokens)
Definition: CliParams.cpp:50
const Parameter & getParam(const string &name) const
Definition: CliParams.cpp:112
void add(auto_ptr< Parameter > param)
Definition: CliParams.cpp:88
A NameFactory takes a name and then creates an instance of a class that has been previously registere...
Definition: NameFactory.h:33
void reportInternalError(const string &errorMsg)
Definition: error.cpp:29