forked from organicmaps/organicmaps
[indexer] DebugPrint for the feature's Metadata.
This commit is contained in:
parent
cd62f39d8f
commit
e4620f5124
2 changed files with 56 additions and 24 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
#include "std/target_os.hpp"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace feature
|
||||
|
@ -156,12 +158,10 @@ void RegionData::AddPublicHoliday(int8_t month, int8_t offset)
|
|||
value.push_back(offset);
|
||||
Set(RegionData::Type::RD_PUBLIC_HOLIDAYS, value);
|
||||
}
|
||||
} // namespace feature
|
||||
|
||||
// Warning: exact osm tag keys should be returned for valid enum values.
|
||||
string ToString(feature::Metadata::EType type)
|
||||
string ToString(Metadata::EType type)
|
||||
{
|
||||
using feature::Metadata;
|
||||
switch (type)
|
||||
{
|
||||
case Metadata::FMD_CUISINE: return "cuisine";
|
||||
|
@ -198,3 +198,26 @@ string ToString(feature::Metadata::EType type)
|
|||
|
||||
return string();
|
||||
}
|
||||
|
||||
string DebugPrint(Metadata const & metadata)
|
||||
{
|
||||
ostringstream oss;
|
||||
bool first = true;
|
||||
oss << "Metadata [";
|
||||
for (uint8_t i = 0; i < static_cast<uint8_t>(Metadata::FMD_COUNT); ++i)
|
||||
{
|
||||
auto const t = static_cast<Metadata::EType>(i);
|
||||
string s;
|
||||
if (metadata.Get(t, s))
|
||||
{
|
||||
if (!first)
|
||||
oss << "; ";
|
||||
first = false;
|
||||
|
||||
oss << DebugPrint(t) << "=" << s;
|
||||
}
|
||||
}
|
||||
oss << "]";
|
||||
return oss.str();
|
||||
}
|
||||
} // namespace feature
|
||||
|
|
|
@ -8,30 +8,10 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace feature
|
||||
{
|
||||
class MetadataBase
|
||||
{
|
||||
protected:
|
||||
// TODO: Change uint8_t to appropriate type when FMD_COUNT reaches 256.
|
||||
void Set(uint8_t type, std::string const & value)
|
||||
{
|
||||
auto found = m_metadata.find(type);
|
||||
if (found == m_metadata.end())
|
||||
{
|
||||
if (!value.empty())
|
||||
m_metadata[type] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value.empty())
|
||||
m_metadata.erase(found);
|
||||
else
|
||||
found->second = value;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
bool Has(uint8_t type) const
|
||||
{
|
||||
|
@ -45,6 +25,15 @@ public:
|
|||
return (it == m_metadata.end()) ? std::string() : it->second;
|
||||
}
|
||||
|
||||
bool Get(uint8_t type, std::string & value) const
|
||||
{
|
||||
auto const it = m_metadata.find(type);
|
||||
if (it == m_metadata.end())
|
||||
return false;
|
||||
value = it->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> GetPresentTypes() const
|
||||
{
|
||||
std::vector<uint8_t> types;
|
||||
|
@ -88,6 +77,24 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
// TODO: Change uint8_t to appropriate type when FMD_COUNT reaches 256.
|
||||
void Set(uint8_t type, std::string const & value)
|
||||
{
|
||||
auto found = m_metadata.find(type);
|
||||
if (found == m_metadata.end())
|
||||
{
|
||||
if (!value.empty())
|
||||
m_metadata[type] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value.empty())
|
||||
m_metadata.erase(found);
|
||||
else
|
||||
found->second = value;
|
||||
}
|
||||
}
|
||||
|
||||
std::map<uint8_t, std::string> m_metadata;
|
||||
};
|
||||
|
||||
|
@ -224,8 +231,10 @@ public:
|
|||
void AddPublicHoliday(int8_t month, int8_t offset);
|
||||
// No public holidays getters until we know what to do with these.
|
||||
};
|
||||
} // namespace feature
|
||||
|
||||
// Prints types in osm-friendly format.
|
||||
std::string ToString(feature::Metadata::EType type);
|
||||
inline std::string DebugPrint(feature::Metadata::EType type) { return ToString(type); }
|
||||
|
||||
std::string DebugPrint(feature::Metadata const & metadata);
|
||||
} // namespace feature
|
||||
|
|
Loading…
Add table
Reference in a new issue