2 * Copyright (c) 2013 TOYOTA MOTOR CORPORATION.
6 * Licensed under the Apache License, Version 2.0 (the License){}
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 #include "CicoEvent.h"
24 #include "CicoEventInfo.h"
25 #include "CicoStateCore.h"
29 * event infomation class
35 * @brief CicoEventInfo::CicoEventInfo
36 * @param ev base event data
38 CicoEventInfo::CicoEventInfo(unsigned short ev):
42 m_transition = (CicoStateCore*)0; // Initialize the pointer value
46 * @brief CicoEventInfo::CicoEventInfo
47 * @param ev event number
48 * @param gcstr operator kind
49 * @param value Comparison value
51 CicoEventInfo::CicoEventInfo(unsigned short ev, const std::string& gcstr,
55 m_JGCE = chgGCType(gcstr); // string change to enum
56 m_transition = (CicoStateCore*)0; // Initialize the pointer value
60 * @brief CicoEventInfo::CicoEventInfo
61 * @param ev event number
62 * @param gcstr operator kind
63 * @param value Comparison value
65 CicoEventInfo::CicoEventInfo(unsigned short ev, const std::string& gcstr,
69 m_JGCE = chgGCType(gcstr); // string change to enum
70 m_transition = (CicoStateCore*)0; // Initialize the pointer value
74 * @brief CicoEventInfo::CicoEventInfo
75 * @param ev event number
76 * @param gcstr operator kind
77 * @param value Comparison value
79 CicoEventInfo::CicoEventInfo(unsigned short ev, const std::string& gcstr,
80 const std::string& value):
83 m_JGCE = chgGCType(gcstr); // string change to enum
84 m_transition = (CicoStateCore*)0; // Initialize the pointer value
88 * @brief CicoEventInfo::CicoEventInfo
89 * @param name event name
90 * @param ev event number
92 CicoEventInfo::CicoEventInfo(const std::string& name, unsigned short ev):
93 CicoEvent(ev), m_name(name)
96 m_transition = (CicoStateCore*)0; // Initialize the pointer value
100 * @brief CicoEventInfo::CicoEventInfo
101 * @param name event name
102 * @param ev event number
103 * @param gcstr operator kind
104 * @param value Comparison value
106 CicoEventInfo::CicoEventInfo(const std::string& name, unsigned short ev,
107 const std::string& gcstr, int value):
108 CicoEvent(ev, value), m_name(name)
110 m_JGCE = chgGCType(gcstr); // string change to enum
111 m_transition = (CicoStateCore*)0; // Initialize the pointer value
115 * @brief CicoEventInfo::CicoEventInfo
116 * @param name event name
117 * @param ev event number
118 * @param gcstr operator kind
119 * @param value Comparison value
121 CicoEventInfo::CicoEventInfo(const std::string& name, unsigned short ev,
122 const std::string& gcstr, double value):
123 CicoEvent(ev, value), m_name(name)
125 m_JGCE = chgGCType(gcstr); // string change to enum
126 m_transition = (CicoStateCore*)0; // Initialize the pointer value
130 * @brief CicoEventInfo::CicoEventInfo
131 * @param name event name
132 * @param ev event number
133 * @param gcstr operator kind
134 * @param value Comparison value
136 CicoEventInfo::CicoEventInfo(const std::string& name, unsigned short ev,
137 const std::string& gcstr,
138 const std::string& value):
139 CicoEvent(ev, value), m_name(name)
141 m_JGCE = chgGCType(gcstr); // string change to enum
142 m_transition = (CicoStateCore*)0; // Initialize the pointer value
146 * @brief CicoEventInfo::CicoEventInfo
147 * @param ei copy source
149 CicoEventInfo::CicoEventInfo(const CicoEventInfo& ei):
153 m_transition = (CicoStateCore*)0; // Initialize the pointer value
158 * @brief CicoEventInfo::~CicoEventInfo
160 CicoEventInfo::~CicoEventInfo()
162 if (false == m_vEvt.empty()) {
165 if (false == m_vJGCE.empty()) {
168 if (false == m_vAgc.empty()) {
171 // m_transition = (CicoStateCore*)0;
175 * @brief CicoEventInfo::addAndGurdCondition
176 * @param gcstr operator kind
177 * @param value Comparison value
178 * @return true:added success false:added fail
180 bool CicoEventInfo::addAndGurdCondition(const std::string& gcstr, int value)
182 CicoEvent e(m_ev, value);
183 E_JGCE j = chgGCType(gcstr); // string change to enum
187 addGurdCondition(e, j, EAGC_AND);
192 * @brief CicoEventInfo::addAndGurdCondition
193 * @param gcstr operator kind
194 * @param value Comparison value
195 * @return true:added success false:added fail
197 bool CicoEventInfo::addAndGurdCondition(const std::string& gcstr, double value)
199 CicoEvent e(m_ev, value);
200 E_JGCE j = chgGCType(gcstr); // string change to enum
204 addGurdCondition(e, j, EAGC_AND);
209 * @brief CicoEventInfo::addAndGurdCondition
210 * @param gcstr operator kind
211 * @param value Comparison value
212 * @return true:added success false:added fail
214 bool CicoEventInfo::addAndGurdCondition(const std::string& gcstr,
215 const std::string& value)
217 CicoEvent e(m_ev, value);
218 E_JGCE j = chgGCType(gcstr); // string change to enum
222 addGurdCondition(e, j, EAGC_AND);
227 * @brief CicoEventInfo::addOrGurdCondition
228 * @param gcstr operator kind
229 * @param value Comparison value
230 * @return true:added success false:added fail
232 bool CicoEventInfo::addOrGurdCondition(const std::string& gcstr, int value)
234 CicoEvent e(m_ev, value);
235 E_JGCE j = chgGCType(gcstr); // string change to enum
239 addGurdCondition(e, j, EAGC_OR);
245 * @brief CicoEventInfo::addOrGurdCondition
246 * @param gcstr operator kind
247 * @param value Comparison value
248 * @return true:added success false:added fail
250 bool CicoEventInfo::addOrGurdCondition(const std::string& gcstr,
253 CicoEvent e(m_ev, value);
254 E_JGCE j = chgGCType(gcstr); // string change to enum
258 addGurdCondition(e, j, EAGC_OR);
263 * @brief CicoEventInfo::addOrGurdCondition
264 * @param gcstr operator kind
265 * @param value Comparison value
266 * @return true:added success false:added fail
268 bool CicoEventInfo::addOrGurdCondition(const std::string& gcstr,
269 const std::string& value)
271 CicoEvent e(m_ev, value);
272 E_JGCE j = chgGCType(gcstr); // string change to enum
276 addGurdCondition(e, j, EAGC_OR);
281 * @brief CicoEventInfo::Judge
282 * @param ev event data
283 * @param sm compare trigger state-object
284 * @return true:event match false:event Mismatch
286 bool CicoEventInfo::Judge(const CicoEvent& ev, const CicoStateCore* sm) const
288 if (m_ev != ev.getEV()) { //
289 return false; // event number mismatch
291 // The event number matches
292 if (Ejnj == m_JGCE) { // Without guard condition
293 return true; // event match !
295 // check guard condition
296 bool bR = checkGurdCondition(m_JGCE, *((CicoEvent*)this), ev, sm); // return value
298 int sz = m_vEvt.size();
299 for (int i=0; i<sz; i++) {
300 bool bR2 = checkGurdCondition(m_vJGCE[i], m_vEvt[i], ev, sm);
301 E_AGC agc = m_vAgc[i];
302 if (EAGC_AND == agc) {
305 else if (EAGC_OR == agc) {
316 * @brief CicoEventInfo::checkGurdCondition
318 * @param base event data
319 * @param rec event data
320 * @param sm compair trigger state-object
321 * @return treu:match false:Mismatch
323 bool CicoEventInfo::checkGurdCondition(E_JGCE j, const CicoEvent& base,
324 const CicoEvent& rec,
325 const CicoStateCore* sm) const
327 bool bR = false; // return value init.
328 if ((Ein == j)||(Enot == j)) { // Guard condition of active state object
329 const CicoStateCore* stt = (CicoStateCore*)0;
330 if (EEvtGCInt == base.getVTG()) {
331 stt = getStateF(sm, base.getGCVi());
333 else if (EEvtGCStr == base.getVTG()) {
334 stt = getStateF(sm, base.getGCVs());
336 if ((CicoStateCore*)0 == stt) {
339 bR = checkActive(j, *stt);
341 else { // Remaining comparisons
342 bR = checkCompare(j, base, rec);
348 * @brief CicoEventInfo::checkActive
349 * @param j in or not operator
350 * @param stt check target
351 * @return true:event match false:event Mismatch
353 bool CicoEventInfo::checkActive(E_JGCE j, const CicoStateCore& stt) const
356 if (true == stt.isActive()) {
360 else if (Enot == j) {
361 if (false == stt.isActive()) {
369 * @brief CicoEventInfo::checkCompare
371 * @param base Comparison Event
372 * @param rec Comparison Event
373 * @return true:match false:Mismatch
375 bool CicoEventInfo::checkCompare(E_JGCE j, const CicoEvent& base,
376 const CicoEvent& rec) const
385 case Ejne: // Not equal
390 case Ejgt: // greater than
395 case Ejge: // greater than or equal
400 case Ejlt: // less than
405 case Ejle: // less than or equal
417 * @brief CicoEventInfo::addGurdCondition
418 * @param e Comparison Event
419 * @param j operator infomation(==/!=/>/>=/</<=/in/not)
422 void CicoEventInfo::addGurdCondition(CicoEvent& e, E_JGCE j, E_AGC a)
424 if (Ejnj == m_JGCE) {
425 E_TOV tov = e.getVTG();
426 if (EEvtGCInt == tov) {
430 else if (EEvtGCDouble == tov) {
434 else if (EEvtGCStr == tov) {
441 m_vJGCE.push_back(j);
447 * @brief CicoEventInfo::chgGCType
448 * @param gcstr string operator
449 * @return enum operator
451 CicoEventInfo::E_JGCE CicoEventInfo::chgGCType(const std::string& gcstr) const
453 if (gcstr == DEFJGCE_EQ) { // "="
454 return Ejeq; // equal
456 else if (gcstr == DEFJGCE_NE) { // "!="
457 return Ejne; // Not equal
459 else if (gcstr == DEFJGCE_GT) { // "<"
460 return Ejgt; // greater than
462 else if (gcstr == DEFJGCE_GE) { // "<="
463 return Ejge; // greater than or equal
465 else if (gcstr == DEFJGCE_GE2) { // "=<"
466 return Ejge; // greater than or equal
468 else if (gcstr == DEFJGCE_LT) { // ">"
469 return Ejlt; // less than
471 else if (gcstr == DEFJGCE_LE) { // ">="
472 return Ejle; // less than or equal
474 else if (gcstr == DEFJGCE_LE2) { // "=>"
475 return Ejle; // less than or equal
478 std::string s(gcstr); // copy string
479 transform(s.begin(), s.end(), s.begin(), tolower); // converted to lower case
480 if (s == DEFJGCE_IN) { // "in"
481 return Ein; // in active state object
483 else if (s == DEFJGCE_NOT) { // "not"
484 return Enot; // not active state object
492 return Ejnj; // Not Judgment
496 * @brief CicoEventInfo::operator =
497 * @param s copy source
499 void CicoEventInfo::operator=(const CicoEventInfo& s)
503 E_TOV tov = s.getVTG();
518 setAdVal(s.getAdVal());
520 // CicoEventInfo Block
521 m_name = s.m_name; // copy event name
522 m_JGCE = s.m_JGCE; // copy Judgment guard condition expression
523 int sz = s.m_vEvt.size(); // get vector member size
524 for (int i = 0; i < sz; i++) { // vector menber size loop
525 m_vEvt.push_back(s.m_vEvt[i]);
526 m_vJGCE.push_back(s.m_vJGCE[i]);
527 m_vAgc.push_back(s.m_vAgc[i]);
529 m_transition = s.m_transition; //
534 * @param e log target
535 * @param l store log string
537 void getLogPartF(const CicoEventInfo& e, std::string& l)
539 const char* opstr[] = {
540 "??", // Ejnj Not Judgment
541 DEFJGCE_EQ, // "=" Ejeq equal
542 DEFJGCE_NE, // "!=" Ejne Not equal
543 DEFJGCE_LT, // "<" Ejlt less than
544 DEFJGCE_LE, // "<=" Ejle less than or equal
545 DEFJGCE_GT, // ">" Ejgt greater than
546 DEFJGCE_GE, // ">=" Ejge greater than or equal
547 DEFJGCE_IN, // "in" Ein in active state object
548 DEFJGCE_NOT, // "not" Enot not active state object
550 std::stringstream stm;
552 if (!((e.getName()).empty())) {
553 stm << "\"" << e.getName() << "\"";
555 stm << ":" << e.getEV() << ":";
556 CicoEventInfo::E_JGCE jgce = e.getGCType();
557 if (CicoEventInfo::Ejnj != jgce) {
561 if ((CicoEventInfo::Ein == jgce)||
562 (CicoEventInfo::Enot == jgce)) {
567 case CicoEvent::EEvtGCInt:
570 case CicoEvent::EEvtGCDouble:
573 case CicoEvent::EEvtGCStr:
574 stm << "\"" << e.getGCVs() << "\"";
576 default: // CicoEvent::EEvtGCUnset
579 if (true == bInNot) {
582 // if (0 != e->m_vAgc.size()) {
591 * @param a Comparison target A
592 * @param b Comparison target B
595 bool operator==(const CicoEventInfo& a, const CicoEventInfo& b)
597 if (a.getEV() == b.getEV()) { // event No. match
598 bool anm = a.m_name.empty();
599 bool bnm = b.m_name.empty();
600 if ((true == anm) && (true == bnm)) { //
603 else if ((false == anm) && (false == bnm)) {
604 if (a.m_name == b.m_name) {