Action.cpp
Go to the documentation of this file.
/* Frobby: Software for monomial ideal computations.
Copyright (C) 2007 Bjarke Hammersholt Roune (www.broune.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
*/
#include "stdinc.h"
#include "Action.h"
#include "error.h"
#include "NameFactory.h"
#include "IrreducibleDecomAction.h"
#include "TransformAction.h"
#include "HelpAction.h"
#include "DynamicFrobeniusAction.h"
#include "GenerateIdealAction.h"
#include "GenerateFrobeniusAction.h"
#include "FrobeniusAction.h"
#include "AnalyzeAction.h"
#include "LatticeFormatAction.h"
#include "IntersectionAction.h"
#include "AssociatedPrimesAction.h"
#include "AlexanderDualAction.h"
#include "HilbertAction.h"
#include "PolyTransformAction.h"
#include "HelpAction.h"
#include "TestAction.h"
#include "PrimaryDecomAction.h"
#include "OptimizeAction.h"
#include "MaximalStandardAction.h"
#include "LatticeAnalyzeAction.h"
#include "DimensionAction.h"
#include "EulerAction.h"
Action::Action(const char* name,
const char* shortDescription,
const char* description,
bool acceptsNonParameterParam):
_name(name),
_shortDescription(shortDescription),
_description(description),
_acceptsNonParameter(acceptsNonParameterParam),
_printActions("time", "Display and time each subcomputation.", false) {
_params.add(_printActions);
}
Action::~Action() {
}
namespace {
typedef NameFactory<Action> ActionFactory;
ActionFactory getActionFactory() {
ActionFactory factory("action");
nameFactoryRegister<HilbertAction>(factory);
nameFactoryRegister<EulerAction>(factory);
nameFactoryRegister<IrreducibleDecomAction>(factory);
nameFactoryRegister<PrimaryDecomAction>(factory);
nameFactoryRegister<AlexanderDualAction>(factory);
nameFactoryRegister<AssociatedPrimesAction>(factory);
nameFactoryRegister<MaximalStandardAction>(factory);
nameFactoryRegister<DimensionAction>(factory);
nameFactoryRegister<OptimizeAction>(factory);
nameFactoryRegister<TransformAction>(factory);
nameFactoryRegister<PolyTransformAction>(factory);
nameFactoryRegister<IntersectionAction>(factory);
nameFactoryRegister<GenerateIdealAction>(factory);
nameFactoryRegister<FrobeniusAction>(factory);
nameFactoryRegister<DynamicFrobeniusAction>(factory);
nameFactoryRegister<GenerateFrobeniusAction>(factory);
nameFactoryRegister<AnalyzeAction>(factory);
nameFactoryRegister<LatticeFormatAction>(factory);
nameFactoryRegister<LatticeAnalyzeAction>(factory);
nameFactoryRegister<HelpAction>(factory);
nameFactoryRegister<TestAction>(factory);
return factory;
}
}
bool Action::displayAction() const {
return true;
}
const Parameter& Action::getParam(const string& name) const {
return _params.getParam(name);
}
void Action::getActionNames(vector<string>& names) {
getActionFactory().getNamesWithPrefix("", names);
}
unique_ptr<Action> Action::createActionWithPrefix(const string& prefix) {
return createWithPrefix(getActionFactory(), prefix);
}
const char* Action::getName() const {
return _name;
}
const char* Action::getShortDescription() const {
return _shortDescription;
}
const char* Action::getDescription() const {
return _description;
}
bool Action::acceptsNonParameter() const {
return _acceptsNonParameter;
}
void Action::processNonParameter(const char*) {
reportInternalError("Action::processNonParameter called.");
}
void Action::obtainParameters(vector<Parameter*>& parameters) {
parameters.insert(parameters.end(), _params.begin(), _params.end());
}
void Action::parseCommandLine(unsigned int tokenCount, const char** tokens) {
vector<Parameter*> tmp;
obtainParameters(tmp);
for (size_t i = 0; i < tmp.size(); ++i)
if (!_params.hasParam(tmp[i]->getName()))
_params.add(*tmp[i]);
if (acceptsNonParameter() && tokenCount > 0 && tokens[0][0] != '-') {
processNonParameter(tokens[0]);
--tokenCount;
++tokens;
}
_params.parseCommandLine(tokenCount, tokens);
}
Action.h
AlexanderDualAction.h
AnalyzeAction.h
AssociatedPrimesAction.h
DimensionAction.h
DynamicFrobeniusAction.h
EulerAction.h
FrobeniusAction.h
GenerateFrobeniusAction.h
GenerateIdealAction.h
HelpAction.h
HilbertAction.h
IntersectionAction.h
IrreducibleDecomAction.h
LatticeAnalyzeAction.h
LatticeFormatAction.h
MaximalStandardAction.h
NameFactory.h
nameFactoryRegister
void nameFactoryRegister(NameFactory< AbstractProduct > &factory)
Registers the string returned by ConcreteProduct::getStaticName() to a function that default-construc...
Definition NameFactory.h:142
createWithPrefix
unique_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
OptimizeAction.h
PolyTransformAction.h
PrimaryDecomAction.h
TestAction.h
TransformAction.h
Action::getName
const char * getName() const
Definition Action.cpp:113
Action::_params
CliParams _params
Definition Action.h:59
Action::_printActions
BoolParameter _printActions
Definition Action.h:68
Action::Action
Action(const char *name, const char *shortDescription, const char *description, bool acceptsNonParameter)
Definition Action.cpp:46
Action::parseCommandLine
virtual void parseCommandLine(unsigned int tokenCount, const char **tokens)
Definition Action.cpp:137
Action::getDescription
const char * getDescription() const
Definition Action.cpp:121
Action::acceptsNonParameter
bool acceptsNonParameter() const
Definition Action.cpp:125
Action::processNonParameter
virtual void processNonParameter(const char *str)
Definition Action.cpp:129
Action::_shortDescription
const char * _shortDescription
Definition Action.h:64
Action::obtainParameters
virtual void obtainParameters(vector< Parameter * > &parameters)
Definition Action.cpp:133
Action::displayAction
virtual bool displayAction() const
Returns whether this action should be shown to the user by the help action.
Definition Action.cpp:97
Action::_description
const char * _description
Definition Action.h:65
Action::getActionNames
static void getActionNames(vector< string > &names)
Definition Action.cpp:105
Action::_name
const char * _name
Definition Action.h:63
Action::_acceptsNonParameter
bool _acceptsNonParameter
Definition Action.h:66
Action::getParam
const Parameter & getParam(const string &name) const
Definition Action.cpp:101
Action::~Action
virtual ~Action()
Definition Action.cpp:59
Action::createActionWithPrefix
static unique_ptr< Action > createActionWithPrefix(const string &prefix)
Definition Action.cpp:109
Action::getShortDescription
const char * getShortDescription() const
Definition Action.cpp:117
NameFactory
A NameFactory takes a name and then creates an instance of a class that has been previously registere...
Definition NameFactory.h:33
Parameter
Definition Parameter.h:24
reportInternalError
void reportInternalError(const string &errorMsg)
Definition error.cpp:29
error.h
stdinc.h
This header file includes common definitions and is included as the first line of code in every imple...