Frobby 0.10.0
Loading...
Searching...
No Matches
VarNames.h
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 <vector>
21#include <string>
22#include <unordered_map>
23class Scanner;
24
38class VarNames {
39public:
40 VarNames();
41 VarNames(size_t varCount);
42 VarNames(const VarNames& names);
43 ~VarNames();
44
48 bool addVar(const string& name);
49
55 void addVarSyntaxCheckUnique(const Scanner& in, const string& name);
56
58 bool operator<(const VarNames& names) const;
59
61 size_t getIndex(const string& name) const;
62
64 bool contains(const string& name) const;
65
67 bool namesAreDefault() const;
68
72 const string& getName(size_t index) const;
73
75 size_t getVarCount() const;
76
78 void clear();
79
81 bool empty() const;
82
83 VarNames& operator=(const VarNames& names);
84 bool operator==(const VarNames& names) const;
85 bool operator!=(const VarNames& names) const;
86
88 void swapVariables(size_t a, size_t b);
89
90 void projectVar(size_t index);
91
92 void toString(string& str) const;
93 void print(FILE* file) const; // For debug
94
95 void swap(VarNames& names);
96
98 static const size_t invalidIndex = static_cast<size_t>(-1);
99
100private:
101 static bool compareNames(const string* a, const string* b);
102
103 typedef unordered_map<string, size_t> VarNameMap;
104 VarNameMap _nameToIndex;
105 vector<const string*> _indexToName;
106};
107
108
109
110inline size_t VarNames::getVarCount() const {
111 return _indexToName.size();
112}
113
114#endif
Definition Scanner.h:50
bool addVar(const string &name)
Definition VarNames.cpp:44
size_t getVarCount() const
Definition VarNames.h:110
const string & getName(size_t index) const
Definition VarNames.cpp:100
void swapVariables(size_t a, size_t b)
Definition VarNames.cpp:143
bool namesAreDefault() const
Definition VarNames.cpp:95
static const size_t invalidIndex
Definition VarNames.h:98
void clear()
Definition VarNames.cpp:106
bool operator<(const VarNames &names) const
Definition VarNames.cpp:75
size_t getIndex(const string &name) const
Definition VarNames.cpp:83
void addVarSyntaxCheckUnique(const Scanner &in, const string &name)
Definition VarNames.cpp:68
bool empty() const
Definition VarNames.cpp:111
bool contains(const string &name) const
Definition VarNames.cpp:91