Names and formatting change in file_container.hpp

This commit is contained in:
Yury Melnichek 2011-01-04 16:26:24 +01:00 committed by Alex Zolotarev
parent 507694e4c1
commit f2871f3fd2
2 changed files with 20 additions and 23 deletions

View file

@ -44,8 +44,8 @@ FilesContainerR::FilesContainerR(string const & fName,
FileReader FilesContainerR::GetReader(Tag const & tag) const
{
info_cont_t::const_iterator i =
lower_bound(m_info.begin(), m_info.end(), tag, less_info());
InfoContainer::const_iterator i =
lower_bound(m_info.begin(), m_info.end(), tag, LessInfo());
if (i != m_info.end() && i->m_tag == tag)
return m_source.SubReader(i->m_offset, i->m_size);
@ -64,7 +64,7 @@ FilesContainerW::FilesContainerW(string const & fName, FileWriter::Op op)
{
FileReader reader(fName);
ReadInfo(reader);
m_needRewrite = true;
m_bNeedRewrite = true;
}
if (m_info.empty())
@ -72,7 +72,7 @@ FilesContainerW::FilesContainerW(string const & fName, FileWriter::Op op)
FileWriter writer(fName);
uint64_t skip = 0;
writer.Write(&skip, sizeof(skip));
m_needRewrite = false;
m_bNeedRewrite = false;
}
}
@ -94,9 +94,9 @@ uint64_t FilesContainerW::SaveCurrentSize()
FileWriter FilesContainerW::GetWriter(Tag const & tag)
{
ASSERT(!m_bFinished, ());
if (m_needRewrite)
if (m_bNeedRewrite)
{
m_needRewrite = false;
m_bNeedRewrite = false;
ASSERT ( !m_info.empty(), () );
uint64_t const curr = m_info.back().m_offset + m_info.back().m_size;
@ -153,7 +153,7 @@ void FilesContainerW::Finish()
WriteToSink(writer, curr);
}
sort(m_info.begin(), m_info.end(), less_info());
sort(m_info.begin(), m_info.end(), LessInfo());
FileWriter writer(m_name, FileWriter::OP_APPEND);

View file

@ -21,7 +21,7 @@ protected:
Info(Tag const & tag, uint64_t offset) : m_tag(tag), m_offset(offset) {}
};
struct less_info
struct LessInfo
{
bool operator() (Info const & t1, Info const & t2) const
{
@ -37,18 +37,14 @@ protected:
}
};
typedef vector<Info> info_cont_t;
info_cont_t m_info;
typedef vector<Info> InfoContainer;
InfoContainer m_info;
void ReadInfo(FileReader & reader);
};
class FilesContainerR : public FilesContainerBase
{
typedef FilesContainerBase base_type;
FileReader m_source;
public:
explicit FilesContainerR(string const & fName,
uint32_t logPageSize = 10,
@ -61,19 +57,13 @@ public:
for (size_t i = 0; i < m_info.size(); ++i)
f(m_info[i].m_tag);
}
private:
FileReader m_source;
};
class FilesContainerW : public FilesContainerBase
{
typedef FilesContainerBase base_type;
string m_name;
uint64_t SaveCurrentSize();
bool m_needRewrite;
bool m_bFinished;
public:
FilesContainerW(string const & fName,
FileWriter::Op op = FileWriter::OP_WRITE_TRUNCATE);
@ -85,4 +75,11 @@ public:
void Append(vector<char> const & buffer, Tag const & tag);
void Finish();
private:
uint64_t SaveCurrentSize();
string m_name;
bool m_bNeedRewrite;
bool m_bFinished;
};