Click here to Skip to main content
15,894,460 members
Articles / Desktop Programming / WTL

A little tool to show some system informations

Rate me:
Please Sign up or sign in to vote.
4.59/5 (15 votes)
12 May 2007CPOL1 min read 40.1K   3K   42  
This small tool shows some real-time system information, such as network speed, CPU utilization, time period and so on on the screen .
#pragma once

#include <list>

using namespace std;


template <class T>
class CDataHistoryT
{
public:
	typedef typename list<T> list_type;
	typedef typename list<T>::size_type size_type;

	CDataHistoryT(): szHistoryLength(400)
	{

	}

	~CDataHistoryT()
	{

	}

	void Push(T d)	// the front is newer, the back is older
	{
		AddData(d);
	}

	int GetHistoryLength(void){return (int)szHistoryLength;}
	int GetSize(void){return (int)lData.size();}
	const list_type & GetDataList(void){return lData;}
	void Clone(list_type & ltTarget){ltTarget.assign(lData.begin(), lData.end());}

	int FillDataToBuffer(T * tBuffer, T * pMin, T * pMax)
	{
		size_type sz = 0;
		list_type::const_iterator i = lData.begin();
		if(i != lData.end())
		{
			if(pMin)
				*pMin = *i;
			if(pMax)
				*pMax = *i;
		}
		for(i = lData.begin(); i != lData.end(); i++)
		{
			tBuffer[sz++] = *i;
			if(pMin)
			{
				if(*pMin > *i)
					*pMin = *i;
			}
			if(pMax)
			{
				if(*pMax < *i)
					*pMax = *i;
			}
		}
		return (int)sz;
	}

	int FillDataToBuffer(T * tBuffer, T * pMin, T * pMax, int nBufferSize)
	{
		if(nBufferSize < 1)
			return 0;
		size_type sz = 0;
		list_type::const_iterator i = lData.begin();
		if(i != lData.end())
		{
			if(pMin)
				*pMin = *i;
			if(pMax)
				*pMax = *i;
		}
		for(i = lData.begin(); i != lData.end(); i++)
		{
			tBuffer[sz++] = *i;
			if(pMin)
			{
				if(*pMin > *i)
					*pMin = *i;
			}
			if(pMax)
			{
				if(*pMax < *i)
					*pMax = *i;
			}
			if((int)sz >= nBufferSize)
				break;
		}
		return (int)sz;
	}

	void SetHistoryLength(int n)
	{
		size_type szNew = (size_type)n;

		if(szNew <= 0)
			return;
		szHistoryLength = szNew;
		if(lData.size() > szHistoryLength)
		{
			size_type sz = lData.size() - szHistoryLength;
			for(size_type i = 0; i < sz; i++)
				lData.pop_back();
		}
	}

	void Clear(void)
	{
		lData.clear();
	}
protected:
	list_type lData;
	size_type szHistoryLength;

	void AddData(T d)
	{
		lData.push_front(d);
		if(lData.size() > szHistoryLength)
		{
			size_type sz = lData.size() - szHistoryLength;
			for(size_type i = 0; i < sz; i++)
				lData.pop_back();
		}
	}
};


typedef CDataHistoryT<DWORD> CDWDataHistory;
typedef CDataHistoryT<double> CDBDataHistory;

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
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions