Fixed notes

This commit is contained in:
Constantin Shalnev 2015-12-10 14:26:36 +03:00
parent d8e7c937b8
commit c32a74bf27
4 changed files with 13 additions and 18 deletions

View file

@ -207,8 +207,7 @@ void GpsTrack::InitCollection(hours duration)
try
{
// Get all data from the file
m_file->ForEach(0 /* timestampSince */ , [this](TItem const & info)->bool
m_file->ForEach([this](TItem const & info)->bool
{
pair<size_t, size_t> evictedIds;
m_collection->Add(info, evictedIds);

View file

@ -92,7 +92,7 @@ void GpsTrackFile::Append(vector<TItem> const & items)
{
ASSERT(m_stream.is_open(), ());
bool const needTrunc = (m_itemCount + items.size()) > (m_maxItemCount * 2); // see NOTE in class declaration
bool const needTrunc = (m_itemCount + items.size()) > (m_maxItemCount * 2); // see NOTE in declaration
if (needTrunc)
TruncFile();
@ -121,7 +121,7 @@ void GpsTrackFile::Clear()
ASSERT_EQUAL(m_stream.tellp(), 0, ());
}
void GpsTrackFile::ForEach(double timestampSince, std::function<bool(TItem const & item)> const & fn)
void GpsTrackFile::ForEach(std::function<bool(TItem const & item)> const & fn)
{
ASSERT(m_stream.is_open(), ());
@ -139,11 +139,8 @@ void GpsTrackFile::ForEach(double timestampSince, std::function<bool(TItem const
if (0 != (m_stream.rdstate() & (ios::failbit | ios::badbit | ios::eofbit)))
MYTHROW(ReadFileException, ("File:", m_filePath));
if (item.m_timestamp >= timestampSince)
{
if (!fn(item))
break;
}
if (!fn(item))
break;
}
}
@ -153,7 +150,7 @@ void GpsTrackFile::TruncFile()
fstream tmp = fstream(tmpFilePath, ios::in|ios::out|ios::binary|ios::trunc);
if (!tmp)
MYTHROW(WriteFileException, ("File:", m_filePath));
MYTHROW(WriteFileException, ("Unable to create temporary file:", m_filePath));
size_t i = GetFirstItemIndex();
@ -196,5 +193,5 @@ void GpsTrackFile::TruncFile()
size_t GpsTrackFile::GetFirstItemIndex() const
{
return (m_itemCount > m_maxItemCount) ? (m_itemCount - m_maxItemCount) : 0; // see NOTE in class declaration
return (m_itemCount > m_maxItemCount) ? (m_itemCount - m_maxItemCount) : 0; // see NOTE in declaration
}

View file

@ -55,9 +55,8 @@ public:
/// Reads file and calls functor for each item with timestamp not earlier than specified
/// @param fn - callable function, return true to stop ForEach
/// @param timestampSince - timestamp to read data since
/// @exceptions ReadFileException if read fails.
void ForEach(double timestampSince, std::function<bool(TItem const & item)> const & fn);
void ForEach(std::function<bool(TItem const & item)> const & fn);
private:
void TruncFile();

View file

@ -59,7 +59,7 @@ UNIT_TEST(GpsTrackFile_WriteReadWithoutTrunc)
file.Append(points);
size_t i = 0;
file.ForEach(0, [&](location::GpsTrackInfo const & point)->bool
file.ForEach([&](location::GpsTrackInfo const & point)->bool
{
TEST_EQUAL(point.m_latitude, points[i].m_latitude, ());
TEST_EQUAL(point.m_longitude, points[i].m_longitude, ());
@ -81,7 +81,7 @@ UNIT_TEST(GpsTrackFile_WriteReadWithoutTrunc)
TEST(file.IsOpen(), ());
size_t i = 0;
file.ForEach(0, [&](location::GpsTrackInfo const & point)->bool
file.ForEach([&](location::GpsTrackInfo const & point)->bool
{
TEST_EQUAL(point.m_latitude, points[i].m_latitude, ());
TEST_EQUAL(point.m_longitude, points[i].m_longitude, ());
@ -106,7 +106,7 @@ UNIT_TEST(GpsTrackFile_WriteReadWithoutTrunc)
TEST(file.IsOpen(), ());
size_t i = 0;
file.ForEach(0, [&](location::GpsTrackInfo const & point)->bool{ ++i; return true; });
file.ForEach([&](location::GpsTrackInfo const & point)->bool{ ++i; return true; });
TEST_EQUAL(i, 0, ());
file.Close();
@ -182,7 +182,7 @@ UNIT_TEST(GpsTrackFile_WriteReadWithTrunc)
TEST(file.IsOpen(), ());
size_t i = 0;
file.ForEach(0, [&](location::GpsTrackInfo const & point)->bool
file.ForEach([&](location::GpsTrackInfo const & point)->bool
{
if (i < fileMaxItemCount/2)
{
@ -217,7 +217,7 @@ UNIT_TEST(GpsTrackFile_WriteReadWithTrunc)
TEST(file.IsOpen(), ());
size_t i = 0;
file.ForEach(0, [&](location::GpsTrackInfo const & point)->bool{ ++i; return true; });
file.ForEach([&](location::GpsTrackInfo const & point)->bool{ ++i; return true; });
TEST_EQUAL(i, 0, ());
file.Close();