VarNames.h
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/.
*/
#ifndef VAR_NAMES_GUARD
#define VAR_NAMES_GUARD
#include "HashMap.h"
#include <vector>
#include <string>
#include <unordered_map>
class Scanner;
class VarNames {
public:
VarNames();
VarNames(size_t varCount);
VarNames(const VarNames& names);
~VarNames();
bool addVar(const string& name);
void addVarSyntaxCheckUnique(const Scanner& in, const string& name);
bool operator<(const VarNames& names) const;
size_t getIndex(const string& name) const;
bool contains(const string& name) const;
bool namesAreDefault() const;
const string& getName(size_t index) const;
size_t getVarCount() const;
void clear();
bool empty() const;
VarNames& operator=(const VarNames& names);
bool operator==(const VarNames& names) const;
bool operator!=(const VarNames& names) const;
void swapVariables(size_t a, size_t b);
void projectVar(size_t index);
void toString(string& str) const;
void print(FILE* file) const; // For debug
void swap(VarNames& names);
static const size_t invalidIndex = static_cast<size_t>(-1);
private:
static bool compareNames(const string* a, const string* b);
typedef unordered_map<string, size_t> VarNameMap;
//typedef HashMap<string, size_t> VarNameMap;
VarNameMap _nameToIndex;
vector<const string*> _indexToName;
};
inline size_t VarNames::getVarCount() const {
return _indexToName.size();
}
#endif
HashMap.h
The purpose of this file is to provide a definition of a hash map whenever possible.
Scanner
This class offers an input interface which is more convenient and for some purposes more efficient th...
Definition Scanner.h:50
VarNames::addVar
bool addVar(const string &name)
Adds the variable and returns true if name is not already a variable.
Definition VarNames.cpp:44
VarNames::getVarCount
size_t getVarCount() const
Returns the current number of variables.
Definition VarNames.h:113
VarNames::getName
const string & getName(size_t index) const
The returned reference can become invalid next time addVar is called.
Definition VarNames.cpp:100
VarNames::~VarNames
~VarNames()
Definition VarNames.cpp:40
VarNames::compareNames
static bool compareNames(const string *a, const string *b)
Definition VarNames.cpp:195
VarNames::VarNames
VarNames()
Definition VarNames.cpp:25
VarNames::swap
void swap(VarNames &names)
Definition VarNames.cpp:190
VarNames::_nameToIndex
VarNameMap _nameToIndex
Definition VarNames.h:107
VarNames::projectVar
void projectVar(size_t index)
Definition VarNames.cpp:161
VarNames::operator!=
bool operator!=(const VarNames &names) const
Definition VarNames.cpp:139
VarNames::swapVariables
void swapVariables(size_t a, size_t b)
Swaps the variables with indexes a and b.
Definition VarNames.cpp:143
VarNames::namesAreDefault
bool namesAreDefault() const
Returns true if the names are x1, x2 and so on.
Definition VarNames.cpp:95
VarNames::invalidIndex
static const size_t invalidIndex
Returns a fixed variable offset that is always invalid.
Definition VarNames.h:100
VarNames::clear
void clear()
Resets the number of variables to zero.
Definition VarNames.cpp:106
VarNames::print
void print(FILE *file) const
Definition VarNames.cpp:180
VarNames::_indexToName
vector< const string * > _indexToName
Definition VarNames.h:108
VarNames::operator<
bool operator<(const VarNames &names) const
This also depends on the order of the names.
Definition VarNames.cpp:75
VarNames::VarNameMap
unordered_map< string, size_t > VarNameMap
Definition VarNames.h:105
VarNames::getIndex
size_t getIndex(const string &name) const
Returns VarNames::invalidIndex() if name is not known.
Definition VarNames.cpp:83
VarNames::operator=
VarNames & operator=(const VarNames &names)
Definition VarNames.cpp:115
VarNames::toString
void toString(string &str) const
Definition VarNames.cpp:171
VarNames::addVarSyntaxCheckUnique
void addVarSyntaxCheckUnique(const Scanner &in, const string &name)
As addvar, except it reports a syntax error if name is already a variable.
Definition VarNames.cpp:68
VarNames::empty
bool empty() const
Returns true if the number of variables is zero.
Definition VarNames.cpp:111
VarNames::operator==
bool operator==(const VarNames &names) const
Definition VarNames.cpp:128
VarNames::contains
bool contains(const string &name) const
Returns true if name is the name of a variable.
Definition VarNames.cpp:91