Click here to Skip to main content
15,886,689 members
Articles / Desktop Programming / WTL

A fast and lightweight cell control

Rate me:
Please Sign up or sign in to vote.
4.42/5 (31 votes)
11 Mar 2008CPOL1 min read 90.9K   4.5K   81  
A fast and lightweight cell control for displaying tabular data. The cell is a custom control derived from ATL::CWindow.
/* -------------------------------------------------------------------------
//MyCell Library - MyCell version 1.0
//
// This file is a part of the MyCell Library.
// The use and distribution terms for this software are covered by the
// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
// which can be found in the file CPL.txt at this distribution. By using
// this software in any fashion, you are agreeing to be bound by the terms
// of this license. You must not remove this notice, or any other, from
// this software.
//
// Creator: yanxueming
// Email: xueming.yan@gmail.com
// -----------------------------------------------------------------------*/
#pragma once
#include <map>
using namespace std;
namespace mycell{
	//[beg,end]
	template<typename k,typename v>
	void delete_cols(map<k,v>& m,int beg,int end)
	{
		int const cnt=end-beg+1;
		map<k,v> mt;
		for(map<k,v>::const_iterator it=m.begin();it!=m.end();++it){
			const int nK=it->first;
			if(nK<beg){
				mt.insert(*it);
			}else if(nK>end){
				mt.insert(make_pair(nK-cnt,it->second));
			}
		}
		m.swap(mt);
		/*
		vector<pair<k,v> > vec;
		for(map<k,v>::iterator it=m.begin();it!=m.end();)
		{
			if(it->first>=beg && it->first<=end){
				it=m.erase(it);
				continue;	   
			}else if(it->first > end){
				vec.push_back(make_pair(it->first-cnt,it->second));
				it=m.erase(it);
				continue;
			}
			++it;
		}
		for(vector<pair<k,v> >::const_iterator it=vec.begin();it!=vec.end();++it)
			m.insert(*it);
			*/
	}
	//��begǰ����nCount��
	template<typename k,typename v>
	void insert_cols(map<k,v>& m,int beg,int nCount)
	{
		//int const end=beg+nCount;
		map<k,v> mt;
		for(map<k,v>::const_iterator it=m.begin();it!=m.end();++it){
			const int nK=it->first;
			if(nK<beg){
				mt.insert(*it);
			}else{
				mt.insert(make_pair(nK+nCount,it->second));
			}
		}
		m.swap(mt);
		/*
		vector<pair<k,v> > vec;
		for(map<k,v>::iterator it=m.begin();it!=m.end();)
		{
			if(it->first>=beg){
				vec.push_back(make_pair(it->first+nCount,it->second));
				it=m.erase(it);
				continue;
			}
			++it;
		}
		for(vector<pair<k,v> >::const_iterator it=vec.begin();it!=vec.end();++it)
		{
			m.insert(*it);
		}
		*/
	}
}//namespace mycell

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
China China
My name is Yanxueming,i live in Chengdu China.Graduated from UESTC in 1999.

Comments and Discussions