minor refactor
This commit is contained in:
parent
00bc940cff
commit
340774d8f6
20 changed files with 103 additions and 98 deletions
14
src/CMakeLists.txt
Normal file
14
src/CMakeLists.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
add_library(osmparser STATIC
|
||||
"osmimember.cpp"
|
||||
"osmnode.cpp"
|
||||
"osmobject.cpp"
|
||||
"osmrelation.cpp"
|
||||
"osmway.cpp"
|
||||
"util.cpp"
|
||||
)
|
||||
|
||||
target_link_libraries(osmparser PUBLIC
|
||||
tinyxml2
|
||||
)
|
|
@ -1,6 +1,6 @@
|
|||
#include <osmimember.hpp>
|
||||
#include "osmimember.hpp"
|
||||
|
||||
#include <osmobject.hpp>
|
||||
#include "osmobject.hpp"
|
||||
#include <tinyxml2.h>
|
||||
|
||||
namespace xml = tinyxml2;
|
||||
|
|
50
src/osmimember.hpp
Normal file
50
src/osmimember.hpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
#include "util.hpp"
|
||||
#include "osmtag.hpp"
|
||||
|
||||
namespace osmp
|
||||
{
|
||||
class Object;
|
||||
|
||||
class IMember
|
||||
{
|
||||
public:
|
||||
enum class Type {
|
||||
NODE, WAY, RELATION
|
||||
};
|
||||
|
||||
public:
|
||||
IMember(const IMember& other) = delete;
|
||||
virtual ~IMember() {}
|
||||
|
||||
IMember::Type GetType() const;
|
||||
|
||||
const TagList& GetTags() const;
|
||||
size_t GetTagsSize() const;
|
||||
const Tag& GetTag(size_t index) const;
|
||||
std::string GetTag(const std::string& key) const;
|
||||
|
||||
protected:
|
||||
IMember(const tinyxml2::XMLElement* element, Object* parent, IMember::Type type);
|
||||
|
||||
protected:
|
||||
IMember::Type type;
|
||||
Object* parent;
|
||||
|
||||
TagList tags;
|
||||
|
||||
public:
|
||||
uint64_t id;
|
||||
std::string user;
|
||||
unsigned int uid;
|
||||
bool visible;
|
||||
std::string version;
|
||||
unsigned int changeset;
|
||||
std::string timestamp;
|
||||
};
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
#include <osmnode.hpp>
|
||||
#include "osmnode.hpp"
|
||||
|
||||
#include <tinyxml2.h>
|
||||
|
||||
|
|
30
src/osmnode.hpp
Normal file
30
src/osmnode.hpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
#pragma once
|
||||
#include <vector>
|
||||
|
||||
#include "util.hpp"
|
||||
#include "osmimember.hpp"
|
||||
#include "osmtag.hpp"
|
||||
|
||||
namespace osmp
|
||||
{
|
||||
class Object;
|
||||
|
||||
class INode : public IMember
|
||||
{
|
||||
public:
|
||||
INode(const INode& other) = delete;
|
||||
INode(const INode&& other) = delete;
|
||||
virtual ~INode() {}
|
||||
|
||||
friend Node CreateNode(const tinyxml2::XMLElement* element, Object* parent);
|
||||
|
||||
double GetLat() const { return lat; }
|
||||
double GetLon() const { return lon; }
|
||||
|
||||
protected:
|
||||
INode(const tinyxml2::XMLElement* xml, Object* parent);
|
||||
|
||||
public:
|
||||
double lat, lon;
|
||||
};
|
||||
}
|
|
@ -1,13 +1,13 @@
|
|||
#include <osmobject.hpp>
|
||||
#include "osmobject.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <tinyxml2.h>
|
||||
|
||||
#include <osmnode.hpp>
|
||||
#include <osmway.hpp>
|
||||
#include <osmrelation.hpp>
|
||||
#include "osmnode.hpp"
|
||||
#include "osmway.hpp"
|
||||
#include "osmrelation.hpp"
|
||||
|
||||
namespace xml = tinyxml2;
|
||||
|
||||
|
|
40
src/osmobject.hpp
Normal file
40
src/osmobject.hpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
#pragma once
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "util.hpp"
|
||||
|
||||
namespace osmp
|
||||
{
|
||||
class Object
|
||||
{
|
||||
public:
|
||||
explicit Object(const std::string& file);
|
||||
~Object();
|
||||
|
||||
Nodes GetNodes() const;
|
||||
size_t GetNodesSize() const;
|
||||
Node GetNode(uint64_t id) const;
|
||||
|
||||
Ways GetWays() const;
|
||||
size_t GetWaysSize() const;
|
||||
Way GetWay(uint64_t id) const;
|
||||
|
||||
Relations GetRelations() const;
|
||||
size_t GetRelationsSize() const;
|
||||
Relation GetRelation(uint64_t id) const;
|
||||
|
||||
public:
|
||||
const std::string version;
|
||||
const std::string generator;
|
||||
|
||||
Bounds bounds;
|
||||
|
||||
private:
|
||||
std::map<uint64_t, Node> nodes;
|
||||
std::map<uint64_t, Way> ways;
|
||||
std::map<uint64_t, Relation> relations;
|
||||
};
|
||||
}
|
8
src/osmp.hpp
Normal file
8
src/osmp.hpp
Normal file
|
@ -0,0 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <osmobject.hpp>
|
||||
#include <osmnode.hpp>
|
||||
#include <osmway.hpp>
|
||||
#include <osmtag.hpp>
|
||||
#include <osmrelation.hpp>
|
||||
#include <osmimember.hpp>
|
|
@ -1,12 +1,12 @@
|
|||
#include "..\include\osmrelation.hpp"
|
||||
#include <osmrelation.hpp>
|
||||
#include "osmrelation.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <tinyxml2.h>
|
||||
#include <osmobject.hpp>
|
||||
#include <osmnode.hpp>
|
||||
#include <osmway.hpp>
|
||||
|
||||
#include "osmobject.hpp"
|
||||
#include "osmnode.hpp"
|
||||
#include "osmway.hpp"
|
||||
|
||||
namespace xml = tinyxml2;
|
||||
|
||||
|
|
58
src/osmrelation.hpp
Normal file
58
src/osmrelation.hpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
#pragma once
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "util.hpp"
|
||||
#include "osmtag.hpp"
|
||||
#include "osmimember.hpp"
|
||||
|
||||
namespace osmp
|
||||
{
|
||||
class Object;
|
||||
class IMember;
|
||||
|
||||
typedef struct sMemberNode {
|
||||
Node node;
|
||||
std::string role;
|
||||
} MemberNode;
|
||||
|
||||
typedef struct sMemberWay {
|
||||
Way way;
|
||||
std::string role;
|
||||
} MemberWay;
|
||||
|
||||
typedef std::vector<MemberNode> MemberNodes;
|
||||
typedef std::vector<MemberWay> MemberWays;
|
||||
|
||||
class IRelation : public IMember
|
||||
{
|
||||
public:
|
||||
IRelation(const IRelation& other) = delete;
|
||||
IRelation(const IRelation&& other) = delete;
|
||||
virtual ~IRelation() {}
|
||||
|
||||
friend Relation CreateRelation(const tinyxml2::XMLElement* xml, Object* parent);
|
||||
|
||||
[[nodiscard]] std::string GetRelationType() const;
|
||||
|
||||
[[nodiscard]] const MemberNodes& GetNodes() const;
|
||||
[[nodiscard]] size_t GetNodesSize() const;
|
||||
[[nodiscard]] const MemberNode& GetNode(size_t index) const;
|
||||
|
||||
[[nodiscard]] const MemberWays& GetWays() const;
|
||||
[[nodiscard]] size_t GetWaysSize() const;
|
||||
[[nodiscard]] const MemberWay& GetWay(size_t index) const;
|
||||
|
||||
[[nodiscard]] bool HasNullMembers() const { return hasNullMembers; }
|
||||
|
||||
protected:
|
||||
IRelation(const tinyxml2::XMLElement* xml, Object* parent);
|
||||
|
||||
private:
|
||||
std::string relationType;
|
||||
bool hasNullMembers;
|
||||
|
||||
MemberNodes nodes;
|
||||
MemberWays ways;
|
||||
};
|
||||
}
|
38
src/osmtag.hpp
Normal file
38
src/osmtag.hpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace osmp
|
||||
{
|
||||
enum class TagKey {
|
||||
NONE,
|
||||
AERIALWAY, AEROWAY, AMENITY, BARRIER, BOUNDARY,
|
||||
BUILDING, CRAFT, EMERGENCY, GEOLOGICAL, HEALTHCARE,
|
||||
HIGHWAY, HISTORIC, LANDUSE, LEISURE, MANMADE, MILITARY,
|
||||
NATURAL, OFFICE, PLACE, POWER, PUBLIC_TRANSPORT,
|
||||
RAILWAY, ROUTE, SHOP, SPORT, TELECOM, TOURISM, WATER, WATERWAY
|
||||
};
|
||||
|
||||
/*
|
||||
enum class TagValue {
|
||||
NONE,
|
||||
|
||||
BUILDING_APARTMENTS, BUILDING_BUNGALOW, BUILDING_CABIN, BUILDING_DETACHED, BUILDING_DORMITORY, BUILDING_FARM, BUILDING_GER,
|
||||
BUILDING_HOTEL, BUILDING_HOUSE, BUILDING_HOUSEBOAT, BUILDING_RESIDENTIAL, BUILDING_SEMIDETACHED_HOUSE, BUILDING_STATIC_CARAVAN,
|
||||
BUILDING_TERRACE, BUILDING_COMMERCIAL, BUILDING_INDUSTRIAL, BUILDING_KIOSK, BUILDING_OFFICE, BUILDING_RETAIL, BUILDING_SUPERMARKET,
|
||||
BUILDING_WAREHOUSE, BUILDING_CATHEDRAL, BUILDING_CHAPEL, BUILDING_CHURCH, BUILDING_MONASTERY, BUILDING_MOSQUE, BUILDING_PRESBYTERY,
|
||||
BUILDING_RELIGIOUS, BUILDING_SHRINE, BUILDING_SYNAGOGUE, BUILDING_TEMPLE, BUILDING_BAKEHOUSE, BUILDING_CIVIC, BUILDING_FIRE_STATION,
|
||||
BUILDING_GOVERNMENT, BUILDING_HOSPITAL, BUILDING_PUBLIC, BUILDING_TOILETS, BUILDING_TRAIN_STATION, BUILDING_TRANSPORTATION,
|
||||
BUILDING_KINDERGARTEN, BUILDING_SCHOOL, BUILDING_UNIVERSITY
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
typedef struct sTag
|
||||
{
|
||||
std::string k; // TODO: Should/could be an enum
|
||||
std::string v;
|
||||
} Tag;
|
||||
|
||||
typedef std::vector<Tag> TagList;
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
#include <osmway.hpp>
|
||||
#include "osmway.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <tinyxml2.h>
|
||||
#include <osmobject.hpp>
|
||||
#include <osmtag.hpp>
|
||||
|
||||
#include "osmobject.hpp"
|
||||
#include "osmtag.hpp"
|
||||
|
||||
namespace xml = tinyxml2;
|
||||
|
||||
|
|
35
src/osmway.hpp
Normal file
35
src/osmway.hpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#pragma once
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
#include "util.hpp"
|
||||
#include "osmtag.hpp"
|
||||
#include "osmimember.hpp"
|
||||
|
||||
namespace osmp
|
||||
{
|
||||
class Object;
|
||||
|
||||
class IWay : public IMember
|
||||
{
|
||||
public:
|
||||
IWay(const IWay& other) = delete;
|
||||
IWay(const IWay&& other) = delete;
|
||||
virtual ~IWay() {}
|
||||
|
||||
friend Way CreateWay(const tinyxml2::XMLElement* way_elem, Object* parent);
|
||||
|
||||
const Nodes& GetNodes() const;
|
||||
size_t GetNodesSize() const;
|
||||
Node GetNode(size_t index) const;
|
||||
|
||||
protected:
|
||||
IWay(const tinyxml2::XMLElement* way_elem, Object* parent);
|
||||
|
||||
public:
|
||||
bool area, closed; // Closed := Startpoint = endpoint, Area := Closed AND certain conditions are not met
|
||||
|
||||
private:
|
||||
Nodes nodes;
|
||||
};
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
#include <util.hpp>
|
||||
#include "util.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <tinyxml2.h>
|
||||
|
|
35
src/util.hpp
Normal file
35
src/util.hpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace tinyxml2
|
||||
{
|
||||
class XMLElement;
|
||||
}
|
||||
|
||||
namespace osmp
|
||||
{
|
||||
class INode;
|
||||
class IWay;
|
||||
class IRelation;
|
||||
|
||||
typedef std::shared_ptr<INode> Node;
|
||||
typedef std::shared_ptr<IWay> Way;
|
||||
typedef std::shared_ptr<IRelation> Relation;
|
||||
|
||||
typedef std::vector<Node> Nodes;
|
||||
typedef std::vector<Way> Ways;
|
||||
typedef std::vector<Relation> Relations;
|
||||
|
||||
typedef struct sBounds
|
||||
{
|
||||
double minlat, minlon, maxlat, maxlon;
|
||||
} Bounds;
|
||||
|
||||
[[nodiscard]] std::string GetSafeAttributeString(const tinyxml2::XMLElement* elem, const std::string& name);
|
||||
[[nodiscard]] double GetSafeAttributeFloat(const tinyxml2::XMLElement* elem, const std::string& name);
|
||||
[[nodiscard]] uint64_t GetSafeAttributeUint64(const tinyxml2::XMLElement* elem, const std::string& name);
|
||||
[[nodiscard]] bool GetSafeAttributeBool(const tinyxml2::XMLElement* elem, const std::string& name);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue