File: table_management.h

package info (click to toggle)
osm2pgrouting 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,036 kB
  • sloc: cpp: 3,754; python: 3,105; xml: 504; sh: 61; sql: 54; ansic: 46; makefile: 18
file content (161 lines) | stat: -rw-r--r-- 4,669 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*PGR-GNU*****************************************************************

 Copyright (c) 2017 pgRouting developers
 Mail: project@pgrouting.org

 ------
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
********************************************************************PGR-GNU*/

/** @file **/
#pragma once
#include <string>
#include "utilities/prog_options.h"

namespace osm2pgr {

class Table {
 public:
     Table() = default;
     Table(const Table &) = default;
     Table(
             const std::string &schema,
             const std::string &name,
             const std::string &full_name,

             const std::string &create_str,
             const std::string &other_columns,
             const std::string &geometry
          );

     void set_columns(const std::vector<std::string> &columns);

     /** @brief prefixNameSufix */
     inline std::string table_name() const {
         return m_full_name;
     }


     /** @brief schema.prefixNameSufix
      *
      * schema.prefixNameSufix
      * OR
      * prefixNameSufix
      *
      */
     std::string addSchema() const;
     std::string temp_name() const;
     std::string name() const {return m_name;};
     std::string full_name() const {return m_full_name;};

     /** sql queries
      */
     std::string primary_key(const std::string &column) const;
     std::string unique(const std::string &column) const;
     std::string foreign_key(
             const std::string &column,
             const Table &table,
             const std::string &table_column) const;
     std::string gist_index() const;

     inline std::vector<std::string> columns() const {
         return m_columns;
     }
     std::string sql(size_t i) const {return m_sql[i];}


     std::string tmp_create() const;
     std::string create() const;
     std::string drop() const;

     /* modifier */
     void add_sql(const string& sql) {
         m_sql.push_back(sql);
     }

 private:
     std::string m_name;
     std::string m_schema;
     std::string m_full_name;

     std::string m_create;
     std::string m_other_columns;
     std::string m_constraint;
     std::string m_geometry;
     std::vector<std::string> m_columns;

     /** aditional sqls (for pois) to keep code clean*/
     std::vector<std::string> m_sql;
};




class Tables {
    public:
        Tables(const po::variables_map &vm);

        const Table& get_table(const std::string &name) const {
            if (name == "osm_nodes") return osm_nodes();
            else if (name == "osm_ways") return osm_ways();
            else if (name == "osm_relations") return osm_relations();
            else if (name == "configuration") return configuration();
            else if (name == "pointsofinterest") return pois();
            else if (name == "ways") return ways();
            else return vertices();
        }

        std::string  post_process(const Table &table) const;



        po::variables_map m_vm;

    private:
        /*
         * Conpulsory tables
         */
        Table m_ways;
        Table m_ways_vertices_pgr;
        Table m_points_of_interest;
        Table m_configuration;

        /*
         * Optional tables
         */
        Table m_osm_nodes;
        Table m_osm_ways;
        Table m_osm_relations;

    public:
        const Table& ways() const {return m_ways;}
        const Table& vertices() const {return m_ways_vertices_pgr;}
        const Table& pois() const {return m_points_of_interest;}
        const Table& configuration() const {return m_configuration;}
        const Table& osm_nodes() const {return m_osm_nodes;}
        const Table& osm_ways() const {return m_osm_ways;}
        const Table& osm_relations() const {return m_osm_relations;}

    private:
        Table osm_nodes_config() const;
        Table pois_config() const;
        Table osm_ways_config() const;
        Table osm_relations_config() const;
        Table configuration_config() const;
        Table ways_config() const;
        Table ways_vertices_pgr_config() const;
};

}