bool TCopyParamList::CompareItem(intptr_t Index, const TCopyParamType * CopyParam, const TCopyParamRule * Rule) const { return ((*GetCopyParam(Index)) == *CopyParam) && ((GetRule(Index) == nullptr) ? (Rule == nullptr) : ((Rule != nullptr) && (*GetRule(Index)) == (*Rule))); }
RULEID __CopyRule(LPRULE lpOldRule, ITEMID idName) { #ifdef INFERENCE RULEID idRule; LPRULE lpRule; LPEXP lpBody; EXPID idBody; if (GetRule(idName) != NULLID) return NULLID; idRule = KppAddItemAndName (RULE, (LPLPSTR)&lpRule, idName); if (!idRule) return NULLID; NAME(lpRule) = idName; FLAGS(lpRule) = NULL; PRIORITY(lpRule) = 0; MATCHES(lpRule) = NULLID; NUMVARS(lpRule) = NUMVARS(lpOldRule); if (! (FLAGS(lpRule) & CBODY)) { VARS(lpRule) = KppDeepListCopy(VARS(lpOldRule), Kpp__CopyVar,idRule); idBody = BODY(lpRule) = KppCopyExp( BODY(lpOldRule), (LPLPSTR)&lpBody, kPERMMODE); KppReleaseExp(idBody); } KppReleaseItem(RULE, idRule); /* Add to KnowledgeTools */ KppAddItemCB (RULE, 1); return idRule; #endif }
void RuleSet::SetJumpIndex(int startPos, int endPos, int ruleNo) { //std::cout << xCurrRuleTerm << " sets jump " << startPos << " - " << endPos << " to " << ruleNo << std::endl; if (startPos < 1) Message(MSG_WARNING, "bad startPos", int2str(startPos)); ensure(startPos >= 0); // Viggo changed from >0 to >= 0 2000-04-04 for (int p=startPos; p<=endPos; p++) { if (jumpIndex[p] > ruleNo && jumpIndex[p] != NRules() && !rules[ruleNo]->IsHelpRule()) { Message(MSG_WARNING, GetRule(ruleNo)->Name(), int2str(p), "bad jump; rules already jumped to", jumpIndex[p] == NRules() ? "endrules" : GetRule(jumpIndex[p])->Name()); } jumpIndex[p] = ruleNo; } }
ServoKeyframeRule* IndexedGetter(uint32_t aIndex, bool& aFound) final { if (aIndex >= mRules.Length()) { aFound = false; return nullptr; } aFound = true; return GetRule(aIndex); }
void TCopyParamList::Delete(intptr_t Index) { DebugAssert((Index >= 0) && (Index < GetCount())); FNames->Delete(Index); delete GetCopyParam(Index); FCopyParams->Delete(Index); delete GetRule(Index); FRules->Delete(Index); Modify(); }
// Derives a final string using the grammar rules associated with each variable found within. std::string Grammar::RandomizedDerivation() { ParseVariablesAndRules(m_file_content); // Grab "START" from the variables vector. if (!m_variables.empty()) { auto i = m_variables.begin(); m_current_string = (*i)->m_name; } std::string temp = ""; // Keep looping until all variables have been derived. Every variable found within the current string are stored // in the 'm_variable_references' vector. Ideally this would store custom objects, but I store them as string // objects instead. while (AnyCapitalLettersLeft(m_current_string)) { temp = ""; for (unsigned i = 0; i < m_current_string.size(); i++) { if (isupper(m_current_string.at(i))) { temp += m_current_string.at(i); } // This takes care of variables that are not at the end of the sentence (i.e. "CONTENTS on ...") if (!isupper(m_current_string.at(i))) { if (temp != "") { m_variable_references.push_back(temp); } temp = ""; } } // This takes care of variables at the end of a sentence (i.e. "... BREAD", or "START") if (temp != "") { m_variable_references.push_back(temp); } // This loop derives all of the variables that were found in the current string. while (!m_variable_references.empty()) { srand((unsigned int)time(NULL)); // Randomly choose which variable to derive. int rand_index = rand() % m_variable_references.size(); auto iter = m_variable_references.at(rand_index); std::cout << "in \"" << iter << "\" replacing \"" << iter << "\" with \"" << GetRule(iter) << "\""; replace(m_current_string, iter, GetRule(iter)); std::cout << " to obtain \"" << m_current_string << "\"" << std::endl; m_variable_references.erase(m_variable_references.begin() + rand_index); } } return m_current_string; }
void TCopyParamList::Clear() { for (intptr_t Index = 0; Index < GetCount(); ++Index) { delete GetCopyParam(Index); delete GetRule(Index); } FCopyParams->Clear(); FRules->Clear(); FNames->Clear(); }
//--------------------------------------------------------------------------- void TCopyParamList::Clear() { for (intptr_t I = 0; I < GetCount(); I++) { delete GetCopyParam(I); delete GetRule(I); } FCopyParams->Clear(); FRules->Clear(); FNames->Clear(); }
sFileRule CGame_MVC2_P::GetNextRule() { sFileRule NewFileRule = GetRule(uRuleCtr); uRuleCtr++; if(uRuleCtr >= MVC2_D_NUMUNIT) { uRuleCtr = 0xFF; } return NewFileRule; }
BOOL CRecurrenceRuleMonthlyDlg::UpdateRule (const COleDateTime& /*dtStart*/) { BOOL bRes = UpdateData (); if (bRes) { CBCGPRecurrenceRuleMonthly* pRule = (CBCGPRecurrenceRuleMonthly*)GetRule (); if (m_btnTypeDay.GetCheck () == BST_CHECKED) { if (m_dwDay < 1 || m_dwDay > 31) { return FALSE; } if (m_dwDaySpan < 1 || m_dwDaySpan > 1000) { return FALSE; } if (m_dwDay > 28) { CString str; str.Format (IDS_APPOINTMENT_4, m_dwDay); AfxMessageBox (str, MB_ICONWARNING); } pRule->SetType (CBCGPRecurrenceRuleMonthly::BCGP_REC_RULE_MONTHLY_TYPE_DAY); pRule->SetDay (m_dwDay); pRule->SetDaySpan (m_dwDaySpan); } else { if (m_dwDayTypeSpan < 1 || m_dwDayTypeSpan > 1000) { return FALSE; } pRule->SetType (CBCGPRecurrenceRuleMonthly::BCGP_REC_RULE_MONTHLY_TYPE_DAYTYPE); pRule->SetDayTypeDay ((CBCGPRecurrenceRuleMonthly::BCGP_REC_RULE_MONTHLY_DAYTYPE_DAY)m_nDayTypeDay); pRule->SetDayTypeWeekDay ((CBCGPRecurrenceRuleMonthly::BCGP_REC_RULE_MONTHLY_DAYTYPE_WEEKDAY)m_nDayTypeWeekDay); pRule->SetDayTypeSpan (m_dwDayTypeSpan); } } return bRes; }
intptr_t TCopyParamList::Find(const TCopyParamRuleData & Value) const { intptr_t Result = -1; intptr_t Index = 0; while ((Index < FRules->GetCount()) && (Result < 0)) { if (FRules->GetItem(Index) != nullptr) { if (GetRule(Index)->Matches(Value)) { Result = Index; } } ++Index; } return Result; }
void TCopyParamList::Change(intptr_t Index, const UnicodeString & Name, TCopyParamType * CopyParam, TCopyParamRule * Rule) { if ((Name != GetName(Index)) || !CompareItem(Index, CopyParam, Rule)) { FNames->SetString(Index, Name); delete GetCopyParam(Index); FCopyParams->SetItem(Index, CopyParam); delete GetRule(Index); FRules->SetItem(Index, Rule); Modify(); } else { SAFE_DESTROY(CopyParam); SAFE_DESTROY(Rule); } }
//--------------------------------------------------------------------------- void TCopyParamList::Change(intptr_t Index, const UnicodeString & Name, TCopyParamType * CopyParam, TCopyParamRule * Rule) { if ((Name != GetName(Index)) || !CompareItem(Index, CopyParam, Rule)) { FNames->SetString(Index, Name); delete GetCopyParam(Index); FCopyParams->SetItem(Index, reinterpret_cast<TObject *>(CopyParam)); delete GetRule(Index); FRules->SetItem(Index, reinterpret_cast<TObject *>(Rule)); Modify(); } else { delete CopyParam; delete Rule; } }
BOOL CRecurrenceRuleDailyDlg::UpdateRule (const COleDateTime& /*dtStart*/) { BOOL bRes = UpdateData (); if (bRes) { if (m_Span < 1 || m_Span > 1000) { return FALSE; } CBCGPRecurrenceRuleDaily* pRule = (CBCGPRecurrenceRuleDaily*)GetRule (); pRule->SetSpan (m_Span); pRule->SetType ( m_btnTypeWeekDays.GetCheck () == BST_CHECKED ? CBCGPRecurrenceRuleDaily::BCGP_REC_RULE_DAILY_TYPE_WEEKDAYS : CBCGPRecurrenceRuleDaily::BCGP_REC_RULE_DAILY_TYPE_SPAN); } return bRes; }
void CBCGPRecurrence::DoException (const COleDateTime& dtDate, const CBCGPAppointmentPropertyList& props, BOOL bDeleted) { ASSERT_VALID (m_pAppointment); CBCGPAppointmentPropertyList srcProps; m_pAppointment->GetProperties (srcProps); if (!bDeleted) { ASSERT (srcProps.GetCount () == props.GetCount ()); } CBCGPRecurrenceBaseRule* pRule = GetRule (); ASSERT_VALID (pRule); COleDateTime dtStart; COleDateTime dtFinish; CBCGPAppointmentPropertyList propsEcp; XBCGPRecurrenceException* pEcp = GetException (dtDate); if (!bDeleted) { CBCGPAppointmentProperty* pProp = NULL; pProp = (CBCGPAppointmentProperty*)props.Get (BCGP_APPOINTMENT_PROPERTY_DATE_START); dtStart = *pProp; pProp = (CBCGPAppointmentProperty*)props.Get (BCGP_APPOINTMENT_PROPERTY_DATE_FINISH); dtFinish = *pProp; COleDateTime dtStartNeed (dtDate + pRule->GetTimeStart ()); COleDateTime dtFinishNeed (dtDate + pRule->GetTimeFinish ()); BOOL bTimeChanged = dtStart != dtStartNeed || dtFinish != dtFinishNeed; if (pEcp != NULL) { bTimeChanged |= pEcp->m_Properties.PropertyExists (BCGP_APPOINTMENT_PROPERTY_DATE_START) || pEcp->m_Properties.PropertyExists (BCGP_APPOINTMENT_PROPERTY_DATE_FINISH); if (!bDeleted) { POSITION pos = pEcp->m_Properties.GetStart (); DWORD ID = 0; CBCGPAppointmentBaseProperty* pProp = NULL; while (pos != NULL) { pEcp->m_Properties.GetNext (pos, ID, pProp); if (ID == BCGP_APPOINTMENT_PROPERTY_DATE_START || ID == BCGP_APPOINTMENT_PROPERTY_DATE_FINISH) { continue; } *(srcProps[ID]) = *pProp; } } } POSITION pos = srcProps.GetStart (); DWORD ID = 0; CBCGPAppointmentBaseProperty* pSrcProp = NULL; while (pos != NULL) { srcProps.GetNext (pos, ID, pSrcProp); if (!bTimeChanged && (ID == BCGP_APPOINTMENT_PROPERTY_DATE_START || ID == BCGP_APPOINTMENT_PROPERTY_DATE_FINISH)) { continue; } const CBCGPAppointmentBaseProperty* pDstProp = props.Get (ID); BOOL bEqual = TRUE; if (pDstProp == NULL) { continue; } else if (pSrcProp != NULL) { bEqual = *pSrcProp == *pDstProp; } if (!bEqual || (ID == BCGP_APPOINTMENT_PROPERTY_DATE_START || ID == BCGP_APPOINTMENT_PROPERTY_DATE_FINISH)) { CBCGPAppointmentBaseProperty* pNewProp = (CBCGPAppointmentBaseProperty*)(pDstProp->GetRuntimeClass ()->CreateObject ()); *pNewProp = *pDstProp; propsEcp[ID] = pNewProp; } } } if (bDeleted || propsEcp.GetCount () > 0) { if (pEcp == NULL) { pEcp = new XBCGPRecurrenceException; } if (!bDeleted) { pEcp->m_dtStart = dtStart; pEcp->m_dtFinish = dtFinish; POSITION pos = propsEcp.GetStart (); DWORD ID = 0; CBCGPAppointmentBaseProperty* pProp = NULL; while (pos != NULL) { propsEcp.GetNext (pos, ID, pProp); ASSERT_VALID (pProp); if (!pEcp->m_Properties.PropertyExists (ID)) { CBCGPAppointmentBaseProperty* pNewProp = (CBCGPAppointmentBaseProperty*)(pProp->GetRuntimeClass ()->CreateObject ()); *pNewProp = *pProp; pEcp->m_Properties[ID] = pNewProp; } else { *(pEcp->m_Properties[ID]) = *pProp; } } } else { pEcp->m_Deleted = bDeleted; pEcp->m_Properties.RemoveAll (); } m_Exceptions[dtDate] = pEcp; } }
void CBCGPRecurrence::Query (XBCGPAppointmentArray& ar, const COleDateTime& date1, const COleDateTime& date2) const { ar.RemoveAll (); POSITION Pos = m_Exceptions.GetStartPosition (); COleDateTime Key; XBCGPRecurrenceException* Val = NULL; CList<COleDateTime, const COleDateTime&> exceptions; CBCGPAppointment* pApp = NULL; while (Pos != NULL) { m_Exceptions.GetNextAssoc (Pos, Key, Val); if (Val != NULL && !Val->m_Deleted) { if ((date1 <= Val->m_dtStart && Val->m_dtStart <= date2) || (date1 <= Val->m_dtFinish && Val->m_dtFinish <= date2) || (Val->m_dtStart < date1 && date2 < Val->m_dtFinish)) { pApp = CreateClone (Key); if (pApp != NULL) { exceptions.AddTail (Key); ar.Add (pApp); } } } } CBCGPRecurrenceBaseRule* pRule = GetRule (); ASSERT_VALID(pRule); if (pRule == NULL) { return; } BOOL bNext = TRUE; COleDateTime dt1 (pRule->GetDateStart ()); if (!CBCGPPlannerView::IsOneDay (m_pAppointment->GetStart (), m_pAppointment->GetFinish ())) { if (dt1 < date1) { COleDateTimeSpan span ((double)((int) ((double)m_pAppointment->GetDuration () + 0.5))); COleDateTime d (date1 - span); if (d > dt1) { dt1 = pRule->GetSiblingEventDay (d); } bNext = FALSE; } } if (bNext) { if (dt1 <= date2) { if (dt1 <= date1) { dt1 = pRule->GetSiblingEventDay (date1); } } } if (dt1 == COleDateTime ()) { return; } while (dt1 <= date2) { if (exceptions.Find (dt1) == NULL && !ExceptionExists (dt1)) { pApp = CreateClone (dt1); if (pApp != NULL) { if (pApp->GetFinish () != date1 || (pApp->GetStart () == pApp->GetFinish () && pApp->GetFinish () == date1)) { ar.Add (pApp); } else { delete pApp; } } } dt1 = pRule->GetNextEventDay (dt1); if (dt1 == COleDateTime ()) { break; } } }
bool LL1Parser::Parse() { bool retVal(true); string errorString; string test_2 = ""; char space = ' '; while ( _currentToken != _tokens.end() && retVal == true && _Done == false ) { list<Token> test; while (test.empty() != true) { test.pop_front(); } if (_ruleStack.top().getString() == _currentToken->getString() || _ruleStack.top().getTokenType() == _currentToken->getTokenType()) // might need an OR top of the stack TYPE is the same as current token TYPE { cout << "Matched a token: " << _currentToken->getString() << endl; //cout << "Matched a character: " << _currentToken->getString() << endl; if (_currentToken->getString() == "$") { _Done = true; } else { FetchNext(); _ruleStack.pop(); } } else if (_ruleStack.top().getString() == " ") { cout << "lambda at: " << _currentToken->getString() << endl; //FetchNext(); _ruleStack.pop(); } else { test = GetRule(_ruleStack.top().getString(), _currentToken->getString()); if (test.empty() != true) { _ruleStack.pop(); //push entire "test" token list onto rule stack in reverse order list<Token> List = test; List.reverse(); for (auto itr = List.begin(); itr != List.end(); ++itr) { Token Pushme(itr->getString(), itr->getTokenType()); _ruleStack.push(Pushme); //test_2 = itr->getString(); /* else { string s; s += *itr; Token s2(s, TokenType::UNDEFINED); _ruleStack.push(s2); cout << *itr << endl; } */ } } else { errorString += "Error when trying to find rule [ "; errorString += _ruleStack.top().getString(); errorString += " , "; errorString += _currentToken->getString(); errorString += " ]"; _errors.push_back(errorString); retVal = false; } } //if the rule matching was successful //_currentToken++; } return retVal; }
void init_life1d(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int size = MI_SIZE(mi); int i; life1dstruct *lp; if (life1ds == NULL) { if ((life1ds = (life1dstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (life1dstruct))) == NULL) return; } lp = &life1ds[MI_SCREEN(mi)]; if (!init_stuff(mi)) { free_life1d(display, lp); return; } lp->screen_generation = 0; lp->row = 0; if (totalistic) { maxstates = MAXSTATES; maxradius = 4; maxsum_size = (maxstates - 1) * (maxradius * 2 + 1) + 1; } else { maxstates = MAXSTATES - 1; maxradius = 1; maxsum_size = (int) power(maxstates, (2 * maxradius + 1)); } if (lp->nextstate == NULL) { if ((lp->nextstate = (char *) malloc(maxsum_size * sizeof (char))) == NULL) { free_life1d(display, lp); return; } } if (lp->init_bits == 0) { XGCValues gcv; gcv.fill_style = FillOpaqueStippled; if ((lp->stippledGC = XCreateGC(display, window, GCFillStyle, &gcv)) == None) { free_life1d(display, lp); return; } for (i = 0; i < MAXSTATES - 1; i++) { LIFE1DBITS(stipples[i + NUMSTIPPLES - MAXSTATES + 1], STIPPLESIZE, STIPPLESIZE); } LIFE1DBITS(stipples[NUMSTIPPLES / 2], STIPPLESIZE, STIPPLESIZE); /* grey */ } if (lp->newcells != NULL) free(lp->newcells); if (lp->oldcells != NULL) free(lp->oldcells); if (lp->buffer != NULL) free(lp->buffer); if (lp->previousBuffer != NULL) free(lp->previousBuffer); lp->previousBuffer = (unsigned char *) NULL; lp->width = MI_WIDTH(mi); lp->height = MI_HEIGHT(mi); if (lp->width < 2) lp->width = 2; if (lp->height < 2) lp->height = 2; if (size == 0 || MINGRIDSIZE * size > lp->width || MINGRIDSIZE * size > lp->height) { if (lp->width > MINGRIDSIZE * lp->logo->width && lp->height > MINGRIDSIZE * lp->logo->height) { lp->pixelmode = False; lp->xs = lp->logo->width; lp->ys = lp->logo->height; } else { int min = MIN(lp->width, lp->height) / (12 * MINGRIDSIZE); int max = MIN(lp->width, lp->height) / (4 * MINGRIDSIZE); lp->xs = lp->ys = MAX(MINSIZE, min + NRAND(max - min + 1)); lp->pixelmode = True; } } else { lp->pixelmode = True; if (size < -MINSIZE) { lp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(lp->width, lp->height) / MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE; } else if (size < MINSIZE) { lp->ys = MINSIZE; } else { lp->ys = MIN(size, MAX(MINSIZE, MIN(lp->width, lp->height) / MINGRIDSIZE)); } lp->xs = lp->ys; } lp->ncols = MAX(lp->width / lp->xs, 2); lp->nrows = MAX(lp->height / lp->ys, 2); lp->border = (lp->nrows / 2 + 1) * MI_CYCLES(mi); if ((lp->newcells = (unsigned char *) calloc(lp->ncols + 2 * lp->border, sizeof (unsigned char))) == NULL) { free_life1d(display, lp); return; } if ((lp->oldcells = (unsigned char *) calloc(lp->ncols + 2 * (maxradius + lp->border), sizeof (unsigned char))) == NULL) { free_life1d(display, lp); return; } if ((lp->buffer = (unsigned char *) calloc(lp->ncols * lp->nrows, sizeof (unsigned char))) == NULL) { free_life1d(display, lp); return; } lp->xb = (lp->width - lp->xs * lp->ncols) / 2; lp->yb = (lp->height - lp->ys * lp->nrows) / 2; GetRule(lp, (int) NRAND((totalistic) ? TOTALISTICRULES : LCAURULES)); if (MI_IS_VERBOSE(mi)) { (void) fprintf(stdout, "colors %d, radius %d, code %ld, ", lp->k, lp->r, lp->code); if (totalistic) { (void) fprintf(stdout, "totalistic rule "); for (i = (lp->k - 1) * (lp->r * 2 + 1); i >= 0; i--) (void) fprintf(stdout, "%d", (int) lp->nextstate[i]); } else { (void) fprintf(stdout, "LCAU rule "); for (i = (int) power(lp->k, (lp->r * 2 + 1)); i >= 0; i--) (void) fprintf(stdout, "%d", (int) lp->nextstate[i]); } (void) fprintf(stdout, "\n"); } if (MI_NPIXELS(mi) > 2) { int offset = NRAND(MI_NPIXELS(mi)); for (i = 0; i < lp->k - 1; i++) { lp->colors[i] = ((offset + (i * MI_NPIXELS(mi) / (lp->k - 1))) % MI_NPIXELS(mi)); } } RandomSoup(lp, 40, 25); (void) memcpy((char *) (lp->oldcells + maxradius + lp->border), (char *) (lp->newcells + lp->border), lp->ncols); lp->busyLoop = 0; MI_CLEARWINDOWCOLORMAP(mi, lp->backGC, lp->black); }