PRISMS-PF Manual v3.0-pre
Loading...
Searching...
No Matches
variableValueContainer.h
1// This class permits the access of a subset of indexed fields and gives an
2// error if any non-allowed fields are requested
3#ifndef VARIBLEVALUECONTAINER_H
4#define VARIBLEVALUECONTAINER_H
5
7{
8public:
10 : num_entries(0) {};
11
12 void
13 set(unsigned int global_variable_index, double variable_value)
14 {
15 var_index.push_back(global_variable_index);
16 value.push_back(variable_value);
17 num_entries++;
18 };
19
20 double
21 operator()(unsigned int global_variable_index)
22 {
23 for (unsigned int i = 0; i < num_entries; i++)
24 {
25 if (global_variable_index == var_index[i])
26 {
27 return value[i];
28 }
29 }
30
31 // If this point is reached, the index isn't allowed so an error should be
32 // thrown
33 std::cerr << "PRISMS-PF Error: Attempted access of a variable value that was not "
34 "marked as needed in 'parameters.in'. Double-check the indices in "
35 "user functions where a variable value is requested."
36 << std::endl;
37 abort();
38 };
39
40private:
41 std::vector<unsigned int> var_index;
42 std::vector<double> value;
43 unsigned int num_entries;
44};
45
46#endif
Definition variableValueContainer.h:7