~ubuntu-branches/ubuntu/maverick/yapgvb/maverick

« back to all changes in this revision

Viewing changes to _yapgvb.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-07-13 17:22:10 UTC
  • Revision ID: james.westby@ubuntu.com-20060713172210-7u48pea2jrxktglo
Tags: upstream-1.1.1
ImportĀ upstreamĀ versionĀ 1.1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
3
* This file is a part of the Yapgvb software package, and is 
 
4
* licensed under the Common Public License version 1.0.  A 
 
5
* `LICENSE' file should have been included with this source.
 
6
*
 
7
* Copyright (c) 2006 Lonnie Princehouse
 
8
*
 
9
*/
 
10
 
 
11
#ifndef _yapgvb_defined
 
12
#define _yapgvb_defined
 
13
 
 
14
#include <iostream>
 
15
#include <boost/python.hpp>
 
16
#include <boost/python/str.hpp>
 
17
#include <boost/python/enum.hpp>
 
18
#include <boost/python/return_value_policy.hpp>
 
19
#include <boost/python/manage_new_object.hpp>
 
20
 
 
21
 
 
22
#include <types.h>
 
23
#include <graph.h>
 
24
#include <gvc.h>
 
25
 
 
26
#include <boost/shared_ptr.hpp>
 
27
 
 
28
using namespace boost::python;
 
29
using namespace boost;
 
30
 
 
31
#include <string.h>
 
32
 
 
33
void stop_iteration ();
 
34
 
 
35
enum agraph_type { 
 
36
    agraph = AGRAPH, 
 
37
    agraphstrict = AGRAPHSTRICT, 
 
38
    agdigraph = AGDIGRAPH,
 
39
    agdigraphstrict = AGDIGRAPHSTRICT,
 
40
};
 
41
 
 
42
// Magical function to reattach graphviz labout attributes to the dictionary
 
43
// structures.  Not listed in any headers because it might go away someday.
 
44
 
 
45
extern "C" {
 
46
void attach_attrs(Agraph_t* g);
 
47
};
 
48
 
 
49
char *extract_str (str s);
 
50
 
 
51
void py_aginit ();
 
52
 
 
53
class AttributeSymbol {
 
54
    Agsym_t *sym;
 
55
  public:
 
56
    AttributeSymbol (Agsym_t *s);
 
57
    bool valid ();
 
58
    int index ();
 
59
    void assert_validity ();
 
60
};
 
61
 
 
62
template <class T>
 
63
class AttributeContainer {
 
64
  protected:
 
65
    T *ptr;
 
66
    void set (T *p);
 
67
  public:
 
68
    AttributeContainer ();
 
69
    AttributeContainer (T *p);
 
70
    T *get();
 
71
    
 
72
    long hash();
 
73
 
 
74
    object get_attribute (AttributeSymbol *s);
 
75
    int set_attribute (AttributeSymbol *s, object value);
 
76
 
 
77
    AttributeSymbol *find_attribute ( str attribute_name ); 
 
78
};
 
79
     
 
80
//class Node;
 
81
 
 
82
class Graph;
 
83
class Node;
 
84
 
 
85
class Edge : public AttributeContainer<Agedge_t> {
 
86
  public:
 
87
      Edge (Agedge_t *e);
 
88
      Node *get_head();
 
89
      Node *get_tail();
 
90
};
 
91
 
 
92
class Node : public AttributeContainer<Agnode_t> { 
 
93
  private:
 
94
      Agraph_t *graph();
 
95
  public:
 
96
      Node (Agnode_t *n);
 
97
      PyObject *get_name ();
 
98
      Edge *first_edge ();
 
99
      Edge *first_inbound_edge ();
 
100
      Edge *next_inbound_edge (Edge *a);
 
101
      Edge *first_outbound_edge ();
 
102
      Edge *next_outbound_edge (Edge *a);
 
103
      Edge *next_edge (Edge *a);
 
104
      Graph *get_graph ();
 
105
};
 
106
 
 
107
 
 
108
 
 
109
class Graph : public AttributeContainer<Agraph_t> {
 
110
  private:
 
111
    bool _is_subgraph;
 
112
    bool destroy;
 
113
    bool auto_attach;
 
114
  public:
 
115
    Graph (); 
 
116
    Graph (FILE *instream); // : AttributeContainer<Agraph_t>();
 
117
    Graph (str name); // : AttributeContainer<Agraph_t>();
 
118
    Graph (str name, agraph_type type); // : AttributeContainer<Agraph_t>();
 
119
    Graph (Agraph_t *g, bool is_a_subgraph); // : AttributeContainer<Agraph_t> (g);
 
120
    Graph (Agraph_t *g); // : AttributeContainer<Agraph_t> (g);
 
121
    ~Graph ();
 
122
    
 
123
    void debug_render();
 
124
    void debug_file(FILE *f);
 
125
 
 
126
    bool points_to_same_graph (Graph *o);
 
127
 
 
128
    Node *node (str name);
 
129
    Node *find_node (str name);
 
130
 
 
131
    Edge *edge (Node *a, Node *b);
 
132
    
 
133
    Graph *subgraph (str name);
 
134
 
 
135
    int write(FILE *f);
 
136
    
 
137
    AttributeSymbol *declare_graph_attribute(str attribute_name, str default_value);
 
138
    
 
139
    AttributeSymbol *declare_node_attribute(str attribute_name, str default_value);
 
140
 
 
141
    AttributeSymbol *declare_edge_attribute(str attribute_name, str default_value);
 
142
    
 
143
    void set_destroy(bool x);
 
144
 
 
145
    PyObject *get_name ();
 
146
   
 
147
    Edge *find_edge (Node *a, Node *b);
 
148
 
 
149
    Node *first_node ();
 
150
 
 
151
    Node *last_node ();
 
152
 
 
153
    Node *next_node (Node *a);
 
154
 
 
155
    Node *previous_node (Node *a);
 
156
 
 
157
    void attach();
 
158
 
 
159
    void set_auto_attach(bool a);
 
160
    bool get_auto_attach();
 
161
 
 
162
    bool is_directed();
 
163
    bool is_strict();
 
164
    bool is_subgraph();
 
165
};
 
166
 
 
167
 
 
168
 
 
169
class GVCWrapper {
 
170
    GVC_t *gvc;
 
171
  public:
 
172
    // Default constructor
 
173
    GVCWrapper();
 
174
    
 
175
    int layout(Graph *graph, str engine);
 
176
    
 
177
    int render(Graph *graph, str fmt, FILE *outstream);
 
178
 
 
179
    // Linking to the pre-compiled graphviz library is causing render to not work
 
180
    // on FILE objects which boost has extracted from Python file objects.
 
181
    // 
 
182
    // Instead of getting to the bottom of this problem, I'm just going to
 
183
    // overload the function in Python and open the file in C. 
 
184
    //
 
185
    // Maybe someone who actually uses Windows would want to fix this properly?
 
186
    int render_windows_workaround(Graph *graph, str fmt, str out_filename);
 
187
 
 
188
    int freeLayout (Graph *graph);
 
189
};
 
190
 
 
191
struct pyfile_to_FILE
 
192
{
 
193
    static FILE& execute(PyObject& o)
 
194
    {
 
195
            return *PyFile_AsFile(&o);
 
196
    }
 
197
};
 
198
 
 
199
#endif