1999-09-27 18:44:28 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
2001-06-01 12:10:06 +00:00
|
|
|
* LyX, The Document Processor
|
|
|
|
* Copyright 2001 The LyX Team.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
1999-11-15 10:54:16 +00:00
|
|
|
* ======================================================
|
1999-09-27 18:44:28 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
2000-02-03 17:09:33 +00:00
|
|
|
|
1999-12-13 00:05:34 +00:00
|
|
|
#include <fstream>
|
2001-05-29 09:50:02 +00:00
|
|
|
#include <iterator>
|
2001-06-01 12:10:06 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <boost/crc.hpp>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-01-17 21:01:30 +00:00
|
|
|
#include "support/lyxlib.h"
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
|
2001-06-01 12:10:06 +00:00
|
|
|
namespace {
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
template<typename InputIterator>
|
2001-03-20 01:22:46 +00:00
|
|
|
inline
|
2000-02-04 09:38:32 +00:00
|
|
|
unsigned long do_crc(InputIterator first, InputIterator last)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-06-01 12:10:06 +00:00
|
|
|
boost::crc_32_type crc;
|
|
|
|
crc = std::for_each(first, last, crc);
|
|
|
|
return crc.checksum();
|
2000-02-04 09:38:32 +00:00
|
|
|
}
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
} // namespace
|
|
|
|
|
2000-02-04 09:38:32 +00:00
|
|
|
|
|
|
|
// And this would be the file interface.
|
2000-10-20 13:13:38 +00:00
|
|
|
unsigned long lyx::sum(string const & file)
|
2000-02-04 09:38:32 +00:00
|
|
|
{
|
2001-05-30 13:17:50 +00:00
|
|
|
std::ifstream ifs(file.c_str());
|
|
|
|
if (!ifs) return 0;
|
2001-06-01 12:10:06 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_DECL_ISTREAMBUF_ITERATOR
|
|
|
|
// This is a lot faster...
|
2001-05-30 13:17:50 +00:00
|
|
|
std::istreambuf_iterator<char> beg(ifs);
|
|
|
|
std::istreambuf_iterator<char> end;
|
|
|
|
#else
|
2001-06-01 12:10:06 +00:00
|
|
|
// than this.
|
2001-05-30 13:17:50 +00:00
|
|
|
ifs.unsetf(std::ios::skipws);
|
|
|
|
std::istream_iterator<char> beg(ifs);
|
|
|
|
std::istream_iterator<char> end;
|
|
|
|
#endif
|
2001-06-01 12:10:06 +00:00
|
|
|
|
|
|
|
return do_crc(beg, end);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|