database.h 1.64 KB
Newer Older
jben's avatar
jben committed
1 2 3 4 5 6 7 8 9 10 11 12
#ifndef H_ROUTAGE_DATABASE
#define H_ROUTAGE_DATABASE 1

#include <pqxx/pqxx>
#include <string>
#include <iomanip>
#include <sstream>
#include <stdlib.h>
#include <stdio.h>
#include <list>
#include <math.h>
#include "node.h"
jben's avatar
jben committed
13 14
#include "model.h"
#include "instant.h"
jben's avatar
jben committed
15
#include <unistd.h>
jben's avatar
jben committed
16 17 18 19 20 21 22 23

#define PREC(N) std::setiosflags(std::ios::fixed) << std::setprecision(N) <<

class database
{
    public:

    pqxx::connection db;
jben's avatar
jben committed
24
    pqxx::read_transaction txn;
jben's avatar
jben committed
25
    unsigned int jid;
jben's avatar
jben committed
26 27
    
    pqxx::connection dbw;
jben's avatar
jben committed
28

jben's avatar
jben committed
29
    database(const std::string & s_filename,unsigned int jid_i) : db(s_filename),txn(db),dbw(s_filename),jid(jid_i) {
Jean-Benoist Leger's avatar
Jean-Benoist Leger committed
30 31
        db.prepare("get_node","SELECT ST_X(geom),ST_Y(geom),height FROM rv_nodes WHERE id=$1;");
        db.prepare("get_adj","SELECT to_id FROM rv_edges WHERE from_id=$1;");
jben's avatar
jben committed
32
    }
jben's avatar
jben committed
33 34 35


    node get_node(const unsigned long long & ull_id);
jben's avatar
jben committed
36
    std::pair<unsigned long long, unsigned int> get_edge(const unsigned long long & ull_from, const unsigned long long & ull_to);
jben's avatar
jben committed
37 38 39 40 41 42 43
    std::list<unsigned long long> get_adjoining(const unsigned long long & ull_id);


    double get_height_s(const int & lon_s, const int & lat_s);

    double get_height(const double & lon, const double & lat);

jben's avatar
jben committed
44 45
    bool find_one_node(std::pair<double,double> P, bool respect_cc, unsigned long long ull_cc, unsigned long long & ull_result_id, unsigned long long & ull_result_cc, double & dist);

jben's avatar
jben committed
46
    bool find_nodes(std::list<unsigned long long> &);
jben's avatar
jben committed
47

jben's avatar
jben committed
48
    model get_model();
jben's avatar
jben committed
49

jben's avatar
jben committed
50 51 52
    unsigned int get_state();
    void write_state(unsigned int state);
    void write_status(double status);
jben's avatar
jben committed
53

jben's avatar
jben committed
54 55
    void write_results(std::list<instant> lI, double puissance);
    void write_pid();
jben's avatar
jben committed
56

jben's avatar
jben committed
57

jben's avatar
jben committed
58 59 60
};

#endif