libFAUDES

Sections

Index

diag_attrfailuretypes.cpp

Go to the documentation of this file.
00001 /** @file diag_attrfailuretypes.cpp
00002 Failure and indicator partition for a system (used as global attribute).
00003 */
00004 
00005 #include "diag_attrfailuretypes.h"
00006 
00007 using namespace std;
00008 
00009 namespace faudes {
00010 
00011 // faudes type std
00012 FAUDES_TYPE_IMPLEMENTATION(Void,AttributeFailureTypeMap,AttributeFlags)
00013 
00014 // copy my members
00015 void AttributeFailureTypeMap::DoAssign(const AttributeFailureTypeMap& rSrcAttr) {
00016   AttributeFlags::DoAssign(rSrcAttr); 
00017   mFailureTypeMap = rSrcAttr.mFailureTypeMap; 
00018 }
00019 
00020 // Equality
00021 bool AttributeFailureTypeMap::DoEqual(const AttributeFailureTypeMap& rAttr) const {
00022   // test base
00023   if(!AttributeFlags::DoEqual(rAttr)) return false;
00024   // my members
00025   if(mFailureTypeMap!=rAttr.mFailureTypeMap) return false; 
00026   // pass
00027   return true; 
00028 } 
00029 
00030 
00031 // IsDefault()
00032 bool AttributeFailureTypeMap::IsDefault(void) const{
00033   return mFailureTypeMap.Empty();
00034 }
00035 
00036 // Empty()
00037 bool AttributeFailureTypeMap::Empty(void) const {
00038   return mFailureTypeMap.Empty();
00039 }
00040 
00041 // Clear()
00042 void AttributeFailureTypeMap::Clear(void) {
00043   mFailureTypeMap.Clear();
00044 }
00045 
00046 // AddFailureTypeMapping()
00047 Idx AttributeFailureTypeMap::AddFailureTypeMapping(const std::string& failureType, const EventSet& rfailureEvents) {
00048   Idx failureLabelIndex;
00049   SymbolTable* mpLabelSymbolTable = DiagLabelSet::StaticLabelSymbolTablep();
00050   
00051   // Insert failureType in msLabelSymbolTable of DiagLabelSet.
00052   // If failure type name does already exist in LabelSymbolTable, InsEntry returns index of existing entry.
00053   try {
00054     failureLabelIndex = mpLabelSymbolTable->InsEntry(failureType);
00055   }
00056   catch (faudes::Exception& exception) {
00057     stringstream errstr;
00058     errstr << "Have not been able to add failure with Index " << failureType << " to LabelSymbolTable" << endl;
00059     throw Exception("AttributeFailureTypeMap::AddFailureTypeMapping()", errstr.str(), 300);
00060   }
00061   // store failure event set in AttributeFailureEvents
00062   AttributeFailureEvents fEvents;
00063   fEvents.mFailureEvents.InsertSet(rfailureEvents);
00064       
00065   // write new map entry
00066   mFailureTypeMap.Insert(failureLabelIndex,fEvents);
00067   
00068   return failureLabelIndex;  
00069 }
00070 
00071 // AddFailureTypeMap()
00072 void AttributeFailureTypeMap::AddFailureTypeMap(const std::map<std::string,EventSet>& rFailureMap) {
00073   map<string,EventSet>::const_iterator it;
00074   
00075   for(it = rFailureMap.begin(); it != rFailureMap.end(); it++) {
00076     AddFailureTypeMapping(it->first,it->second);
00077   }
00078 }
00079 
00080 // FailureType()
00081 // not used
00082 Idx AttributeFailureTypeMap::FailureType(Idx failureEvent) const {
00083   TaNameSet<AttributeFailureEvents>::Iterator it;  
00084 
00085   for(it = mFailureTypeMap.Begin(); it != mFailureTypeMap.End(); it++) {
00086     if (mFailureTypeMap.Attribute(*it).mFailureEvents.Exists(failureEvent)) {
00087       return *it;
00088     }
00089   }
00090   return 0;
00091 }
00092 
00093 // AllFailureEvents()
00094 EventSet AttributeFailureTypeMap::AllFailureEvents(void) const {
00095   EventSet failures;
00096   AttributeFailureEvents failureAttr;
00097   TaNameSet<AttributeFailureEvents>::Iterator it;  
00098   
00099   failures.Clear();
00100   for(it = mFailureTypeMap.Begin(); it != mFailureTypeMap.End(); it++) {
00101     failureAttr = mFailureTypeMap.Attribute(*it);
00102     failures.InsertSet(failureAttr.mFailureEvents);
00103   }  
00104   return failures;
00105 }
00106 
00107 // DoWrite()
00108 void AttributeFailureTypeMap::DoWrite(TokenWriter& rTw, const std::string& rLabel, const Type* pContext) const {
00109   if(IsDefault()) return;
00110   mFailureTypeMap.Write(rTw,"FailureTypes", pContext);
00111 }
00112 
00113 // DoRead()
00114 void AttributeFailureTypeMap::DoRead(TokenReader &rTr, const std::string &rLabel, const Type *pContext) {
00115   mFailureTypeMap.Clear();
00116   Token token;
00117   rTr.Peek(token);
00118   if(token.Type()!=Token::Begin) return;
00119   if(token.StringValue()!="FailureTypes") return;
00120   mFailureTypeMap.Read(rTr, "FailureTypes", pContext);
00121 }
00122 
00123 
00124 } // namespace faudes
00125 

libFAUDES 2.18b --- 2010-12-17 --- c++ source docu by doxygen 1.6.3