ошибка: нет соответствующей функции для вызова «get (long unsigned int*&, long unsigned int&)» с union_set

Этот код

table_edges[ this_relationship ] = boost::add_edge(
    table_vertices[ string( foreign_keys[i]["parent_table"].c_str() ) ], 
    table_vertices[ string( foreign_keys[i]["child_table"].c_str() ) ], 
    this_relationship, 
    rg
).first;
ds.union_set( 
    table_vertices[ string( foreign_keys[i]["parent_table"].c_str() ) ],
    table_vertices[ string( foreign_keys[i]["child_table"].c_str() ) ] 
);

дает эту ошибку и многие другие, касающиеся get

/usr/include/boost/pending/detail/disjoint_sets.hpp:59:33: ошибка: нет соответствующей функции для вызова ‘get(long unsigned int*&, long unsigned int&)’

Я использую связанные свойства.

typedef boost::adjacency_list < 
   boost::vecS, 
   boost::vecS, 
   boost::undirectedS, 
   string, 
   foreign_key_relationship  
> relational_graph;

Определения рангов и родительских типов объявляются глобально.

Как можно решить эту ошибку?


struct foreign_key_relationship{
    string parent_table;
    string parent_column;
    string child_table;
    string child_column;

    foreign_key_relationship(){}

    foreign_key_relationship( string pt, string pc, string ct, string cc ) : parent_table( pt ), parent_column( pc ), child_table( ct ), child_column( cc ) {}

};

inline bool operator==(const foreign_key_relationship& lhs, const foreign_key_relationship& rhs)
{
    return 
        lhs.parent_table == rhs.parent_table 
        && lhs.parent_column == rhs.parent_column 
        && lhs.child_table == rhs.child_table 
        && lhs.child_column == rhs.child_column 
    ;
}

inline bool operator<(const foreign_key_relationship& lhs, const foreign_key_relationship& rhs)
{
    return 
        lhs.parent_table < rhs.parent_table 
        && lhs.parent_column < rhs.parent_column 
        && lhs.child_table < rhs.child_table 
        && lhs.child_column < rhs.child_column 
    ;
}

typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS, string, foreign_key_relationship  > relational_graph;
typedef boost::graph_traits<relational_graph>::vertex_descriptor relational_vertex;
typedef boost::graph_traits<relational_graph>::vertices_size_type relational_vertex_index;
typedef boost::graph_traits<relational_graph>::edge_descriptor relational_edge;
typedef relational_vertex_index* relational_rank;
typedef relational_vertex* relational_parent;

void libpqxx_error( const pqxx_exception &e ){
    cerr << "*** Caught pqxx_exception:\n";
    cerr << e.base().what() << "\n";
    const sql_error *s=dynamic_cast<const sql_error*>(&e.base());
    if (s) std::cerr << "Query was: " << s->query() << "\n";
}

void connect_relational_vertices( map< foreign_key_relationship, relational_edge > &table_edges, result &foreign_keys, set<string> &tables_to_connect, map< string, relational_vertex > &table_vertices, relational_graph &rg, boost::disjoint_sets<relational_rank, relational_parent> &ds ){
    for( unsigned i=0; i<foreign_keys.size(); i++ ){
        foreign_key_relationship this_relationship(
            foreign_keys[i]["parent_table"].c_str(),
            foreign_keys[i]["parent_column"].c_str(),
            foreign_keys[i]["child_table"].c_str(),
            foreign_keys[i]["child_column"].c_str()
        );
        if( !table_edges.count( this_relationship ) && tables_to_connect.count( foreign_keys[i]["parent_table"].c_str() ) && tables_to_connect.count( foreign_keys[i]["child_table"].c_str() ) ){
            table_edges[ this_relationship ] = boost::add_edge(
                table_vertices[ string( foreign_keys[i]["parent_table"].c_str() ) ], 
                table_vertices[ string( foreign_keys[i]["child_table"].c_str() ) ], 
                this_relationship, 
                rg
            ).first;
            ds.union_set( table_vertices[ string( foreign_keys[i]["parent_table"].c_str() ) ], table_vertices[ string( foreign_keys[i]["child_table"].c_str() ) ] );
        }
    }
}

void add_possible_linking_vertex( result &foreign_keys, map< string, relational_vertex > &table_vertices, relational_graph &rg ){
    for( unsigned i=0; i<foreign_keys.size(); i++ ){
        if( !table_vertices.count( foreign_keys[i]["parent_table"].c_str() ) ){
            table_vertices[ foreign_keys[i]["parent_table"].c_str() ] = boost::add_vertex( foreign_keys[i]["parent_table"].c_str(), rg );
            break;
        }
        if( foreign_keys[i]["child_table"].c_str() ){
            table_vertices[ foreign_keys[i]["child_table"].c_str() ] = boost::add_vertex( foreign_keys[i]["child_table"].c_str(), rg );
            break;
        }
    }
}    

set< foreign_key_relationship > get_foreign_keys( transaction_base &t, set<string> tables_to_connect ){
    try{
        result foreign_keys = t.prepared("get_foreign_keys").exec();

        set< foreign_key_relationship > relational_routes;

        if( tables_to_connect.size() ){

            relational_graph rg;

            map< string, relational_vertex > table_vertices;
            for( string table: tables_to_connect )
                table_vertices[ table ] = boost::add_vertex( table, rg );

            std::vector<relational_vertex_index> rank( num_vertices(rg) );
            std::vector<relational_vertex> parent( num_vertices(rg) );

            boost::disjoint_sets<relational_rank, relational_parent> ds(&rank[0], &parent[0]);

            boost::initialize_incremental_components(rg, ds);
            boost::incremental_components(rg, ds);

            map< foreign_key_relationship, relational_edge > table_edges;
            for( unsigned i=0; i<foreign_keys.size(); i++ )
                connect_relational_vertices( table_edges, foreign_keys, tables_to_connect, table_vertices, rg, ds );

        }

        return relational_routes;
    }
    catch( const pqxx_exception &e ){
        libpqxx_error( e );
        set< foreign_key_relationship > relational_routes;
        return relational_routes;
    }
}

Я использую libpqxx, и запрос на поиск всех отношений внешнего ключа: set-of-potentially-gapped-ta">здесь.


person Community    schedule 06.10.2014    source источник
comment
Вы не показываете достаточно релевантного кода. Пожалуйста, уменьшите до SSCCE   -  person sehe    schedule 07.10.2014
comment
@sehe Пожалуйста, дайте мне знать, если этого недостаточно.   -  person    schedule 07.10.2014


Ответы (1)


Я только что потратил ~ 15 минут, чтобы добавить недостающие биты в пример кода. Я собирался отредактировать вопрос и оставить комментарий: «К сожалению, у меня не хватило времени, чтобы посмотреть на ваш настоящий вопрос».

Однако потом мне пришло в голову, что на самом деле вопрос был «почему он не компилируется»?

Что ж, тогда он компилируется для меня, так что, может быть, это поможет вам понять, что, тем не менее, отличается?

#include <boost/graph/use_mpi.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/distributed/dehne_gotz_min_spanning_tree.hpp>
#include <boost/graph/incremental_components.hpp>
#include <iostream>
#include <pqxx/except.hxx>
#include <pqxx/transaction_base.hxx>
#include <set>
#include <map>
#include <string>

using std::string;
using std::set;
using std::map;
using namespace pqxx;

struct foreign_key_relationship{
    string parent_table;
    string parent_column;
    string child_table;
    string child_column;

    foreign_key_relationship(){}

    foreign_key_relationship( string pt, string pc, string ct, string cc ) : parent_table( pt ), parent_column( pc ), child_table( ct ), child_column( cc ) {}

};

inline bool operator==(const foreign_key_relationship& lhs, const foreign_key_relationship& rhs)
{
    return 
        lhs.parent_table == rhs.parent_table 
        && lhs.parent_column == rhs.parent_column 
        && lhs.child_table == rhs.child_table 
        && lhs.child_column == rhs.child_column 
    ;
}

inline bool operator<(const foreign_key_relationship& lhs, const foreign_key_relationship& rhs)
{
    return 
        lhs.parent_table < rhs.parent_table 
        && lhs.parent_column < rhs.parent_column 
        && lhs.child_table < rhs.child_table 
        && lhs.child_column < rhs.child_column 
    ;
}

typedef boost::adjacency_list < boost::vecS, boost::vecS, boost::undirectedS, string, foreign_key_relationship  > relational_graph;
typedef boost::graph_traits<relational_graph>::vertex_descriptor relational_vertex;
typedef boost::graph_traits<relational_graph>::vertices_size_type relational_vertex_index;
typedef boost::graph_traits<relational_graph>::edge_descriptor relational_edge;
typedef relational_vertex_index* relational_rank;
typedef relational_vertex* relational_parent;

void libpqxx_error( const pqxx_exception &e ){
    std::cerr << "*** Caught pqxx_exception:\n";
    std::cerr << e.base().what() << "\n";
    const sql_error *s=dynamic_cast<const sql_error*>(&e.base());
    if (s) std::cerr << "Query was: " << s->query() << "\n";
}

void connect_relational_vertices( map< foreign_key_relationship, relational_edge > &table_edges, result &foreign_keys, set<string> &tables_to_connect, map< string, relational_vertex > &table_vertices, relational_graph &rg, boost::disjoint_sets<relational_rank, relational_parent> &ds ){
    for( unsigned i=0; i<foreign_keys.size(); i++ ){
        foreign_key_relationship this_relationship(
            foreign_keys[i]["parent_table"].c_str(),
            foreign_keys[i]["parent_column"].c_str(),
            foreign_keys[i]["child_table"].c_str(),
            foreign_keys[i]["child_column"].c_str()
        );
        if( !table_edges.count( this_relationship ) && tables_to_connect.count( foreign_keys[i]["parent_table"].c_str() ) && tables_to_connect.count( foreign_keys[i]["child_table"].c_str() ) ){
            table_edges[ this_relationship ] = boost::add_edge(
                table_vertices[ string( foreign_keys[i]["parent_table"].c_str() ) ], 
                table_vertices[ string( foreign_keys[i]["child_table"].c_str() ) ], 
                this_relationship, 
                rg
            ).first;
            ds.union_set( table_vertices[ string( foreign_keys[i]["parent_table"].c_str() ) ], table_vertices[ string( foreign_keys[i]["child_table"].c_str() ) ] );
        }
    }
}

void add_possible_linking_vertex( result &foreign_keys, map< string, relational_vertex > &table_vertices, relational_graph &rg ){
    for( unsigned i=0; i<foreign_keys.size(); i++ ){
        if( !table_vertices.count( foreign_keys[i]["parent_table"].c_str() ) ){
            table_vertices[ foreign_keys[i]["parent_table"].c_str() ] = boost::add_vertex( foreign_keys[i]["parent_table"].c_str(), rg );
            break;
        }
        if( foreign_keys[i]["child_table"].c_str() ){
            table_vertices[ foreign_keys[i]["child_table"].c_str() ] = boost::add_vertex( foreign_keys[i]["child_table"].c_str(), rg );
            break;
        }
    }
}    

set< foreign_key_relationship > get_foreign_keys( transaction_base &t, set<string> tables_to_connect ){
    try{
        result foreign_keys = t.prepared("get_foreign_keys").exec();

        set< foreign_key_relationship > relational_routes;

        if( tables_to_connect.size() ){

            relational_graph rg;

            map< string, relational_vertex > table_vertices;
            for( string table: tables_to_connect )
                table_vertices[ table ] = boost::add_vertex( table, rg );

            std::vector<relational_vertex_index> rank( num_vertices(rg) );
            std::vector<relational_vertex> parent( num_vertices(rg) );

            boost::disjoint_sets<relational_rank, relational_parent> ds(&rank[0], &parent[0]);

            boost::initialize_incremental_components(rg, ds);
            boost::incremental_components(rg, ds);

            map< foreign_key_relationship, relational_edge > table_edges;
            for( unsigned i=0; i<foreign_keys.size(); i++ )
                connect_relational_vertices( table_edges, foreign_keys, tables_to_connect, table_vertices, rg, ds );

        }

        return relational_routes;
    }
    catch( const pqxx_exception &e ){
        libpqxx_error( e );
        set< foreign_key_relationship > relational_routes;
        return relational_routes;
    }
}

int main()
{
    relational_graph rg;
    map<foreign_key_relationship, relational_edge> table_edges;
    pqxx::result data;
    set<string> tables { "foo", "bar" };
    map<string, relational_vertex> table_vertices;
    boost::disjoint_sets<relational_rank, relational_parent> ds(relational_rank{}, relational_parent{});

    connect_relational_vertices(table_edges, data, tables, table_vertices, rg, ds);
}

я скомпилировал с

  • gcc 4.8, 4.9, лязг 3.5-1
  • повысить 1_56_0
  • командная строка:

    g++ -std=c++0x -Wall -pedantic -lpthread -g -O0 -isystem ~/custom/boost/ -isystem /usr/include/mpi test.cpp -o test -lmpich -lpqxx

person sehe    schedule 07.10.2014