23 #ifndef COM_DAFER45_TBTK_INDEX_TREE
24 #define COM_DAFER45_TBTK_INDEX_TREE
156 SearchMode searchMode = SearchMode::StrictMatch,
157 bool returnNegativeForMissingIndex =
false
235 template<
bool isConstIterator>
240 typedef typename std::conditional<
260 typedef typename std::conditional<
264 >::type IndexTreePointerType;
267 IndexTreePointerType indexTree;
270 std::vector<int> currentIndex;
280 _Iterator(IndexTreePointerType indexTree,
bool end =
false);
287 unsigned int subindex
291 friend class Iterator;
292 friend class ConstIterator;
302 ) : _Iterator<true>(indexTree,
end){}
329 virtual std::string
toString()
const;
335 std::vector<IndexTree> children;
362 void add(
const Index& index,
unsigned int subindex);
372 unsigned int subindex,
374 bool returnNegativeForMissingIndex
381 std::vector<Subindex> &indices
385 int getMinIndex()
const;
388 int getMaxIndex()
const;
392 return !(lhs == rhs);
422 template<
bool isConstIterator>
423 IndexTree::_Iterator<isConstIterator>::_Iterator(IndexTreePointerType indexTree,
bool end){
425 this->indexTree = indexTree;
426 currentIndex.push_back(indexTree->children.size());
429 this->indexTree = indexTree;
430 currentIndex.push_back(0);
431 skipNextIndex =
false;
432 searchNext(this->indexTree, 0);
436 template<
bool isConstIterator>
437 void IndexTree::_Iterator<isConstIterator>::operator++(){
438 skipNextIndex =
true;
439 searchNext(indexTree, 0);
442 template<
bool isConstIterator>
443 bool IndexTree::_Iterator<isConstIterator>::searchNext(
444 const IndexTree *indexTree,
445 unsigned int subindex
447 if(indexTree->children.size() == 0){
448 if(indexTree->indexIncluded){
450 skipNextIndex =
false;
456 unsigned int n = currentIndex.at(subindex);
457 while(n < indexTree->children.size()){
458 if(subindex+1 == currentIndex.size())
459 currentIndex.push_back(0);
460 if(searchNext(&indexTree->children.at(n), subindex+1))
463 currentIndex.pop_back();
464 n = ++currentIndex.back();
470 template<
bool isConstIterator>
471 typename IndexTree::_Iterator<isConstIterator>::IndexType IndexTree::_Iterator<isConstIterator>::operator*(){
472 if(currentIndex.at(0) == (
int)indexTree->children.size()){
474 "IndexTree::_Iterator<isConstIterator>::operator*()",
475 "Out of range access. Tried to access an element using"
476 <<
" an Iterator that points beyond the last element.",
483 const IndexTree *indexTreeBranch = this->indexTree;
484 for(
unsigned int n = 0; n < currentIndex.size()-1; n++){
485 if(indexTreeBranch->indexSeparator)
486 index.pushBack(IDX_SEPARATOR);
488 if(indexTreeBranch->wildcardIndex)
489 index.pushBack(indexTreeBranch->wildcardType);
491 index.pushBack(currentIndex.at(n));
493 if(n < currentIndex.size()-1)
494 indexTreeBranch = &indexTreeBranch->children.at(currentIndex.at(n));
500 template<
bool isConstIterator>
501 bool IndexTree::_Iterator<isConstIterator>::operator==(
const _Iterator &rhs)
const{
502 if(indexTree != rhs.indexTree)
505 if(currentIndex.size() != rhs.currentIndex.size())
508 for(
unsigned int n = 0; n < currentIndex.size(); n++)
509 if(currentIndex[n] != rhs.currentIndex[n])
515 template<
bool isConstIterator>
516 bool IndexTree::_Iterator<isConstIterator>::operator!=(
const _Iterator &rhs)
const{
517 return !operator==(rhs);