Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00040 #include <CExporter.h>
00041
00042
00043 namespace beliefstate {
00044 CExporter::CExporter() {
00045 m_ckvpConfiguration = new CKeyValuePair();
00046 }
00047
00048 CExporter::~CExporter() {
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 if(m_ckvpConfiguration) {
00059 delete m_ckvpConfiguration;
00060 m_ckvpConfiguration = NULL;
00061 }
00062 }
00063
00064 void CExporter::addNode(Node* ndAdd) {
00065 m_lstNodes.push_back(ndAdd);
00066 }
00067
00068 void CExporter::setRootNodes(std::list<Node*> lstRootNodes) {
00069 m_lstRootNodes = lstRootNodes;
00070 }
00071
00072 void CExporter::addRootNode(Node* ndRoot) {
00073 m_lstRootNodes.push_back(ndRoot);
00074 }
00075
00076 std::list<Node*> CExporter::rootNodes() {
00077 return m_lstRootNodes;
00078 }
00079
00080 list<Node*> CExporter::nodes() {
00081 return m_lstNodes;
00082 }
00083
00084 void CExporter::clearNodes() {
00085 for(Node* ndDelete : m_lstNodes) {
00086 delete ndDelete;
00087 }
00088
00089 m_lstNodes.clear();
00090 }
00091
00092 CKeyValuePair* CExporter::configuration() {
00093 return m_ckvpConfiguration;
00094 }
00095
00096 std::string CExporter::nodeIDPrefix(Node* ndInQuestion, std::string strProposition) {
00097 std::string strPrefix = ndInQuestion->metaInformation()->stringValue("class");
00098
00099 if(strPrefix == "") {
00100 strPrefix = strProposition;
00101 } else {
00102 strPrefix += "_";
00103 }
00104
00105 return strPrefix;
00106 }
00107
00108 void CExporter::renewUniqueIDsForNode(Node *ndRenew) {
00109 std::string strNodeIDPrefix = this->nodeIDPrefix(ndRenew, "node_");
00110 ndRenew->setUniqueID(this->generateUniqueID(strNodeIDPrefix, 8));
00111
00112 std::list<Node*> lstSubnodes = ndRenew->subnodes();
00113 for(Node* ndNode : lstSubnodes) {
00114 this->renewUniqueIDsForNode(ndNode);
00115 }
00116 }
00117
00118 void CExporter::renewUniqueIDs() {
00119 for(Node* ndNode : m_lstNodes) {
00120 this->renewUniqueIDsForNode(ndNode);
00121 }
00122 }
00123
00124 bool CExporter::runExporter(CKeyValuePair* ckvpConfigurationOverlay) {
00125
00126
00127
00128
00129 return true;
00130 }
00131
00132 std::string CExporter::generateRandomIdentifier(std::string strPrefix, unsigned int unLength) {
00133 std::stringstream sts;
00134 sts << strPrefix;
00135
00136 for(unsigned int unI = 0; unI < unLength; unI++) {
00137 int nRandom;
00138
00139 do {
00140 nRandom = rand() % 122 + 48;
00141 } while(nRandom < 48 ||
00142 (nRandom > 57 && nRandom < 65) ||
00143 (nRandom > 90 && nRandom < 97) ||
00144 nRandom > 122);
00145
00146 char cRandom = (char)nRandom;
00147 sts << cRandom;
00148 }
00149
00150 return sts.str();
00151 }
00152
00153 std::string CExporter::generateUniqueID(std::string strPrefix, unsigned int unLength) {
00154 std::string strID;
00155
00156 do {
00157 strID = this->generateRandomIdentifier(strPrefix, unLength);
00158 } while(this->uniqueIDPresent(strID));
00159
00160 return strID;
00161 }
00162
00163 bool CExporter::uniqueIDPresent(std::string strUniqueID) {
00164 for(Node* ndNode : m_lstNodes) {
00165 if(ndNode->includesUniqueID(strUniqueID)) {
00166 return true;
00167 }
00168 }
00169
00170 return false;
00171 }
00172
00173 std::string CExporter::replaceString(std::string strOriginal, std::string strReplaceWhat, std::string strReplaceBy) {
00174 size_t found;
00175
00176 found = strOriginal.find(strReplaceWhat);
00177 while(found != string::npos) {
00178 strOriginal.replace(found, strReplaceWhat.length(), strReplaceBy);
00179 found = strOriginal.find(strReplaceWhat, found + strReplaceBy.length());
00180 };
00181
00182 return strOriginal;
00183 }
00184
00185 bool CExporter::nodeHasValidDetailLevel(Node* ndDisplay) {
00186 int nConfigMaxDetailLevel = this->configuration()->floatValue("max-detail-level");
00187 int nNodeDetailLevel = ndDisplay->metaInformation()->floatValue("detail-level");
00188
00189 return (nNodeDetailLevel <= nConfigMaxDetailLevel);
00190 }
00191
00192 bool CExporter::nodeDisplayable(Node* ndDisplay) {
00193 bool bDisplaySuccesses = (this->configuration()->floatValue("display-successes") == 1);
00194 bool bDisplayFailures = (this->configuration()->floatValue("display-failures") == 1);
00195 bool bNodeSuccess = (ndDisplay->metaInformation()->floatValue("success") == 1);
00196
00197 if(this->nodeHasValidDetailLevel(ndDisplay)) {
00198 if((bNodeSuccess && bDisplaySuccesses) || (!bNodeSuccess && bDisplayFailures)) {
00199 return true;
00200 }
00201 }
00202
00203 return false;
00204 }
00205
00206 void CExporter::setDesignatorIDs(std::list< std::pair<std::string, std::string> > lstDesignatorIDs) {
00207 m_lstDesignatorIDs = lstDesignatorIDs;
00208 }
00209
00210 void CExporter::setDesignatorEquations(std::list< std::pair<std::string, std::string> > lstDesignatorEquations) {
00211 m_lstDesignatorEquations = lstDesignatorEquations;
00212 }
00213
00214 void CExporter::setDesignatorEquationTimes(std::list< std::pair<std::string, std::string> > lstDesignatorEquationTimes) {
00215 m_lstDesignatorEquationTimes = lstDesignatorEquationTimes;
00216 }
00217
00218 std::list<std::string> CExporter::designatorIDs() {
00219 std::list<std::string> lstResult;
00220
00221 for(std::pair<std::string, std::string> prPair : m_lstDesignatorIDs) {
00222 lstResult.push_back(prPair.second);
00223 }
00224
00225 return lstResult;
00226 }
00227
00228 std::list<std::string> CExporter::parentDesignatorsForID(std::string strID) {
00229 std::list<std::string> lstResult;
00230
00231 for(std::pair<std::string, std::string> prPair : m_lstDesignatorEquations) {
00232 if(prPair.second == strID) {
00233 lstResult.push_back(prPair.first);
00234 }
00235 }
00236
00237 return lstResult;
00238 }
00239
00240 std::list<std::string> CExporter::successorDesignatorsForID(std::string strID) {
00241 std::list<std::string> lstResult;
00242
00243 for(std::pair<std::string, std::string> prPair : m_lstDesignatorEquations) {
00244 if(prPair.first == strID) {
00245 lstResult.push_back(prPair.second);
00246 }
00247 }
00248
00249 return lstResult;
00250 }
00251
00252 std::string CExporter::equationTimeForSuccessorID(std::string strID) {
00253 string strReturn = "";
00254
00255 for(std::pair<std::string, std::string> prPair : m_lstDesignatorEquationTimes) {
00256 if(prPair.first == strID) {
00257 strReturn = prPair.second;
00258 break;
00259 }
00260 }
00261
00262 return strReturn;
00263 }
00264 }