diag_attrfailuretypes.cpp
Go to the documentation of this file.
1 /** @file diag_attrfailuretypes.cpp
2 Failure and indicator partition for a system (used as global attribute).
3 */
4 
6 
7 using namespace std;
8 
9 namespace faudes {
10 
11 // faudes type std
12 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeFailureTypeMap,AttributeFlags)
13 
14 // construct
16  // configure unregistered type
17  // note: its just my member which is not registered, the attribute is registered
18  mFailureTypeMap.TypeName("FailureTypes");
19  mFailureTypeMap.XElementTag("FailureType");
20  mFailureTypeMap.Name("FailureTypes");
21  // always use static symbol table
22  mFailureTypeMap.SymbolTablep(DiagLabelSet::StaticLabelSymbolTablep());
23 }
24 
25 // comnstruct from file
26 AttributeFailureTypeMap::AttributeFailureTypeMap(const std::string& rFilename) : AttributeFlags() {
27  // configure unregistered type
28  // note: its just my member which is not registered, the attribute is registered
29  mFailureTypeMap.TypeName("FailureTypes");
30  mFailureTypeMap.XElementTag("FailureType");
31  mFailureTypeMap.Name("FailureTypes");
32  // always use static symbol table
34  // read
35  Read(rFilename);
36 }
37 
38 // copycontruct
40  // configure unregistered type
41  // note: its just my member which is not registered, the attribute is registered
42  mFailureTypeMap.TypeName("FailureTypes");
43  mFailureTypeMap.XElementTag("FailureType");
44  mFailureTypeMap.Name("FailureTypes");
45  // always use static symbol table
47  // copy
48  DoAssign(rOtherAttr);
49 }
50 
51 
52 // copy my members
54  AttributeFlags::DoAssign(rSrcAttr);
55  mFailureTypeMap = rSrcAttr.mFailureTypeMap;
56 }
57 
58 // Equality
60  // test base
61  if(!AttributeFlags::DoEqual(rAttr)) return false;
62  // my members
63  if(mFailureTypeMap!=rAttr.mFailureTypeMap) return false;
64  // pass
65  return true;
66 }
67 
68 
69 // IsDefault()
71  return mFailureTypeMap.Empty();
72 }
73 
74 // Empty()
76  return mFailureTypeMap.Empty();
77 }
78 
79 // Clear()
81  mFailureTypeMap.Clear();
82 }
83 
84 // AddFailureTypeMapping()
85 Idx AttributeFailureTypeMap::AddFailureTypeMapping(const std::string& failureType, const EventSet& rfailureEvents) {
86  Idx failureLabelIndex;
87  SymbolTable* mpLabelSymbolTable = DiagLabelSet::StaticLabelSymbolTablep();
88 
89  // Insert failureType in msLabelSymbolTable of DiagLabelSet.
90  // If failure type name does already exist in LabelSymbolTable, InsEntry returns index of existing entry.
91  try {
92  failureLabelIndex = mpLabelSymbolTable->InsEntry(failureType);
93  }
94  catch (faudes::Exception& exception) {
95  stringstream errstr;
96  errstr << "Have not been able to add failure with Index " << failureType << " to LabelSymbolTable" << endl;
97  throw Exception("AttributeFailureTypeMap::AddFailureTypeMapping()", errstr.str(), 300);
98  }
99  // store failure event set in AttributeFailureEvents
100  AttributeFailureEvents fEvents;
101  fEvents.mFailureEvents.InsertSet(rfailureEvents);
102 
103  // write new map entry
104  mFailureTypeMap.Insert(failureLabelIndex,fEvents);
105 
106  return failureLabelIndex;
107 }
108 
109 // AddFailureTypeMap()
110 void AttributeFailureTypeMap::AddFailureTypeMap(const std::map<std::string,EventSet>& rFailureMap) {
111  map<string,EventSet>::const_iterator it;
112 
113  for(it = rFailureMap.begin(); it != rFailureMap.end(); it++) {
114  AddFailureTypeMapping(it->first,it->second);
115  }
116 }
117 
118 // FailureType()
119 // not used
122 
123  for(it = mFailureTypeMap.Begin(); it != mFailureTypeMap.End(); it++) {
124  if (mFailureTypeMap.Attribute(*it).mFailureEvents.Exists(failureEvent)) {
125  return *it;
126  }
127  }
128  return 0;
129 }
130 
131 // AllFailureEvents()
133  EventSet failures;
134  AttributeFailureEvents failureAttr;
136 
137  failures.Clear();
138  for(it = mFailureTypeMap.Begin(); it != mFailureTypeMap.End(); it++) {
139  failureAttr = mFailureTypeMap.Attribute(*it);
140  failures.InsertSet(failureAttr.mFailureEvents);
141  }
142  return failures;
143 }
144 
145 // DoWrite()
146 void AttributeFailureTypeMap::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
147  if(IsDefault()) return;
148  mFailureTypeMap.Write(rTw,"FailureTypes", pContext);
149 }
150 
151 // DoXWrite()
152 void AttributeFailureTypeMap::DoXWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
153  if(IsDefault()) return;
154  mFailureTypeMap.XWrite(rTw,"FailureTypes", pContext);
155 }
156 
157 // DoRead()
158 void AttributeFailureTypeMap::DoRead(TokenReader &rTr, const std::string &rLabel, const Type *pContext) {
159  mFailureTypeMap.Clear();
160  Token token;
161  rTr.Peek(token);
162  if(!token.IsBegin("FailureTypes")) return;
163  mFailureTypeMap.Read(rTr, "FailureTypes", pContext);
164 }
165 
166 
167 } // namespace faudes
168 
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
faudes type implementation macros, overall
Definition: cfl_types.h:946
Stores the failure and indicator events for a particular failure type.
EventSet mFailureEvents
Set of failure events.
Partitions the failure and indicator events.
AttributeFailureTypeMap(void)
Default constructor.
EventSet AllFailureEvents(void) const
Obtain all failure events in mFailureTypeMap.
TaNameSet< AttributeFailureEvents > mFailureTypeMap
Failure and indicator event partition.
bool DoEqual(const AttributeFailureTypeMap &rAttr) const
Test equality.
void AddFailureTypeMap(const std::map< std::string, EventSet > &rFailureMap)
Inserts entire failure type map to mFailureTypeMap.
void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=0)
Read mFailureTypeMap from TokenReader.
Idx AddFailureTypeMapping(const std::string &failureType, const EventSet &rfailureEvents)
Add a set of failure events to failure type map.
bool Empty(void) const
Test if mFailureTypeMap is empty.
void Clear(void)
Clears mFailureTypeMap.
void DoAssign(const AttributeFailureTypeMap &rSrcAttr)
Copy attribute members.
Idx FailureType(Idx failureEvent) const
Returns failure type of failure event.
bool IsDefault(void) const
Test for default value.
void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write mFailureTypeMap to TokenWriter.
void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=0) const
Write mFailureTypeMap to TokenWriter.
Boolean flags Attribute.
bool DoEqual(const AttributeFlags &rOther) const
Test equality of configuration data.
void DoAssign(const AttributeFlags &rSrcAttr)
Assignment method.
static SymbolTable * StaticLabelSymbolTablep(void)
Get pointer to static LabelSymbolTable.
Faudes exception class.
Set of indices with symbolic names.
Definition: cfl_nameset.h:69
virtual void InsertSet(const NameSet &rOtherSet)
Inserts all elements of rOtherSet.
A SymbolTable associates sybolic names with indices.
Idx InsEntry(Idx index, const std::string &rName)
Add new entry (aka symbolic name and index) to symboltable,.
Set of indices with symbolic names and attributes.
Definition: cfl_nameset.h:564
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
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
Read configuration data from file with label specified.
Definition: cfl_types.cpp:261
virtual const std::string & TypeName(void) const
Get objects's type name.
Definition: cfl_types.cpp:132
Contains the failure and indicator partition for a system (used as global attribute).
virtual void Clear(void)
Clear all set.
Definition: cfl_baseset.h:1902
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)

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