Frobby 0.9.5
VarNames.h
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#ifndef VAR_NAMES_GUARD
18#define VAR_NAMES_GUARD
19
20#include "HashMap.h"
21
22#include <vector>
23#include <string>
24#include <unordered_map>
25class Scanner;
26
40class VarNames {
41public:
42 VarNames();
43 VarNames(size_t varCount);
44 VarNames(const VarNames& names);
45 ~VarNames();
46
50 bool addVar(const string& name);
51
57 void addVarSyntaxCheckUnique(const Scanner& in, const string& name);
58
60 bool operator<(const VarNames& names) const;
61
63 size_t getIndex(const string& name) const;
64
66 bool contains(const string& name) const;
67
69 bool namesAreDefault() const;
70
74 const string& getName(size_t index) const;
75
77 size_t getVarCount() const;
78
80 void clear();
81
83 bool empty() const;
84
85 VarNames& operator=(const VarNames& names);
86 bool operator==(const VarNames& names) const;
87 bool operator!=(const VarNames& names) const;
88
90 void swapVariables(size_t a, size_t b);
91
92 void projectVar(size_t index);
93
94 void toString(string& str) const;
95 void print(FILE* file) const; // For debug
96
97 void swap(VarNames& names);
98
100 static const size_t invalidIndex = static_cast<size_t>(-1);
101
102private:
103 static bool compareNames(const string* a, const string* b);
104
105 typedef unordered_map<string, size_t> VarNameMap;
106 //typedef HashMap<string, size_t> VarNameMap;
108 vector<const string*> _indexToName;
109};
110
111
112
113inline size_t VarNames::getVarCount() const {
114 return _indexToName.size();
115}
116
117#endif
The purpose of this file is to provide a definition of a hash map whenever possible.
This class offers an input interface which is more convenient and for some purposes more efficient th...
Definition: Scanner.h:50
Defines the variables of a polynomial ring and facilities IO involving them.
Definition: VarNames.h:40
bool addVar(const string &name)
Adds the variable and returns true if name is not already a variable.
Definition: VarNames.cpp:44
size_t getVarCount() const
Returns the current number of variables.
Definition: VarNames.h:113
const string & getName(size_t index) const
The returned reference can become invalid next time addVar is called.
Definition: VarNames.cpp:100
~VarNames()
Definition: VarNames.cpp:40
static bool compareNames(const string *a, const string *b)
Definition: VarNames.cpp:195
VarNames()
Definition: VarNames.cpp:25
void swap(VarNames &names)
Definition: VarNames.cpp:190
VarNameMap _nameToIndex
Definition: VarNames.h:107
void projectVar(size_t index)
Definition: VarNames.cpp:161
bool operator!=(const VarNames &names) const
Definition: VarNames.cpp:139
void swapVariables(size_t a, size_t b)
Swaps the variables with indexes a and b.
Definition: VarNames.cpp:143
bool namesAreDefault() const
Returns true if the names are x1, x2 and so on.
Definition: VarNames.cpp:95
static const size_t invalidIndex
Returns a fixed variable offset that is always invalid.
Definition: VarNames.h:100
void clear()
Resets the number of variables to zero.
Definition: VarNames.cpp:106
void print(FILE *file) const
Definition: VarNames.cpp:180
vector< const string * > _indexToName
Definition: VarNames.h:108
bool operator<(const VarNames &names) const
This also depends on the order of the names.
Definition: VarNames.cpp:75
unordered_map< string, size_t > VarNameMap
Definition: VarNames.h:105
size_t getIndex(const string &name) const
Returns VarNames::invalidIndex() if name is not known.
Definition: VarNames.cpp:83
VarNames & operator=(const VarNames &names)
Definition: VarNames.cpp:115
void toString(string &str) const
Definition: VarNames.cpp:171
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
bool empty() const
Returns true if the number of variables is zero.
Definition: VarNames.cpp:111
bool operator==(const VarNames &names) const
Definition: VarNames.cpp:128
bool contains(const string &name) const
Returns true if name is the name of a variable.
Definition: VarNames.cpp:91