forked from organicmaps/organicmaps
- Fix error with FilesContainerW append mode.
This commit is contained in:
parent
4ea9e2e045
commit
1255968f94
2 changed files with 31 additions and 3 deletions
|
@ -81,6 +81,9 @@ FilesContainerW::FilesContainerW(string const & fName, FileWriter::Op op)
|
|||
// read an existing service info
|
||||
FileReader reader(fName);
|
||||
ReadInfo(reader);
|
||||
|
||||
// Important: in append mode we should sort info-vector by offsets
|
||||
sort(m_info.begin(), m_info.end(), LessOffset());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,10 +137,9 @@ FileWriter FilesContainerW::GetWriter(Tag const & tag)
|
|||
|
||||
FileWriter FilesContainerW::GetExistingWriter(Tag const & tag)
|
||||
{
|
||||
InfoContainer::const_iterator i =
|
||||
lower_bound(m_info.begin(), m_info.end(), tag, LessInfo());
|
||||
InfoContainer::const_iterator i = find_if(m_info.begin(), m_info.end(), EqualTag(tag));
|
||||
|
||||
if (i != m_info.end() && i->m_tag == tag)
|
||||
if (i != m_info.end())
|
||||
{
|
||||
FileWriter writer(m_name, FileWriter::OP_WRITE_EXISTING);
|
||||
writer.Seek(i->m_offset);
|
||||
|
|
|
@ -36,6 +36,32 @@ protected:
|
|||
return (t1 < t2.m_tag);
|
||||
}
|
||||
};
|
||||
struct LessOffset
|
||||
{
|
||||
bool operator() (Info const & t1, Info const & t2) const
|
||||
{
|
||||
return (t1.m_offset < t2.m_offset);
|
||||
}
|
||||
bool operator() (Info const & t1, uint64_t const & t2) const
|
||||
{
|
||||
return (t1.m_offset < t2);
|
||||
}
|
||||
bool operator() (uint64_t const & t1, Info const & t2) const
|
||||
{
|
||||
return (t1 < t2.m_offset);
|
||||
}
|
||||
};
|
||||
class EqualTag
|
||||
{
|
||||
Tag const & m_tag;
|
||||
public:
|
||||
EqualTag(Tag const & tag) : m_tag(tag) {}
|
||||
bool operator() (Info const & t) const
|
||||
{
|
||||
return (t.m_tag == m_tag);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
typedef vector<Info> InfoContainer;
|
||||
InfoContainer m_info;
|
||||
|
|
Loading…
Add table
Reference in a new issue