2016-01-15 02:47:19 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-08-24 14:51:13 +00:00
|
|
|
#include <Poco/Util/AbstractConfiguration.h>
|
|
|
|
#include <Poco/Exception.h>
|
|
|
|
|
2017-04-16 05:40:17 +00:00
|
|
|
#include <common/Types.h>
|
2016-01-15 02:47:19 +00:00
|
|
|
|
2017-08-24 14:51:13 +00:00
|
|
|
#include <ext/singleton.h>
|
|
|
|
|
2016-01-15 02:47:19 +00:00
|
|
|
|
2017-04-17 11:56:55 +00:00
|
|
|
/** @brief Class that lets you know if a search engine or operating system belongs
|
|
|
|
* another search engine or operating system, respectively.
|
|
|
|
* Information about the hierarchy of regions is downloaded from the database.
|
2016-01-15 02:47:19 +00:00
|
|
|
*/
|
|
|
|
class TechDataHierarchy
|
|
|
|
{
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
UInt8 os_parent[256] {};
|
|
|
|
UInt8 se_parent[256] {};
|
2016-01-15 02:47:19 +00:00
|
|
|
|
|
|
|
public:
|
2017-12-01 20:21:35 +00:00
|
|
|
void reload();
|
2016-01-15 02:47:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Has corresponding section in configuration file.
|
2017-08-24 14:51:13 +00:00
|
|
|
static bool isConfigured(const Poco::Util::AbstractConfiguration & config);
|
2016-01-15 02:47:19 +00:00
|
|
|
|
|
|
|
|
2017-04-17 11:56:55 +00:00
|
|
|
/// The "belongs" relation.
|
2017-04-01 07:20:54 +00:00
|
|
|
bool isOSIn(UInt8 lhs, UInt8 rhs) const
|
|
|
|
{
|
|
|
|
while (lhs != rhs && os_parent[lhs])
|
|
|
|
lhs = os_parent[lhs];
|
2017-01-21 04:24:28 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return lhs == rhs;
|
|
|
|
}
|
2016-01-15 02:47:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool isSEIn(UInt8 lhs, UInt8 rhs) const
|
|
|
|
{
|
|
|
|
while (lhs != rhs && se_parent[lhs])
|
|
|
|
lhs = se_parent[lhs];
|
2016-01-15 02:47:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return lhs == rhs;
|
|
|
|
}
|
2017-01-21 04:24:28 +00:00
|
|
|
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
UInt8 OSToParent(UInt8 x) const
|
|
|
|
{
|
|
|
|
return os_parent[x];
|
|
|
|
}
|
2016-01-15 02:47:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
UInt8 SEToParent(UInt8 x) const
|
|
|
|
{
|
|
|
|
return se_parent[x];
|
|
|
|
}
|
2017-01-21 04:24:28 +00:00
|
|
|
|
2016-01-15 02:47:19 +00:00
|
|
|
|
2017-04-17 11:56:55 +00:00
|
|
|
/// To the topmost ancestor.
|
2017-04-01 07:20:54 +00:00
|
|
|
UInt8 OSToMostAncestor(UInt8 x) const
|
|
|
|
{
|
|
|
|
while (os_parent[x])
|
|
|
|
x = os_parent[x];
|
|
|
|
return x;
|
|
|
|
}
|
2016-01-15 02:47:19 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
UInt8 SEToMostAncestor(UInt8 x) const
|
|
|
|
{
|
|
|
|
while (se_parent[x])
|
|
|
|
x = se_parent[x];
|
|
|
|
return x;
|
|
|
|
}
|
2016-01-15 02:47:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-07-10 04:34:14 +00:00
|
|
|
class TechDataHierarchySingleton : public ext::singleton<TechDataHierarchySingleton>, public TechDataHierarchy {};
|