About
User Reference
C++ API
luafaudes
Developer
Links
libFAUDES online
libFAUDES

Sections

Index

diag_attrdiagstate.cpp

Go 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 // copy my members
00015 void AttributeDiagnoserState::DoAssign(const AttributeDiagnoserState& rSrcAttr) {
00016   AttributeFlags::DoAssign(rSrcAttr); 
00017   mDiagnoserStateMap=rSrcAttr.mDiagnoserStateMap;
00018 }
00019 
00020 // IsDefault()
00021 bool AttributeDiagnoserState::IsDefault(void) const {
00022   return mDiagnoserStateMap.Empty();
00023 }
00024 
00025 // Clear()
00026 void AttributeDiagnoserState::Clear(void) {
00027   mDiagnoserStateMap.Clear();
00028 }
00029 
00030 // DiagnoserStateMap()
00031 const TaIndexSet<DiagLabelSet>& AttributeDiagnoserState::DiagnoserStateMap(void) const {
00032   return mDiagnoserStateMap;
00033 }
00034 
00035 // DiagnoserStateMapp()
00036 const TaIndexSet<DiagLabelSet>* AttributeDiagnoserState::DiagnoserStateMapp(void) const {
00037   return &mDiagnoserStateMap;
00038 }
00039 
00040 // DiagnoserStateMap()
00041 void AttributeDiagnoserState::DiagnoserStateMap(const TaIndexSet<DiagLabelSet>& newDiagStateMap) {
00042   mDiagnoserStateMap = newDiagStateMap;
00043 }
00044 
00045 // AddStateLabelMapping()
00046 void AttributeDiagnoserState::AddStateLabelMapping(Idx gstate, Idx label) {
00047   DiagLabelSet hset;
00048   
00049   // if gstate is already mapped from, the corresponding DiagLabelSet is loaded
00050   if(mDiagnoserStateMap.Exists(gstate)) {
00051     hset = mDiagnoserStateMap.Attribute(gstate);
00052   }
00053   // and the new mapping is added
00054   hset.mDiagLabels.Insert(label);
00055   mDiagnoserStateMap.Insert(gstate,hset);
00056 }
00057 
00058 // AddStateLabelMap()
00059 void AttributeDiagnoserState::AddStateLabelMap(Idx gstate, const DiagLabelSet& labels) {
00060   NameSet::Iterator it;
00061   DiagLabelSet hset;
00062   
00063   // if gstate is already mapped from, the corresponding DiagLabelSet is loaded
00064   if(mDiagnoserStateMap.Exists(gstate)) {
00065     hset = mDiagnoserStateMap.Attribute(gstate);
00066   }
00067   // add labels
00068   for(it = labels.mDiagLabels.Begin(); it != labels.mDiagLabels.End(); it++) {
00069     hset.mDiagLabels.Insert(*it);
00070   }
00071   // set
00072   mDiagnoserStateMap.Insert(gstate,hset);
00073 }
00074 
00075 // Str()
00076 string AttributeDiagnoserState::Str(void) const {
00077   TaIndexSet<DiagLabelSet>::Iterator it;
00078   string str;
00079   DiagLabelSet label;
00080   
00081   for (it = mDiagnoserStateMap.Begin(); it != mDiagnoserStateMap.End(); it++) {
00082     label = mDiagnoserStateMap.Attribute(*it);
00083     if (it != mDiagnoserStateMap.Begin()) {
00084       str += " ";
00085     }
00086     str += ToStringInteger(*it);
00087     str += label.Str();
00088   }
00089   return str;
00090 }
00091 
00092 // ExistsState()
00093 // not used
00094 bool AttributeDiagnoserState::ExistsState(Idx state) const {
00095   return mDiagnoserStateMap.Exists(state);
00096 }
00097 
00098 // DoWrite()
00099 void AttributeDiagnoserState::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
00100   if(IsDefault()) return;
00101   mDiagnoserStateMap.Write(rTw,"StateEstimates", pContext);
00102 }
00103 
00104 //DoRead()
00105 void AttributeDiagnoserState::DoRead(TokenReader &rTr, const std::string &rLabel, const Type *pContext) {
00106   mDiagnoserStateMap.Clear();
00107   Token token;
00108   rTr.Peek(token);
00109   if(token.Type()!=Token::Begin) return;
00110   if(token.StringValue()!="StateEstimates") return;
00111   mDiagnoserStateMap.Read(rTr,"StateEstimates",pContext);
00112 }
00113 
00114 // Equality
00115 bool AttributeDiagnoserState::DoEqual(const AttributeDiagnoserState& rOtherAttribute) const {
00116   // equal set
00117   if(mDiagnoserStateMap != rOtherAttribute.mDiagnoserStateMap) return false;
00118   // equal attributes
00119   if(!mDiagnoserStateMap.EqualAttributes(rOtherAttribute.mDiagnoserStateMap)) return false;
00120   // pass
00121   return true;
00122 }
00123 
00124 
00125 } // namespace faudes
00126 

libFAUDES 2.20d --- 2011.04.26 --- c++ source docu by doxygen