diag_attrdiagstate.cpp
Go to the documentation of this file.
1 /** @file diag_attrdiagstate.cpp
2 Implements state estimates for the current status of the generator (as state attributes).
3 */
4 
5 #include "diag_attrdiagstate.h"
6 
7 using namespace std;
8 
9 namespace faudes {
10 
11 // faudes type std
12 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeDiagnoserState,AttributeFlags)
13 
14 // consruct
16  // our map type is not in the registry, so we need to configure manually
17  mDiagnoserStateMap.XElementTag("TargetState");
18  mDiagnoserStateMap.Name("TargetStateEstimates");
19  mDiagnoserStateMap.TypeName("TargetStateEstimates");
20 }
21 
22 // destruct
23 AttributeDiagnoserState::~AttributeDiagnoserState(void) {}
24 
25 
26 // copy my members
27 void AttributeDiagnoserState::DoAssign(const AttributeDiagnoserState& rSrcAttr) {
28  AttributeFlags::DoAssign(rSrcAttr);
29  mDiagnoserStateMap=rSrcAttr.mDiagnoserStateMap;
30 }
31 
32 // IsDefault()
33 bool AttributeDiagnoserState::IsDefault(void) const {
34  return mDiagnoserStateMap.Empty();
35 }
36 
37 // Clear()
38 void AttributeDiagnoserState::Clear(void) {
39  mDiagnoserStateMap.Clear();
40 }
41 
42 // DiagnoserStateMap()
43 const TaIndexSet<DiagLabelSet>& AttributeDiagnoserState::DiagnoserStateMap(void) const {
44  return mDiagnoserStateMap;
45 }
46 
47 // DiagnoserStateMapp()
48 const TaIndexSet<DiagLabelSet>* AttributeDiagnoserState::DiagnoserStateMapp(void) const {
49  return &mDiagnoserStateMap;
50 }
51 
52 // DiagnoserStateMap()
53 void AttributeDiagnoserState::DiagnoserStateMap(const TaIndexSet<DiagLabelSet>& newDiagStateMap) {
54  mDiagnoserStateMap = newDiagStateMap;
55 }
56 
57 // AddStateLabelMapping()
58 void AttributeDiagnoserState::AddStateLabelMapping(Idx gstate, Idx label) {
59  DiagLabelSet hset;
60 
61  // if gstate is already mapped from, the corresponding DiagLabelSet is loaded
62  if(mDiagnoserStateMap.Exists(gstate)) {
63  hset = mDiagnoserStateMap.Attribute(gstate);
64  }
65  // and the new mapping is added
66  hset.mDiagLabels.Insert(label);
67  mDiagnoserStateMap.Insert(gstate,hset);
68 }
69 
70 // AddStateLabelMap()
71 void AttributeDiagnoserState::AddStateLabelMap(Idx gstate, const DiagLabelSet& labels) {
72  NameSet::Iterator it;
73  DiagLabelSet hset;
74 
75  // if gstate is already mapped from, the corresponding DiagLabelSet is loaded
76  if(mDiagnoserStateMap.Exists(gstate)) {
77  hset = mDiagnoserStateMap.Attribute(gstate);
78  }
79  // add labels
80  for(it = labels.mDiagLabels.Begin(); it != labels.mDiagLabels.End(); it++) {
81  hset.mDiagLabels.Insert(*it);
82  }
83  // set
84  mDiagnoserStateMap.Insert(gstate,hset);
85 }
86 
87 // Str()
88 string AttributeDiagnoserState::Str(void) const {
90  string str;
91  DiagLabelSet label;
92 
93  for (it = mDiagnoserStateMap.Begin(); it != mDiagnoserStateMap.End(); it++) {
94  label = mDiagnoserStateMap.Attribute(*it);
95  if (it != mDiagnoserStateMap.Begin()) {
96  str += " ";
97  }
98  str += ToStringInteger(*it);
99  str += label.Str();
100  }
101  return str;
102 }
103 
104 // ExistsState()
105 // not used
106 bool AttributeDiagnoserState::ExistsState(Idx state) const {
107  return mDiagnoserStateMap.Exists(state);
108 }
109 
110 // DoWrite()
111 void AttributeDiagnoserState::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
112  if(IsDefault()) return;
113  mDiagnoserStateMap.Write(rTw,"StateEstimates", pContext);
114 }
115 
116 // DoXWrite()
117 void AttributeDiagnoserState::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
118  if(IsDefault()) return;
119  mDiagnoserStateMap.XWrite(rTw,"TargetStateEstimates", pContext);
120 }
121 
122 //DoRead()
123 void AttributeDiagnoserState::DoRead(TokenReader &rTr, const std::string &rLabel, const Type *pContext) {
124  mDiagnoserStateMap.Clear();
125  Token token;
126  rTr.Peek(token);
127  // native faudes
128  if(token.IsBegin("StateEstimates"))
129  mDiagnoserStateMap.Read(rTr,"",pContext);
130  // XML format
131  if(token.IsBegin("TargetStateEstimates"))
132  mDiagnoserStateMap.Read(rTr,"",pContext);
133 }
134 
135 // Equality
136 bool AttributeDiagnoserState::DoEqual(const AttributeDiagnoserState& rOtherAttribute) const {
137  // equal set
138  if(mDiagnoserStateMap != rOtherAttribute.mDiagnoserStateMap) return false;
139  // equal attributes
140  if(!mDiagnoserStateMap.EqualAttributes(rOtherAttribute.mDiagnoserStateMap)) return false;
141  // pass
142  return true;
143 }
144 
145 
146 } // namespace faudes
147 
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
faudes type implementation macros, overall
Definition: cfl_types.h:946
Implements state estimates for the current status of the generator.
TaIndexSet< DiagLabelSet > mDiagnoserStateMap
The diagnoser state attribute is a map of state indices of the original generator to their failure la...
Implements the label representation for state estimates.
std::string Str(void) const
Prints mDiagLabels to a string.
NameSet mDiagLabels
Set of diagnoser label names.
bool Insert(const Idx &rIndex)
Add an element by index.
Set of indices with attributes.
Definition: cfl_indexset.h:316
A TokenReader reads sequential tokens from a file or string.
bool Peek(Token &token)
Peek next token.
A TokenWriter writes sequential tokens to a file, a string or stdout.
Tokens model atomic data for stream IO.
Definition: cfl_token.h:53
bool IsBegin(void) const
Test token Type.
Definition: cfl_token.cpp:258
Base class of all libFAUDES objects that participate in the run-time interface.
Definition: cfl_types.h:239
virtual void Name(const std::string &rName)
Set the objects's name.
Definition: cfl_types.cpp:117
State estimates for the current status of the generator (as state attributes).
Iterator End(void) const
Iterator to the end of set.
Definition: cfl_baseset.h:1896
Iterator Begin(void) const
Iterator to the begin of set.
Definition: cfl_baseset.h:1891
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
std::string ToStringInteger(Int number)
integer to string
Definition: cfl_helper.cpp:43

libFAUDES 2.32b --- 2024.03.01 --- c++ api documentaion by doxygen