Boost logo

Boost Users :

From: Alejandro Aragón (alex_aragon_at_[hidden])
Date: 2006-02-27 14:09:22


Doug Gregor wrote:
> On Feb 17, 2006, at 7:27 PM, Alejandro Aragón wrote:
>
>> Hi, I've been using the graph library for a while now. I was finally
>> able to run my first Kruskal's algorithm adapted to my own problem.
>> I am not a expert in C++ so I would like to ask something. I was
>> taught
>> that you should keep the definitions in one file and the declarations
>> in
>> another file. Well, working with the boost graph lirary, do we have to
>> do this as well???? It doesn't make sense to me to do this since I am
>> already working with the headers of the boost graph library to have the
>> declarations in a .h file. Therefore, I just created a file graph.cxx
>> where I put the particular implementation that I'm using, the
>> definitions of my own graph properties and so on. Is this correct?
>
> If you need the definitions of your graph in a file other than
> graph.cxx, move them to a header. Generally, the more you can put in
> .cxx files the better.
>
> Doug

Thanks for replying Doug. What I did in the end was to separate part of
the code in a header. Thus, my header looks like this:

#ifndef _GRAPH_H
#define _GRAPH_H

#include <iostream>
#include <fstream>
#include <boost/lexical_cast.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <math.h>

using namespace boost;

// define interior properties for vertices
struct vertex_coord_t {
     typedef vertex_property_tag kind;
};

// defines interior properties for edges
struct edge_angle_t {
     typedef edge_property_tag kind;
     };

typedef property<vertex_coord_t, std::pair<double,double> > VertexProperty;
typedef property<edge_angle_t, double,
                 property < edge_weight_t, double > > EdgeProperty;

typedef adjacency_list<
     // store out_edges of each vertex in a set, enforcing a graph without
     // parallel edges
     setS, //check also hash_setS
     // store vertex set in a std::vector
     vecS,
     directedS,
     VertexProperty,
     EdgeProperty
> Graph;

#endif

In the other file, I have all the functions that I wrote to handle my
special case of graph. Have a nice day,

a^2


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net