| Revision 1 (by moose, 2006/03/06 10:00:33) |
Initial Import
|
// FuncObjs.h - An STL Iterator for the Internet Explorer Cache
// Copyright 2000 by Samir Bajaj
//
// NOTES
// This file contains the implementation of function objects
// to illustrate the use of cache_iterator with STL algorithms.
#include "CacheIter.h"
template <typename T>
struct always_true: public std::unary_function<T, bool>
{
bool operator()(T) { return true; }
};
struct display_cache_entry
{
void operator()(INTERNET_CACHE_ENTRY_INFO CacheEntryInfo) const
{
if (CacheEntryInfo.lpszLocalFileName)
std::cout << CacheEntryInfo.lpszLocalFileName << std::endl;
}
};
struct cache_file_size: std::binary_function<size_t, INTERNET_CACHE_ENTRY_INFO, size_t>
{
size_t operator()(size_t n, INTERNET_CACHE_ENTRY_INFO CacheEntryInfo)
{
if (CacheEntryInfo.lpszLocalFileName)
{
HANDLE hFile;
if (INVALID_HANDLE_VALUE != (hFile = ::CreateFile(CacheEntryInfo.lpszLocalFileName, GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
OPEN_EXISTING, 0, 0)))
{
n += ::GetFileSize(hFile, 0);
::CloseHandle(hFile);
}
}
return n;
}
};