//============================================================================== /// Configures the given filter. //============================================================================== void JRangeFilter::Config(std::string filter){ Reset(); std::string tx,tx2; while(!filter.empty()){ int pos=int(filter.find(",")); tx=(pos>0? filter.substr(0,pos): filter); filter=(pos>0? filter.substr(pos+1): ""); pos=int(tx.find("-")); tx2=(pos>0? tx.substr(0,pos): ""); if(pos>0)tx=tx.substr(pos+1); if(tx2.empty())AddValue(atoi(tx.c_str())); else AddRange(atoi(tx2.c_str()),atoi(tx.c_str())); } SortRanges(); JoinRanges(); if(Count){ ValueMin=Ranges[0]; ValueMax=Ranges[((int(Count)-1)<<1)+1]; if(ValueMax-ValueMin<1000&&ValueMax-ValueMin>1&&Count>1){ FastValue=new byte[ValueMax-ValueMin+1]; memset(FastValue,0,sizeof(byte)*(ValueMax-ValueMin+1)); for(unsigned c=0;c<Count;c++){ unsigned r=Ranges[c<<1],r2=Ranges[(c<<1)+1]; for(;r<=r2;r++)FastValue[r-ValueMin]=1; } } } }
template<class T> Vector<T>& Vector<T>::operator+=(Vector const & source) { if(!source.IsEmpty()) AddRange(source.Begin(), source.End()); return *this; }
bool trpgRangeTable::Read(trpgReadBuffer &buf) { int32 numRange; trpgToken tok; int32 len; valid = false; try { buf.Get(numRange); if (numRange < 0) throw 1; for (int i=0;i<numRange;i++) { // Read in the individual range buf.GetToken(tok,len); if (tok != TRPG_RANGE) throw 1; buf.PushLimit(len); trpgRange range; bool status = range.Read(buf); buf.PopLimit(); if (!status) throw 1; AddRange(range); } valid = true; } catch (...) { return false; } return isValid(); }
template<class T> Vector<T>::Vector(ConstElement* begin, ConstElement* end, CtorModeEnum ctorMode) : _ctorMode(ctorMode), _origin(NULL), _last(NULL), _end(NULL) { AddRange(begin, end); }
static int Append(ElementType *SC1, ElementType *SC2) { if (SC1 == NULL || SC2 == NULL) { return NullPtrError("Append"); } if (SC1->Flags & CONTAINER_READONLY) { return ReadOnlyError(SC1,"Append"); } return AddRange(SC1,SC2->count,(const CHAR_TYPE **)SC2->contents); }
void InitFilterTable() { filter_count=0; AddRange(L"uxtheme.dll"); AddRange(L"usp10.dll"); AddRange(L"msctf.dll"); AddRange(L"gdiplus.dll"); AddRange(L"lpk.dll"); AddRange(L"psapi.dll"); AddRange(L"user32.dll"); }
int trpgRangeTable::FindAddRange(trpgRange &range) { RangeMapType::iterator itr = rangeMap.begin(); for ( ; itr != rangeMap.end( ); itr++) { if(itr->second==range) return itr->first; } #if 0 for (int i=0;i<rangeList.size();i++) { if (range == rangeList[i]) return i; } #endif return AddRange(range); }
RegExpressionT *D(char *e, int *place) { int input, peek, nextchar, result, invert = 0; RegExpressionT *ex; CharSetT *cs; input = NextCharacter(e, *place); if (input == '^') { invert = 1; AdvanceParser(e, place); } cs = CreateCharSet(); while(1) { input = NextCharacter(e, *place); switch(input) { case ']': if (invert) InvertCharSet(cs); ex = NewRegularExpression(); ex->type = CHARSET; ex->charset = cs; return ex; default: if (!ValidForD(input)) { #if ERR_MESG fprintf(stderr, "Bad regexp: character %c.\n", input); fprintf(stderr, "%s == at %d\n", e, *place); #endif free (cs); return NULL; } if (input == '\\') peek = 2; else if (input == '#') peek = 4; else peek = 1; nextchar = PeekCharacter(e, place, peek); if (nextchar == '-') result = AddRange(e, place, cs); else result = AddSymbol(e, place, cs); if (result == 0) { #if ERR_MESG fprintf(stderr, "Failed to create character set.\n"); fprintf(stderr, "%s == at %d\n", e, *place); #endif free (cs); return NULL; } } } return NULL; }
void OutputSet::Add(int output_port, int vc, int pri) { AddRange(output_port, vc, vc, pri); }
/******************************************************* * Convert an IP list to numbers and add them ********************************************************/ int AddIPRanges(NumList* n, char* Ranges){ int i; char ThisNum[64]; int ThisNumCount; unsigned int LowNum; unsigned int HighNum; unsigned int Mask; int SubListID; int IsDashed=FALSE; DEBUGPATH; if (!n) return FALSE; #ifdef DEBUG printf("Ranges is %s\n",Ranges); #endif if ( (SubListID=GetListByName(Ranges))!=LIST_NONE){ if (!AddSubList(n,Globals.Lists[SubListID].List)){ printf("Failed to add ip list \"%s\" \n",Ranges); return FALSE; } return TRUE; } ThisNumCount=0; LowNum=0; for (i=0;i<=strlen(Ranges);i++){ switch(Ranges[i]){ case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0': case '.': /*normal number, keep going*/ ThisNum[ThisNumCount]=Ranges[i]; ThisNumCount++; break; case '-': /*contiguous range notation*/ /*this a delimiter, add the numbers*/ ThisNum[ThisNumCount]=0x00; LowNum=ntohl(inet_addr(ThisNum)); #ifdef DEBUG printf("Setting Low Range to %u\n",LowNum); #endif ThisNumCount=0; IsDashed=TRUE; break; case 0x00: case ',': /*this a delimiter, add the numbers*/ ThisNum[ThisNumCount]=0x00; HighNum=ntohl(inet_addr(ThisNum)); if (LowNum==0) LowNum=HighNum; if (IsDashed){ AddRange(n, LowNum, HighNum); #ifdef DEBUG printf("1Added Number %u-%u\n",LowNum, HighNum); #endif }else{ /*there may be a bug here*/ /*keep an eye on it*/ AddRange(n, LowNum, LowNum); #ifdef DEBUG printf("5Added Number %u-%u\n", LowNum, LowNum); #endif } ThisNumCount=0; IsDashed=FALSE; LowNum=0; break; case ' ': /*ignore white space*/ break; case '/': /*this is a range*/ ThisNum[ThisNumCount]=0x00; LowNum=ntohl(inet_addr(ThisNum)); i++; Mask=atoi(&Ranges[i]); HighNum=LowNum; switch (Mask){ case 0: LowNum&=0x00000000; HighNum|=0xFFFFFFFF; AddRange(n, LowNum, HighNum); break; case 1: LowNum&=0x10000000; HighNum|=0x7FFFFFFF; AddRange(n, LowNum, HighNum); break; case 2: LowNum&=0x30000000; HighNum|=0x3FFFFFFF; AddRange(n, LowNum, HighNum); break; case 3: LowNum&=0x70000000; HighNum|=0x1FFFFFFF; AddRange(n, LowNum, HighNum); break; case 4: LowNum&=0xF0000000; HighNum|=0x0FFFFFFF; AddRange(n, LowNum, HighNum); break; case 5: LowNum&=0xF1000000; HighNum|=0x07FFFFFF; AddRange(n, LowNum, HighNum); break; case 6: LowNum&=0xF3000000; HighNum|=0x03FFFFFF; AddRange(n, LowNum, HighNum); break; case 7: LowNum&=0xF7000000; HighNum|=0x01FFFFFF; AddRange(n, LowNum, HighNum); break; case 8: LowNum&=0xFF000000; HighNum|=0x00FFFFFF; AddRange(n, LowNum, HighNum); break; case 9: LowNum&=0xFF100000; HighNum|=0x007FFFFF; AddRange(n, LowNum, HighNum); break; case 10: LowNum&=0xFF300000; HighNum|=0x003FFFFF; AddRange(n, LowNum, HighNum); break; case 11: LowNum&=0xFF700000; HighNum|=0x001FFFFF; AddRange(n, LowNum, HighNum); break; case 12: LowNum&=0xFFF00000; HighNum|=0x000FFFFF; AddRange(n, LowNum, HighNum); break; case 13: LowNum&=0xFFF10000; HighNum|=0x0007FFFF; AddRange(n, LowNum, HighNum); break; case 14: LowNum&=0xFFF30000; HighNum|=0x0003FFFF; AddRange(n, LowNum, HighNum); break; case 15: LowNum&=0xFFF70000; HighNum|=0x0001FFFF; AddRange(n, LowNum, HighNum); break; case 16: LowNum&=0xFFFF0000; HighNum|=0x0000FFFF; AddRange(n, LowNum, HighNum); break; case 17: LowNum&=0xFFFF1000; HighNum|=0x00007FFF; AddRange(n, LowNum, HighNum); break; case 18: LowNum&=0xFFFF3000; HighNum|=0x00003FFF; AddRange(n, LowNum, HighNum); break; case 19: LowNum&=0xFFFF7000; HighNum|=0x00001FFF; AddRange(n, LowNum, HighNum); break; case 20: LowNum&=0xFFFF000; HighNum|=0x00000FFF; AddRange(n, LowNum, HighNum); break; case 21: LowNum&=0xFFFFF100; HighNum|=0x000007FF; AddRange(n, LowNum, HighNum); break; case 22: LowNum&=0xFFFFF300; HighNum|=0x000003FF; AddRange(n, LowNum, HighNum); break; case 23: LowNum&=0xFFFFF700; HighNum|=0x000001FF; AddRange(n, LowNum, HighNum); break; case 24: LowNum&=0xFFFFFF00; HighNum|=0x000000FF; AddRange(n, LowNum, HighNum); break; case 25: LowNum&=0xFFFFFF10; HighNum|=0x0000007F; AddRange(n, LowNum, HighNum); break; case 26: LowNum&=0xFFFFFF30; HighNum|=0x0000003F; AddRange(n, LowNum, HighNum); break; case 27: LowNum&=0xFFFFFF70; HighNum|=0x0000001F; AddRange(n, LowNum, HighNum); break; case 28: LowNum&=0xFFFFFFF0; HighNum|=0x0000000F; AddRange(n, LowNum, HighNum); break; case 29: LowNum&=0xFFFFFFF1; HighNum|=0x00000007; AddRange(n, LowNum, HighNum); break; case 30: LowNum&=0xFFFFFFF3; HighNum|=0x00000003; AddRange(n, LowNum, HighNum); break; case 31: LowNum&=0xFFFFFFF7; HighNum|=0x00000001; AddRange(n, LowNum, HighNum); break; case 32: LowNum&=0xFFFFFFFF; HighNum|=0x00000000; AddRange(n, LowNum, HighNum); break; default: printf("Invalid CIDR Notation /%u\n",Mask); return FALSE; } #ifdef DEBUG printf("1Added Range %u-%u\n",LowNum, HighNum); #endif while ((Ranges[i]>='0') && (Ranges[i]<='9')) i++; ThisNumCount=0; IsDashed=FALSE; break; default: printf("Invalid character \"%c\"\n", Ranges[i]); printf("I don't understand %s\n",Ranges); return FALSE; } } return TRUE; }
/**************************************************** * Parse a string for the ranges ****************************************************/ int AddRangesString(NumList* n, char* RawRanges, NumAlias* Aliases, int NumAliases){ int i; char ThisNum[64]; int ThisNumCount; unsigned int LowNum; unsigned int HighNum; int IsRange; char* Ranges; DEBUGPATH; if (!n) return FALSE; Ranges=calloc(strlen(RawRanges)*2,sizeof(char)); if (!ReplaceAliases(RawRanges, strlen(RawRanges), Ranges, strlen(RawRanges)*2, Aliases, NumAliases)){ printf("Couldn't apply alias list\n"); free(Ranges); return FALSE; } ThisNumCount=0; IsRange=FALSE; for (i=0;i<strlen(Ranges);i++){ switch(Ranges[i]){ case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0': /*normal number, keep going*/ ThisNum[ThisNumCount]=Ranges[i]; ThisNumCount++; break; case ',': /*this a delimiter, add the numbers*/ ThisNum[ThisNumCount]=0x00; if (!IsRange){ LowNum=strtoul(ThisNum,NULL,10); AddRange(n, LowNum, LowNum); #ifdef DEBUG printf("2Added Number %u-%u\n",LowNum, LowNum); #endif }else{ HighNum=strtoul(ThisNum, NULL, 10); AddRange(n, LowNum, HighNum); #ifdef DEBUG printf("Added Range %u-%u\n",LowNum, HighNum); #endif } ThisNumCount=0; IsRange=FALSE; break; case ' ': /*ignore white space*/ break; case '-': /*this is a range*/ ThisNum[ThisNumCount]=0x00; LowNum=strtoul(ThisNum, NULL, 10); #ifdef DEBUG printf("Low part of the range is %u\n",LowNum); #endif IsRange=TRUE; ThisNumCount=0; break; default: printf("Invalid character \"%c\"\n", Ranges[i]); printf("I don't understand %s\n",Ranges); free(Ranges); return FALSE; } } /*Finish out the last one*/ ThisNum[ThisNumCount]=0x00; if (!IsRange){ LowNum=strtoul(ThisNum,NULL,10); AddRange(n, LowNum, LowNum); #ifdef DEBUG printf("3Added Number %u-%u\n",LowNum, LowNum); #endif }else{ HighNum=strtoul(ThisNum, NULL, 10); AddRange(n, LowNum, HighNum); #ifdef DEBUG printf("Added Range %u-%u\n",LowNum, HighNum); #endif } free(Ranges); return TRUE; }
/*---------------------------------------------------------------------------------------------------------------------- | Reads in a set from a NEXUS data file. Returns true if the set was terminated by a semicolon, false otherwise. */ bool NxsSetReader::Run() { bool ok; bool retval = false; unsigned rangeBegin = UINT_MAX; unsigned rangeEnd = rangeBegin; bool insideRange = false; unsigned modValue = 0; for (;;) { // Next token should be one of the following: // ';' --> set definition finished // '-' --> range being defined // <integer> --> member of set (or beginning or end of a range) // '.' --> signifies the number max // '\' --> signifies modulus value coming next // token.GetNextToken(); if (token.Equals("-")) { // We should not be inside a range when we encounter a hyphenation symbol. // The hyphen is what _puts_ us inside a range! // if (insideRange) { block.errormsg = "The symbol '-' is out of place here"; throw NxsException(block.errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } insideRange = true; } else if (token.Equals(".")) { // We _should_ be inside a range if we encounter a period, as this // is a range termination character // if (!insideRange) { block.errormsg = "The symbol '.' can only be used to specify the end of a range"; throw NxsException(block.errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } rangeEnd = max; } else if (token.Equals("\\")) { // The backslash character is used to specify a modulus to a range, and // thus should only be encountered if currently inside a range // if (!insideRange) { block.errormsg = "The symbol '\\' can only be used after the end of a range has been specified"; throw NxsException(block.errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } // This should be the modulus value // modValue = NxsToken::DemandPositiveInt(token, block.errormsg, "The modulus value"); } else if (insideRange && rangeEnd == UINT_MAX) { // The beginning of the range and the hyphen symbol have been read // already, just need to store the end of the range at this point // rangeEnd = GetTokenValue(); } else if (insideRange) { // If insideRange is true, we must have already stored the beginning // of the range and read in the hyphen character. We would not have // made it this far if we had also not already stored the range end. // Thus, we can go ahead and add the range. // ok = AddRange(rangeBegin, rangeEnd, modValue); if (!ok) { block.errormsg = "Character number out of range (or range incorrectly specified) in set specification"; throw NxsException(block.errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } // We have actually already read in the next token, so deal with it // now so that we don't end up skipping a token // if (token.Equals(";")) { retval = true; break; } else if (token.Equals(",")) { break; } rangeBegin = GetTokenValue(); rangeEnd = UINT_MAX; insideRange = false; } else if (rangeBegin != UINT_MAX) { // If we were inside a range, we would have not gotten this far. // If not in a range, we are either getting ready to begin a new // range or have previously read in a single value. Handle the // latter possibility here. // ok = AddRange(rangeBegin, rangeBegin, modValue); if (!ok) { block.errormsg = "Character number out of range (or range incorrectly specified) in set specification"; throw NxsException(block.errormsg, token.GetFilePosition(), token.GetFileLine(), token.GetFileColumn()); } if (token.Equals(";")) { retval = true; break; } else if (token.Equals(",")) { break; } rangeBegin = GetTokenValue(); rangeEnd = UINT_MAX; } else if (token.Equals(";")) { retval = true; break; } else if (token.Equals(",")) { break; } else if (token.Equals("ALL")) { rangeBegin = 1; rangeEnd = max; ok = AddRange(rangeBegin, rangeEnd); } else { // Can only get here if rangeBegin still equals UINT_MAX and thus we // are reading in the very first token and that token is neither // the word "all" nor is it a semicolon // rangeBegin = GetTokenValue(); rangeEnd = UINT_MAX; } } return retval; }
//**************************************************************************************** BOOL CBCGPGridSerializeManager::PrepareDataFromSelection () { ASSERT (m_pOwnerGrid != NULL); CleanUp (); if (m_pOwnerGrid != NULL) { m_nLastColumn = m_pOwnerGrid->GetColumnsInfo ().GetColumnCount (TRUE) - 1; m_nLastRow = m_pOwnerGrid->GetTotalRowCount () - 1; } if (m_ClipboardFormatType == CF_Rows) { if (!m_pOwnerGrid->NormalizeSelectionList ()) { return FALSE; } } //--------------------- // Calculate min offset //--------------------- int i = 0; CBCGPGridItemID idOffset (-1, -1); for (i = 0; i < m_pOwnerGrid->GetSelectionCount (); i++) { CBCGPGridRange rangeIndex, rangeOrder; if (m_pOwnerGrid->GetSelection (i, rangeIndex) && IndexToOrder (rangeIndex, rangeOrder)) { const int nRow = (rangeOrder.m_nTop != -1) ? rangeOrder.m_nTop: 0; const int nCol = (rangeOrder.m_nLeft != -1) ? rangeOrder.m_nLeft: 0; if (idOffset.m_nRow == -1 || nRow <= idOffset.m_nRow) { idOffset.m_nRow = nRow; } if (idOffset.m_nColumn == -1 || nCol <= idOffset.m_nColumn) { idOffset.m_nColumn = nCol; } if (idOffset.m_nRow == -1 || idOffset.m_nRow == 0 && idOffset.m_nRow == m_nLastRow) { m_bWholeColSelected = TRUE; } if (idOffset.m_nColumn == -1 || idOffset.m_nColumn == 0 && idOffset.m_nColumn == m_nLastColumn) { m_bWholeRowSelected = TRUE; } } } if (idOffset.m_nRow == -1) { idOffset.m_nRow = 0; } if (idOffset.m_nColumn == -1) { idOffset.m_nColumn = 0; } ASSERT (idOffset.m_nRow >= 0); ASSERT (idOffset.m_nColumn >= 0); m_idRangesOffset = idOffset; //------------------------------ // Prepare serialized selection: //------------------------------ for (i = 0; i < m_pOwnerGrid->GetSelectionCount (); i++) { CBCGPGridRange rangeIndex, rangeOrder; if (m_pOwnerGrid->GetSelection (i, rangeIndex) && IndexToOrder (rangeIndex, rangeOrder)) { const int nRowOffset = (rangeOrder.m_nTop != -1) ? rangeOrder.m_nTop - m_idRangesOffset.m_nRow: 0; const int nColOffset = (rangeOrder.m_nLeft != -1) ? rangeOrder.m_nLeft - m_idRangesOffset.m_nColumn: 0; CBCGPGridRange rangeRelative ( nColOffset, nRowOffset, nColOffset + (rangeOrder.m_nRight - rangeOrder.m_nLeft), nRowOffset + (rangeOrder.m_nBottom - rangeOrder.m_nTop)); try { CMemFile f; CArchive archive (&f, CArchive::store | CArchive::bNoFlushOnDelete); if (m_ClipboardFormatType == CF_Items) { WriteItemsToArchive (archive, rangeOrder); } else if (m_ClipboardFormatType == CF_Rows) { WriteRowsToArchive (archive, rangeOrder); } archive.Close (); if (f.GetLength () <= 0) { return FALSE; } UINT cbSize = (UINT)f.GetLength (); BYTE* pData = new BYTE[cbSize]; if (NULL == pData) { delete [] pData; return FALSE; } f.SeekToBegin (); if (f.Read (pData, cbSize) != cbSize) { delete [] pData; return FALSE; } AddRange (rangeRelative, cbSize, pData); } catch (CFileException* pEx) { TRACE(_T("CBCGPGridSerializeManager::PrepareDataFromSelection. File exception\r\n")); pEx->Delete (); return FALSE; } catch (CException* e) { TRACE(_T("CBCGPGridSerializeManager::PrepareDataFromSelection. Exception\r\n")); e->Delete (); return FALSE; } } } return TRUE; }
//**************************************************************************************** BOOL CBCGPGridSerializeManager::ReadFromArchive (CArchive& archive) { CleanUp (); if (m_pOwnerGrid != NULL) { m_nLastColumn = m_pOwnerGrid->GetColumnsInfo ().GetColumnCount (TRUE) - 1; m_nLastRow = m_pOwnerGrid->GetTotalRowCount () - 1; } //---------------------- // Read serialized data: //---------------------- // int - format type // int - ranges common offset: row // int - ranges common offset: column // int - range count // ranges array: // int - range offset: row \ // int - range offset: column | range // int - range size: row count | // int - range size: columns count | // UINT - size in bytes | range data | // BYTE - range data | / try { int nClipboardFormatType = 0;; archive >> nClipboardFormatType; if (nClipboardFormatType != (int) m_ClipboardFormatType) { return FALSE; } //----------------------------------- // Read common offset for all ranges: //----------------------------------- archive >> m_idRangesOffset.m_nRow; archive >> m_idRangesOffset.m_nColumn; //--------------------- // Read list of ranges: //--------------------- int nRangeCount = 0; archive >> nRangeCount; if (nRangeCount <= 0) { return FALSE; } for (int nRange = 0; nRange < nRangeCount; nRange++) { //------------ // Read range: //------------ CBCGPGridItemID idOffset; archive >> idOffset.m_nRow; archive >> idOffset.m_nColumn; int nRowCount = 0; archive >> nRowCount; if (nRowCount <= 0) { return FALSE; } int nColCount = 0; archive >> nColCount; if (nColCount <= 0) { return FALSE; } CBCGPGridRange range ( idOffset.m_nColumn, idOffset.m_nRow, idOffset.m_nColumn + nColCount - 1, idOffset.m_nRow + nRowCount - 1); if (idOffset.m_nRow == 0 && nRowCount - 1 == m_nLastRow) { m_bWholeColSelected = TRUE; } if (idOffset.m_nColumn == 0 && nColCount - 1 == m_nLastColumn) { m_bWholeRowSelected = TRUE; } //----------------- // Read range data: //----------------- UINT nDataSize = 0; archive >> nDataSize; if (nDataSize <= 0) { return FALSE; } BYTE* pData = new BYTE[nDataSize]; if (NULL == pData) { delete [] pData; return FALSE; } if (archive.Read (pData, nDataSize) != nDataSize) { delete [] pData; return FALSE; } AddRange (range, nDataSize, pData); } } catch (CArchiveException* pEx) { TRACE(_T("CBCGPGridSerializeManager::ReadFromArchive. Archive exception\r\n")); pEx->Delete (); return FALSE; } return TRUE; }
void CGUIDialogMediaFilter::InitializeSettings() { CGUIDialogSettingsManualBase::InitializeSettings(); if (m_filter == NULL) return; Reset(true); int handledRules = 0; CSettingCategory *category = AddCategory("filter", -1); if (category == NULL) { CLog::Log(LOGERROR, "CGUIDialogMediaFilter: unable to setup filters"); return; } CSettingGroup *group = AddGroup(category); if (group == NULL) { CLog::Log(LOGERROR, "CGUIDialogMediaFilter: unable to setup filters"); return; } for (unsigned int index = 0; index < NUM_FILTERS; index++) { if (filterList[index].mediaType != m_mediaType) continue; Filter filter = filterList[index]; // check the smartplaylist if it contains a matching rule for (CDatabaseQueryRules::iterator rule = m_filter->m_ruleCombination.m_rules.begin(); rule != m_filter->m_ruleCombination.m_rules.end(); rule++) { if ((*rule)->m_field == filter.field) { filter.rule = (CSmartPlaylistRule *)rule->get(); handledRules++; break; } } std::string settingId = StringUtils::Format("filter.%s.%d", filter.mediaType.c_str(), filter.field); if (filter.controlType == "edit") { CVariant data; if (filter.rule != NULL && filter.rule->m_parameter.size() == 1) data = filter.rule->m_parameter.at(0); if (filter.settingType == SettingTypeString) filter.setting = AddEdit(group, settingId, filter.label, 0, data.asString(), true, false, filter.label, true); else if (filter.settingType == SettingTypeInteger) filter.setting = AddEdit(group, settingId, filter.label, 0, static_cast<int>(data.asInteger()), 0, 1, 0, false, static_cast<int>(filter.label), true); else if (filter.settingType == SettingTypeNumber) filter.setting = AddEdit(group, settingId, filter.label, 0, data.asFloat(), 0.0f, 1.0f, 0.0f, false, filter.label, true); } else if (filter.controlType == "toggle") { int value = CHECK_ALL; if (filter.rule != NULL) value = filter.rule->m_operator == CDatabaseQueryRule::OPERATOR_TRUE ? CHECK_YES : CHECK_NO; StaticIntegerSettingOptions entries; entries.push_back(std::pair<int, int>(CHECK_LABEL_ALL, CHECK_ALL)); entries.push_back(std::pair<int, int>(CHECK_LABEL_NO, CHECK_NO)); entries.push_back(std::pair<int, int>(CHECK_LABEL_YES, CHECK_YES)); filter.setting = AddSpinner(group, settingId, filter.label, 0, value, entries, true); } else if (filter.controlType == "list") { std::vector<std::string> values; if (filter.rule != NULL && !filter.rule->m_parameter.empty()) { values = StringUtils::Split(filter.rule->GetParameter(), DATABASEQUERY_RULE_VALUE_SEPARATOR); if (values.size() == 1 && values.at(0).empty()) values.erase(values.begin()); } filter.setting = AddList(group, settingId, filter.label, 0, values, GetStringListOptions, filter.label); } else if (filter.controlType == "range") { CVariant valueLower, valueUpper; if (filter.rule != NULL) { if (filter.rule->m_parameter.size() == 2) { valueLower = filter.rule->m_parameter.at(0); valueUpper = filter.rule->m_parameter.at(1); } else { DeleteRule(filter.field); filter.rule = NULL; } } if (filter.settingType == SettingTypeInteger) { int min, interval, max; GetRange(filter, min, interval, max); // don't create the filter if there's no real range if (min == max) continue; int iValueLower = valueLower.isNull() ? min : static_cast<int>(valueLower.asInteger()); int iValueUpper = valueUpper.isNull() ? max : static_cast<int>(valueUpper.asInteger()); if (filter.controlFormat == "integer") filter.setting = AddRange(group, settingId, filter.label, 0, iValueLower, iValueUpper, min, interval, max, -1, 21469, true); else if (filter.controlFormat == "percentage") filter.setting = AddPercentageRange(group, settingId, filter.label, 0, iValueLower, iValueUpper, -1, 1, 21469, true); else if (filter.controlFormat == "date") filter.setting = AddDateRange(group, settingId, filter.label, 0, iValueLower, iValueUpper, min, interval, max, -1, 21469, true); else if (filter.controlFormat == "time") filter.setting = AddTimeRange(group, settingId, filter.label, 0, iValueLower, iValueUpper, min, interval, max, -1, 21469, true); } else if (filter.settingType == SettingTypeNumber) { float min, interval, max; GetRange(filter, min, interval, max); // don't create the filter if there's no real range if (min == max) continue; float fValueLower = valueLower.isNull() ? min : valueLower.asFloat(); float fValueUpper = valueUpper.isNull() ? max : valueUpper.asFloat(); filter.setting = AddRange(group, settingId, filter.label, 0, fValueLower, fValueUpper, min, interval, max, -1, 21469, true); } } else { if (filter.rule != NULL) handledRules--; CLog::Log(LOGWARNING, "CGUIDialogMediaFilter: filter %d of media type %s with unknown control type '%s'", filter.field, filter.mediaType.c_str(), filter.controlType.c_str()); continue; } if (filter.setting == NULL) { if (filter.rule != NULL) handledRules--; CLog::Log(LOGWARNING, "CGUIDialogMediaFilter: failed to create filter %d of media type %s with control type '%s'", filter.field, filter.mediaType.c_str(), filter.controlType.c_str()); continue; } m_filters.insert(make_pair(settingId, filter)); } // make sure that no change in capacity size is needed when adding new rules // which would copy around the rules and our pointers in the Filter struct // wouldn't work anymore m_filter->m_ruleCombination.m_rules.reserve(m_filters.size() + (m_filter->m_ruleCombination.m_rules.size() - handledRules)); }
struct ZippedUniqueObjectCollection { // apply _func_ to _graphics_ and _physics_ #define DOBOTH(func) graphics.func; physics.func; UniqueObjectCollection graphics, physics; inline void Add(WorldObject& obj) { DOBOTH(Add(obj)) } template<typename Iter> inline void AddRange(Iter begin, Iter end) { DOBOTH(AddRange(begin, end)) } inline void Remove(WorldObject& obj) { DOBOTH(Remove(obj)) } template<typename Iter> inline void RemoveRange(Iter begin, Iter end) { DOBOTH(RemoveRange(begin, end)) } #undef DOBOTH };