omg_rabinacc.cpp
Go to the documentation of this file.
1/** @file omg_rabinacc.cpp Rabin acceptance condition */
2
3
4/* FAU Discrete Event Systems Library (libfaudes)
5
6 Copyright (C) 2025 Thomas Moor
7 Exclusive copyright is granted to Klaus Schmidt
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23
24
25#include "omg_rabinacc.h"
26
27namespace faudes {
28
29// local debugging
30//#undef FD_DC
31//#define FD_DC(m) FD_WARN(m)
32
33/*
34********************************
35Autoregister
36********************************
37*/
38
43
44/*
45********************************
46implementation RabinPair
47********************************
48*/
49
50// faudes Type std
52
53// Construct
55 FD_DC("RabinPair(" << this << ")::RabinPair()");
56 Name("RabinPair");
57 mRSet.Name("R");
58 mISet.Name("I");
59}
60
61// Copy construct
63 FD_DC("RabinPair(" << this << ")::RabinPair(other): " << rRP.Name());
64 Name("RabinPair");
65 mRSet.Name("R");
66 mISet.Name("I");
67 DoAssign(rRP);
68}
69
70// Assign my members
71void RabinPair::DoAssign(const RabinPair& rSrc) {
72 mRSet=rSrc.mRSet;
73 mISet=rSrc.mISet;
74}
75
76// Clear configuration
77void RabinPair::Clear(void) {
78 mRSet.Clear();
79 mISet.Clear();
80}
81
82// Ordering
83bool RabinPair::operator<(const RabinPair& rOther) const {
84 if(mRSet<rOther.mRSet) return true;
85 if(rOther.mRSet<mRSet) return false;
86 return mISet<rOther.mISet;
87}
88
89// Test equality
90bool RabinPair::DoEqual(const RabinPair& rOther) const {
91 if(mRSet != rOther.mRSet) return false;
92 if(mISet != rOther.mISet) return false;
93 return true;
94}
95
96// Write
97void RabinPair::DoWrite(TokenWriter& rTw,const std::string& rLabel, const Type* pContext) const {
98 FD_DC("RabinPair(" << this << ")::DoWrite(tw)");
99 // insist in label
100 std::string label="RabinPair";
101 // set up outer tag with name
102 Token btag;
103 btag.SetBegin(label);
104 btag.InsAttributeString("name",Name());
105 // begin tag
106 rTw.Write(btag);
107 // use context if its a generator (todo:xml)
108 const vGenerator* vg = dynamic_cast<const vGenerator*>(pContext);
109 if(vg!=nullptr) {
110 FD_DC("RabinPair(" << this << ")::DoWrite(tw): using context");
111 vg->WriteStateSet(rTw, mRSet,"R");
112 vg->WriteStateSet(rTw, mISet, "I");
113 } else {
114 FD_DC("RabinPair(" << this << ")::DoWrite(tw): no context");
115 mRSet.Write(rTw, "R", pContext);
116 mISet.Write(rTw, "I", pContext);
117 }
118 // close tag
119 rTw.WriteEnd(label);
120}
121
122
123// Write XML
124void RabinPair::DoXWrite(TokenWriter& rTw,const std::string& rLabel, const Type* pContext) const{
125 FD_DC("RabinPair(" << this << ")::DoXWrite(tw)");
126 // default label
127 std::string label=rLabel;
128 if(label=="") label="RabinPair";
129 // set up outer tag
130 Token btag=XBeginTag(label,"RabinPair");
131 rTw.Write(btag);
132 // use context if its a generator (todo:xml)
133 const vGenerator* vg = dynamic_cast<const vGenerator*>(pContext);
134 if(vg!=nullptr) {
135 FD_DC("RabinPair(" << this << ")::DoXWrite(tw): using context");
136 vg->XWriteStateSet(rTw, mRSet, "R");
137 vg->XWriteStateSet(rTw, mISet, "I");
138 } else {
139 FD_DC("RabinPair(" << this << ")::DoXWrite(tw): no context");
140 mRSet.XWrite(rTw, "R", pContext);
141 mISet.XWrite(rTw, "I", pContext);
142 }
143 // close tag
144 rTw.WriteEnd(btag.StringValue());
145}
146
147//DoRead(rTr)
148void RabinPair::DoRead(TokenReader& rTr, const std::string& rLabel, const Type* pContext) {
149 FD_DC("RabinPair(" << this << ")::DoRead(tr)");
150 // default label
151 std::string label=rLabel;
152 if(label=="") label="RabinPair";
153 // read begin
154 Token btag;
155 rTr.ReadBegin(label,btag);
156 FD_DC("RabinPair(" << this << ")::DoRead(tr): found " << btag.Str());
157 // figure name from begin tag
158 Name("");
159 if(btag.ExistsAttributeString("name"))
160 Name(btag.AttributeStringValue("name"));
161 FD_DC("RabinPair(" << this << ")::DoRead(tr): object name " << Name());
162 // use context if its a generator (todo:xml)
163 const vGenerator* vg = dynamic_cast<const vGenerator*>(pContext);
164 if(vg!=nullptr) {
165 vg->ReadStateSet(rTr, "R", mRSet);
166 vg->ReadStateSet(rTr, "I", mISet);
167 } else {
168 mRSet.Read(rTr,"R",pContext);
169 mISet.Read(rTr,"I",pContext);
170 }
171 // end tag
172 rTr.ReadEnd(label);
173}
174
175
176// restrict domain
178 mRSet.RestrictSet(rDomain);
179 mISet.RestrictSet(rDomain);
180}
181
182
183/*
184********************************
185implementation RabinAcceptance
186********************************
187*/
188
189// faudes Type std
191
192// Consttruct
194 FD_DC("RabinAcceptance(" << this << ")::RabinAcceptance()");
195 Name("RabinAcceptance");
196}
197
198// Copy construct
200 FD_DC("RabinAcceptance(" << this << ")::RabinAcceptance(other): " << rRA.Name());
201 Name("RabinAcceptance");
202 DoAssign(rRA);
203}
204
205// Condtruct from file
206RabinAcceptance::RabinAcceptance(const std::string& rFileName) : TBaseVector<RabinPair>() {
207 Name("RabinAcceptance");
208 Read(rFileName);
209}
210
211
212
213// DoSWrite()
215 //TBaseVector::DoSWrite(rTw); // also use base?
216 Type::DoSWrite(rTw);
217 rTw.WriteComment(" RabinPairs: " + ToStringInteger(Size()));
218 CIterator rit;
219 for(rit=Begin();rit!=End();++rit)
220 rTw.WriteComment(" R/I-States: " + ToStringInteger(rit->RSet().Size()) +
221 "/" + ToStringInteger(rit->ISet().Size()));
222 rTw.WriteComment(" ");
223}
224
225// restrict domain
227 Iterator rit;
228 for(rit=Begin();rit!=End();++rit)
229 rit->RestrictStates(rDomain);
230}
231
232
233}// namespace
234
235
#define FD_DC(message)
#define FAUDES_TYPE_IMPLEMENTATION(ftype, ctype, cbase)
Definition cfl_types.h:958
const std::string & Name(void) const
virtual void DoSWrite(TokenWriter &rTw) const
void RestrictStates(const StateSet &rDomain)
bool operator<(const RabinPair &rOther) const
void RestrictStates(const StateSet &rDomain)
virtual void DoWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=nullptr) const
virtual void DoRead(TokenReader &rTr, const std::string &rLabel="", const Type *pContext=nullptr)
virtual void DoXWrite(TokenWriter &rTw, const std::string &rLabel="", const Type *pContext=nullptr) const
StateSet & RSet(void)
StateSet & ISet(void)
void DoAssign(const RabinPair &rSrc)
virtual void Clear(void)
bool DoEqual(const RabinPair &rOther) const
void DoAssign(const TBaseVector< RabinPair > &rSourceVector)
void ReadEnd(const std::string &rLabel)
void ReadBegin(const std::string &rLabel)
void WriteComment(const std::string &rComment)
void Write(Token &rToken)
void WriteEnd(const std::string &rLabel)
std::string Str(void) const
const std::string & StringValue(void) const
bool ExistsAttributeString(const std::string &name)
void SetBegin(const std::string &rName)
Definition cfl_token.cpp:92
void InsAttributeString(const std::string &name, const std::string &value)
const std::string & AttributeStringValue(const std::string &name)
virtual Token XBeginTag(const std::string &rLabel="", const std::string &rFallbackLabel="") const
void Read(const std::string &rFileName, const std::string &rLabel="", const Type *pContext=0)
virtual void XWrite(const std::string &pFileName, const std::string &rLabel="", const Type *pContext=0) const
virtual void DoSWrite(TokenWriter &rTw) const
void Write(const Type *pContext=0) const
void WriteStateSet(const StateSet &rStateSet) const
void XWriteStateSet(TokenWriter &rTw, const StateSet &rStateSet, const std::string &rLabel="") const
void ReadStateSet(TokenReader &rTr, const std::string &rLabel, StateSet &rStateSet) const
virtual void Clear(void)
virtual void RestrictSet(const TBaseSet &rOtherSet)
Idx Size(void) const
AutoRegisterElementType< RabinAcceptance > gRtiRabinAcceptanceEType("RabinAcceptance","RabinPair")
AutoRegisterElementTag< RabinAcceptance > gRtiRabinAcceptanceETag("RabinAcceptance","RabinPair")
AutoRegisterType< RabinAcceptance > gRtiRabinAcceptance("RabinAcceptance")
AutoRegisterType< RabinPair > gRtiRabinPair("RabinPair")
std::string ToStringInteger(Int number)
Definition cfl_utils.cpp:43

libFAUDES 2.33k --- 2025.09.16 --- c++ api documentaion by doxygen