StateObsAct.cpp
Go to the documentation of this file.
00001 // written by png shao wei
00002 
00003 #include "StateObsAct.h"
00004 #include <string>
00005 #include <cassert>
00006 using namespace std;
00007 
00008 const vector<string>& StateObsAct::getValueEnum() const {
00009     return valueEnum;
00010 }
00011 
00012 void StateObsAct::setValueEnum(const vector<string>& ve) {
00013     valueEnum = ve;
00014     positionLookup.clear();
00015     return;
00016 }
00017 
00018 void StateObsAct::preparePositionLookup() {
00019     if (positionLookup.empty()) {
00020         for (int i=0; i<valueEnum.size(); i++) {
00021             positionLookup[valueEnum[i]] = i;
00022         }
00023     }
00024     return;
00025 }
00026 
00027 int StateObsAct::getPosition(const string& name) {
00028     preparePositionLookup();
00029     assert(containsInstance(name));
00030     return positionLookup[name];
00031 }
00032 
00033 void StateObsAct::print() {
00034     for (unsigned int i = 0; i < valueEnum.size(); i++) {
00035         cout << "i: " << i << " " << valueEnum[i] << endl;
00036     }
00037     cout << endl;
00038 }
00039 
00040 const bool StateObsAct::containsInstance(const string& instanceName) {
00041     preparePositionLookup();
00042     return positionLookup.find(instanceName) != positionLookup.end();
00043 }


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29