mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 05:13:58 +00:00
Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run: git remote add om-historic [om-historic.git repo url] git fetch --tags om-historic git replace squashed-history historic-commits
This commit is contained in:
66
indexer/types_mapping.cpp
Normal file
66
indexer/types_mapping.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include "indexer/types_mapping.hpp"
|
||||
#include "indexer/classificator.hpp"
|
||||
|
||||
#include "base/stl_helpers.hpp"
|
||||
#include "base/string_utils.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
void IndexAndTypeMapping::Clear()
|
||||
{
|
||||
m_types.clear();
|
||||
m_map.clear();
|
||||
}
|
||||
|
||||
void IndexAndTypeMapping::Load(istream & s)
|
||||
{
|
||||
Classificator const & c = classif();
|
||||
|
||||
string line;
|
||||
vector<string_view> path;
|
||||
|
||||
uint32_t ind = 0;
|
||||
while (s.good())
|
||||
{
|
||||
line.clear();
|
||||
s >> line;
|
||||
|
||||
if (!line.empty())
|
||||
{
|
||||
std::string_view v = line;
|
||||
|
||||
// Types can be deprecated with replacement, for deprecated type we have replacing type
|
||||
// in types.txt. We should use only main type for type index to ensure stable indices.
|
||||
// Main type description starts with '*' in types.txt.
|
||||
auto const isMainTypeDescription = (v[0] == '*');
|
||||
if (isMainTypeDescription)
|
||||
{
|
||||
v = v.substr(1);
|
||||
CHECK(!v.empty(), (ind));
|
||||
}
|
||||
|
||||
Add(ind++, c.GetTypeByPath(strings::Tokenize(v, "|")), isMainTypeDescription);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void IndexAndTypeMapping::Add(uint32_t ind, uint32_t type, bool isMainTypeDescription)
|
||||
{
|
||||
ASSERT_EQUAL ( ind, m_types.size(), () );
|
||||
|
||||
m_types.push_back(type);
|
||||
if (isMainTypeDescription)
|
||||
{
|
||||
auto const res = m_map.insert(make_pair(type, ind));
|
||||
CHECK(res.second, ("Type can have only one main description.", ind, m_map[ind]));
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t IndexAndTypeMapping::GetIndex(uint32_t t) const
|
||||
{
|
||||
Map::const_iterator i = m_map.find(t);
|
||||
/// @todo Should review each call of Classificator::GetIndexForType (see also IsTypeValid),
|
||||
/// because this situation is possible for deleted dummy types in old maps data.
|
||||
CHECK(i != m_map.end(), (t, classif().GetFullObjectName(t)));
|
||||
return i->second;
|
||||
}
|
||||
Reference in New Issue
Block a user