diag_attrdiagstate.cppGo to the documentation of this file.00001 /** @file diag_attrdiagstate.cpp 00002 Implements state estimates for the current status of the generator (as state attributes). 00003 */ 00004 00005 #include "diag_attrdiagstate.h" 00006 00007 using namespace std; 00008 00009 namespace faudes { 00010 00011 // faudes type std 00012 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeDiagnoserState,AttributeFlags) 00013 00014 // consruct 00015 AttributeDiagnoserState::AttributeDiagnoserState(void) { 00016 // our map type is not in the registry, so we need to configure manually 00017 mDiagnoserStateMap.XElementTag("TargetState"); 00018 mDiagnoserStateMap.Name("TargetStateEstimates"); 00019 mDiagnoserStateMap.TypeName("TargetStateEstimates"); 00020 } 00021 00022 // destruct 00023 AttributeDiagnoserState::~AttributeDiagnoserState(void) {} 00024 00025 00026 // copy my members 00027 void AttributeDiagnoserState::DoAssign(const AttributeDiagnoserState& rSrcAttr) { 00028 AttributeFlags::DoAssign(rSrcAttr); 00029 mDiagnoserStateMap=rSrcAttr.mDiagnoserStateMap; 00030 } 00031 00032 // IsDefault() 00033 bool AttributeDiagnoserState::IsDefault(void) const { 00034 return mDiagnoserStateMap.Empty(); 00035 } 00036 00037 // Clear() 00038 void AttributeDiagnoserState::Clear(void) { 00039 mDiagnoserStateMap.Clear(); 00040 } 00041 00042 // DiagnoserStateMap() 00043 const TaIndexSet<DiagLabelSet>& AttributeDiagnoserState::DiagnoserStateMap(void) const { 00044 return mDiagnoserStateMap; 00045 } 00046 00047 // DiagnoserStateMapp() 00048 const TaIndexSet<DiagLabelSet>* AttributeDiagnoserState::DiagnoserStateMapp(void) const { 00049 return &mDiagnoserStateMap; 00050 } 00051 00052 // DiagnoserStateMap() 00053 void AttributeDiagnoserState::DiagnoserStateMap(const TaIndexSet<DiagLabelSet>& newDiagStateMap) { 00054 mDiagnoserStateMap = newDiagStateMap; 00055 } 00056 00057 // AddStateLabelMapping() 00058 void AttributeDiagnoserState::AddStateLabelMapping(Idx gstate, Idx label) { 00059 DiagLabelSet hset; 00060 00061 // if gstate is already mapped from, the corresponding DiagLabelSet is loaded 00062 if(mDiagnoserStateMap.Exists(gstate)) { 00063 hset = mDiagnoserStateMap.Attribute(gstate); 00064 } 00065 // and the new mapping is added 00066 hset.mDiagLabels.Insert(label); 00067 mDiagnoserStateMap.Insert(gstate,hset); 00068 } 00069 00070 // AddStateLabelMap() 00071 void AttributeDiagnoserState::AddStateLabelMap(Idx gstate, const DiagLabelSet& labels) { 00072 NameSet::Iterator it; 00073 DiagLabelSet hset; 00074 00075 // if gstate is already mapped from, the corresponding DiagLabelSet is loaded 00076 if(mDiagnoserStateMap.Exists(gstate)) { 00077 hset = mDiagnoserStateMap.Attribute(gstate); 00078 } 00079 // add labels 00080 for(it = labels.mDiagLabels.Begin(); it != labels.mDiagLabels.End(); it++) { 00081 hset.mDiagLabels.Insert(*it); 00082 } 00083 // set 00084 mDiagnoserStateMap.Insert(gstate,hset); 00085 } 00086 00087 // Str() 00088 string AttributeDiagnoserState::Str(void) const { 00089 TaIndexSet<DiagLabelSet>::Iterator it; 00090 string str; 00091 DiagLabelSet label; 00092 00093 for (it = mDiagnoserStateMap.Begin(); it != mDiagnoserStateMap.End(); it++) { 00094 label = mDiagnoserStateMap.Attribute(*it); 00095 if (it != mDiagnoserStateMap.Begin()) { 00096 str += " "; 00097 } 00098 str += ToStringInteger(*it); 00099 str += label.Str(); 00100 } 00101 return str; 00102 } 00103 00104 // ExistsState() 00105 // not used 00106 bool AttributeDiagnoserState::ExistsState(Idx state) const { 00107 return mDiagnoserStateMap.Exists(state); 00108 } 00109 00110 // DoWrite() 00111 void AttributeDiagnoserState::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const { 00112 if(IsDefault()) return; 00113 mDiagnoserStateMap.Write(rTw,"StateEstimates", pContext); 00114 } 00115 00116 // DoXWrite() 00117 void AttributeDiagnoserState::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const { 00118 if(IsDefault()) return; 00119 mDiagnoserStateMap.XWrite(rTw,"TargetStateEstimates", pContext); 00120 } 00121 00122 //DoRead() 00123 void AttributeDiagnoserState::DoRead(TokenReader &rTr, const std::string &rLabel, const Type *pContext) { 00124 mDiagnoserStateMap.Clear(); 00125 Token token; 00126 rTr.Peek(token); 00127 // native faudes 00128 if(token.IsBegin("StateEstimates")) 00129 mDiagnoserStateMap.Read(rTr,"",pContext); 00130 // XML format 00131 if(token.IsBegin("TargetStateEstimates")) 00132 mDiagnoserStateMap.Read(rTr,"",pContext); 00133 } 00134 00135 // Equality 00136 bool AttributeDiagnoserState::DoEqual(const AttributeDiagnoserState& rOtherAttribute) const { 00137 // equal set 00138 if(mDiagnoserStateMap != rOtherAttribute.mDiagnoserStateMap) return false; 00139 // equal attributes 00140 if(!mDiagnoserStateMap.EqualAttributes(rOtherAttribute.mDiagnoserStateMap)) return false; 00141 // pass 00142 return true; 00143 } 00144 00145 00146 } // namespace faudes 00147 libFAUDES 2.23h --- 2014.04.03 --- c++ api documentaion by doxygen |