PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
VariableMap Class Reference

#include <VariableMap.h>

Public Member Functions

 VariableMap ()
 The Standard constructor.
 
 ~VariableMap ()
 The Standard destructor.

 
void AddVariable (const std::string &varname, const Variant &val)
 
Variant RetrieveValue (const std::string &varname)
 
bool Exists (const std::string &varname)
 
void Erase (const std::string &varname)
 
void DumpValues ()
 
void Destroy ()
 

Detailed Description

This is the primary structure for holding variables: the variable map It is an STL map that takes a string-based variable name and stores a variant. Every instance of an Evaluator has one private local VariableMap that cannot be accessed by other Evaluators, and there is on global VariableMap that is shared between Evaluators.

Definition at line 42 of file VariableMap.h.

Constructor & Destructor Documentation

◆ VariableMap()

VariableMap::VariableMap ( )

The Standard constructor.

Definition at line 46 of file VariableMap.cpp.

47{
48 //cout << "Creating variable map\n";
49 //Initiate anything necessary here.
50}

◆ ~VariableMap()

VariableMap::~VariableMap ( )

The Standard destructor.

Definition at line 53 of file VariableMap.cpp.

54{
55
56 //cout << "Deleting variablemap\n";
57 //cout << "contains " << mVariableMap.size() << " values\n";
58 //DumpValues();
59 //Delete mVariableMap if necessary.
60 //Erase things by hand, for debugging's sake
61 // std::map<std::string, Variant>::iterator i = mVariableMap.begin();
62
63 // while(i != mVariableMap.end())
64 // {
65 // i = mVariableMap.begin();
66 // mVariableMap.erase(i);
67 // }
68 mVariableMap.clear();
69
70}

Member Function Documentation

◆ AddVariable()

void VariableMap::AddVariable ( const std::string &  varname,
const Variant val 
)

This method will add a new variable with name varname and value val to the variable map, or (if it already exists) change its value to val.

Definition at line 84 of file VariableMap.cpp.

85{
86 string tmpVarName = PEBLUtility::ToUpper(varname);
87
88 map<string, Variant>::iterator p;
89
90 p = mVariableMap.find(tmpVarName);
91
92 //If the variable is in there already, change its value
93
94 if(p!=mVariableMap.end())
95 {
96
97 p->second = val;
98 }
99 else
100 {
101 //variable isn't there yet, so add the new value into map
102 mVariableMap.insert(pair<string, Variant>(tmpVarName, val));
103 }
104
105}
std::string ToUpper(const std::string &text)

References PEBLUtility::ToUpper().

Referenced by Evaluator::Evaluate(), Evaluator::Evaluate1(), extra(), PlatformWindow::Initialize(), PEventLoop::Loop(), PEventLoop::Loop1(), main(), main(), PEBLInterpret(), PlatformEventQueue::Prime(), and PlatformWindow::Resize().

◆ Destroy()

void VariableMap::Destroy ( )

Definition at line 73 of file VariableMap.cpp.

74{
75 mVariableMap.clear();
76}

Referenced by CaptureSignal(), and PEBLInterpret().

◆ DumpValues()

void VariableMap::DumpValues ( )

This method is primarily for debugging purposes. It will iterate through the entire variable map, and Display each of the values held in the map.

Definition at line 162 of file VariableMap.cpp.

163{
164 map<string,Variant>::iterator p;
165
166 for(p= mVariableMap.begin(); p!=mVariableMap.end(); p++)
167 {
168 cout << "VariableName: [" << p->first << ":"<< (p->first).length() << "] | Value: [" << p->second << "]\n";
169 }
170
171}

Referenced by extra(), and main().

◆ Erase()

void VariableMap::Erase ( const std::string &  varname)

This will erase the value stored in varname

Definition at line 150 of file VariableMap.cpp.

151{
152 string tmpVarname = PEBLUtility::ToUpper(varname);
153 mVariableMap.erase(tmpVarname);
154}

References PEBLUtility::ToUpper().

Referenced by extra().

◆ Exists()

bool VariableMap::Exists ( const std::string &  varname)

Definition at line 138 of file VariableMap.cpp.

139{
140 string tmpVarName = PEBLUtility::ToUpper(varname);
141 map<string,Variant>::iterator p = mVariableMap.find(tmpVarName);
142 if(p == mVariableMap.end())
143 return false;
144 else
145 return true;
146}

References PEBLUtility::ToUpper().

Referenced by PlatformWindow::Initialize(), and Evaluator::IsVariableName().

◆ RetrieveValue()

Variant VariableMap::RetrieveValue ( const std::string &  varname)

This method will retrieve the value designated by varname. If varname doesn't exist, it will return 0, along with a warning.

Definition at line 113 of file VariableMap.cpp.

114{
115
116 map<string,Variant>::iterator p;
117
118 //Get a the variable
119 string tmpVarName = PEBLUtility::ToUpper(varname);
120
121 p = mVariableMap.find(tmpVarName);
122
123 if(p == mVariableMap.end())
124 {
125 string message = "Trying to use an undefined variable: " + string(varname);
127 return Variant(0); //This really won't happen.
128 }
129 else
130 {
131 Variant vt = p->second;
132 return vt;
133 }
134}
void SignalFatalError(const std::string &message)

References PError::SignalFatalError(), and PEBLUtility::ToUpper().

Referenced by Evaluator::Evaluate(), Evaluator::Evaluate(), Evaluator::Evaluate1(), Evaluator::Evaluate1(), extra(), PlatformWindow::Initialize(), PEventLoop::Loop(), main(), PEBLObjects::MakeTextBox(), PEBLObjects::MakeWindow(), and PlatformWindow::Resize().


The documentation for this class was generated from the following files: