-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathVariableCollection.h
More file actions
65 lines (49 loc) · 1.87 KB
/
Copy pathVariableCollection.h
File metadata and controls
65 lines (49 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
#include <map>
#include <vector>
#include "Variable.h"
/* Class represents a collections of variables
Allows us to error-check basic operations */
class VariableCollection {
std::map<std::string, Variable> variables;
// Holds pointers to the vars in variables
// In order added
std::vector<Variable*> variable_added_list;
// in order of "access"
// That is, be the parameter to the function "access"
std::vector<Variable*> variable_access_list;
public:
VariableCollection(){};
// Returns true if a variable with that name exists
bool has(const std::string&) const;
// Checks to see if variable with that name exists
// If it does, return that variable, else throw FetlangException
Variable& get(const std::string&);
// Same as "get," but adds to the access list
Variable& access(const std::string&);
// Return last variable added, error if no variables added
Variable& getLastAdded();
// Return last variable accessed, error if no variables accessed
Variable& getLastAccessed();
// Dealing with pronouns and gender
// Retrieves the last variable that is of that gender, or of an unassigned gender
Variable& getLastOfGender(Gender, bool excluding_last = false);
// Like the previous method, but does not count the last added variable
Variable& getLastOfGenderExcludingLast(Gender);
// Checks if the previous two methods can occur without exception
bool hasLastOfGender(Gender, bool excluding_last = false);
// Like the previous method, but does not count the last added variable
bool hasLastOfGenderExcludingLast(Gender);
inline bool empty() { return variables.empty(); }
inline std::vector<Variable> getAll() const {
std::vector<Variable> output;
for (const auto& varpair : variables) {
output.push_back(varpair.second);
}
return output;
}
// Just add a variable
void add(const Variable&);
// Display as a list
void display();
};