コード例 #1
0
ファイル: rangelist.hpp プロジェクト: billw2012/BGalaxy1
	void add(value_type start, value_type end)
	{
		if(end <= start)
			return;
		// dirty list represents ranges with alternate elements: start,end,start,end 
		// to insert a new range:
		// find insert point of start. find element before, if it is a start element then it is the start of the new range
		// otherwise the new insertion is
		// find insert point of end. find element after, if it is an end element then it is the end of the new range
		// otherwise the new insertion is
		std::pair<RangeMap::iterator, bool> sloc = _ranges.insert(RangeRec(start, true));

		if(sloc.first != _ranges.begin())
		{
			RangeMap::iterator prev = sloc.first; prev--;
			if(prev->start)
			{
				sloc.first--;
			}
		}
		std::pair<RangeMap::iterator, bool> eloc = _ranges.insert(RangeRec(end, false));
		RangeMap::iterator next = eloc.first; next++;

		if(next != _ranges.end() && !next->start)
		{
			eloc.first++;
		}

		// erase the interior of the range
		++sloc.first;
		if(sloc.first != eloc.first && sloc.first != _ranges.end())
		{
			//eloc.first;
			if(sloc.first != eloc.first)
				_ranges.erase(sloc.first, eloc.first);
			else
				_ranges.erase(sloc.first);
		}
		assert((_ranges.size() - 1) % 2 != 0);
	}
コード例 #2
0
ファイル: rangelist.hpp プロジェクト: billw2012/BGalaxy1
	bool empty() const
	{
		return _ranges.size() == 0;
	}