~zorba-coders/zorba/bug-942161-image

« back to all changes in this revision

Viewing changes to src/com/zorba-xquery/www/modules/image/graphviz.xq.src/graphviz.h

  • Committer: Tarmac
  • Author(s): Juan Zacarias
  • Date: 2012-08-04 05:15:34 UTC
  • mfrom: (50.1.2 image-module)
  • Revision ID: tarmac-20120804051534-xpd92v60lisexzvf
Tags: zorba-2.6
Moves GraphViz module out of the image module. Approved: Juan Zacarias, Chris Hillery

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2006-2008 The FLWOR Foundation.
3
 
 *
4
 
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 
 * you may not use this file except in compliance with the License.
6
 
 * You may obtain a copy of the License at
7
 
 *
8
 
 * http://www.apache.org/licenses/LICENSE-2.0
9
 
 *
10
 
 * Unless required by applicable law or agreed to in writing, software
11
 
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 
 * See the License for the specific language governing permissions and
14
 
 * limitations under the License.
15
 
 */
16
 
 
17
 
#ifndef ZORBA_GRAPHVIZMODULE_GRAPHVIZ_H
18
 
#define ZORBA_GRAPHVIZMODULE_GRAPHVIZ_H
19
 
 
20
 
#include <map>
21
 
 
22
 
#include <zorba/iterator.h>
23
 
#include <zorba/zorba.h>
24
 
#include <zorba/function.h>
25
 
#include <zorba/external_module.h>
26
 
 
27
 
namespace zorba
28
 
{
29
 
namespace graphvizmodule
30
 
{
31
 
 
32
 
class GraphvizModule;
33
 
 
34
 
/******************************************************************************
35
 
 *****************************************************************************/
36
 
class GraphvizFunction : public ContextualExternalFunction
37
 
{
38
 
  protected:
39
 
    const GraphvizModule* theModule;
40
 
 
41
 
    GraphvizFunction(const GraphvizModule* aModule)
42
 
    : theModule(aModule) {}
43
 
 
44
 
    static std::string
45
 
    getGraphvizTmpFileName(zorba::ItemFactory* aFactory);
46
 
 
47
 
    static bool
48
 
    getAttribute(zorba::ItemFactory* aFactory,
49
 
        const char* attrname,
50
 
        const zorba::Item& elem,
51
 
        zorba::Item& attr);
52
 
 
53
 
    static void
54
 
    printTypeAndAttr(zorba::ItemFactory* aFactory,
55
 
                     const zorba::Item& in,
56
 
                     std::fstream& os);
57
 
 
58
 
    static void
59
 
    visitNode(zorba::ItemFactory* aFactory,
60
 
              const zorba::Item& in, std::fstream& os);
61
 
 
62
 
    static void
63
 
    visitEdge(zorba::ItemFactory* aFactory,
64
 
              const zorba::Item& in, std::fstream& os);
65
 
 
66
 
    static void
67
 
    printGraph(zorba::ItemFactory* aFactory,
68
 
               const zorba::Item& in, std::fstream& os);
69
 
 
70
 
    static void
71
 
    gxl2dot(zorba::ItemFactory* aFactory,
72
 
            const zorba::Item& in, std::fstream& os);
73
 
 
74
 
    static void
75
 
    throwErrorWithQName (zorba::ItemFactory* aFactory,
76
 
                         const String& aLocalName,
77
 
                         const String& aMessage);
78
 
 
79
 
  public:
80
 
 
81
 
    virtual String
82
 
    getURI() const;
83
 
};
84
 
 
85
 
/******************************************************************************
86
 
 *****************************************************************************/
87
 
class DotFunction : public GraphvizFunction
88
 
{
89
 
public:
90
 
  DotFunction(const GraphvizModule* aModule)
91
 
    : GraphvizFunction(aModule) {}
92
 
 
93
 
  virtual ~DotFunction() {}
94
 
 
95
 
  virtual String
96
 
  getLocalName() const { return "dot"; }
97
 
 
98
 
  virtual zorba::ItemSequence_t
99
 
  evaluate(const Arguments_t&,
100
 
           const zorba::StaticContext*,
101
 
           const zorba::DynamicContext*) const;
102
 
 
103
 
protected:
104
 
  class LazyDotSequence : public zorba::ItemSequence
105
 
  {
106
 
    class InternalIterator : public Iterator
107
 
    {
108
 
    private:
109
 
      LazyDotSequence   *theItemSequence;
110
 
      Iterator_t        arg_iter;
111
 
      bool is_open;
112
 
    public:
113
 
      InternalIterator(LazyDotSequence *item_sequence);
114
 
 
115
 
      virtual void open();
116
 
      virtual bool next(Item& aItem);
117
 
      virtual void close();
118
 
      virtual bool isOpen() const;
119
 
    };
120
 
    public:
121
 
      LazyDotSequence(const DotFunction*,
122
 
                      ItemSequence* aArg);
123
 
 
124
 
      virtual Iterator_t    getIterator();
125
 
 
126
 
    protected:
127
 
      const DotFunction*            theFunc;
128
 
      ItemSequence*                 theArg;
129
 
  };
130
 
};
131
 
 
132
 
/******************************************************************************
133
 
 *****************************************************************************/
134
 
class GxlFunction : public GraphvizFunction
135
 
{
136
 
public:
137
 
  GxlFunction(const GraphvizModule* aModule)
138
 
    : GraphvizFunction(aModule) {}
139
 
 
140
 
  virtual ~GxlFunction() {}
141
 
 
142
 
  virtual String
143
 
  getLocalName() const { return "gxl"; }
144
 
 
145
 
  virtual zorba::ItemSequence_t
146
 
  evaluate(const Arguments_t&,
147
 
           const zorba::StaticContext*,
148
 
           const zorba::DynamicContext*) const;
149
 
 
150
 
protected:
151
 
  class LazyGxlSequence : public zorba::ItemSequence
152
 
  {
153
 
    class InternalIterator : public Iterator
154
 
    {
155
 
    private:
156
 
      LazyGxlSequence   *theItemSequence;
157
 
      Iterator_t        arg_iter;
158
 
      bool is_open;
159
 
    public:
160
 
      InternalIterator(LazyGxlSequence *item_sequence);
161
 
 
162
 
      virtual void open();
163
 
      virtual bool next(Item& aItem);
164
 
      virtual void close();
165
 
      virtual bool isOpen() const;
166
 
    };
167
 
    public:
168
 
      LazyGxlSequence(const GxlFunction*,
169
 
                      ItemSequence* aArg);
170
 
 
171
 
      Iterator_t  getIterator();
172
 
 
173
 
    protected:
174
 
      const GxlFunction*            theFunc;
175
 
      ItemSequence*                 theArg;
176
 
  };
177
 
};
178
 
 
179
 
/******************************************************************************
180
 
 ******************************************************************************/
181
 
class GraphvizModule : public ExternalModule
182
 
{
183
 
private:
184
 
  static ItemFactory* theFactory;
185
 
 
186
 
protected:
187
 
  class ltstr
188
 
  {
189
 
  public:
190
 
        
191
 
 
192
 
    bool operator()(const String& s1, const String& s2) const
193
 
    {
194
 
      return s1.compare(s2) < 0;
195
 
    }
196
 
  };
197
 
 
198
 
  typedef std::map<String, ExternalFunction*, ltstr> FuncMap_t;
199
 
 
200
 
  FuncMap_t theFunctions;
201
 
 
202
 
public:
203
 
 
204
 
        static const char* theModule;
205
 
 
206
 
  virtual ~GraphvizModule();
207
 
 
208
 
  virtual String
209
 
  getURI() const
210
 
  {
211
 
    return theModule;
212
 
  }
213
 
 
214
 
  virtual ExternalFunction*
215
 
  getExternalFunction(const String& aLocalname);
216
 
 
217
 
  virtual void
218
 
  destroy();
219
 
 
220
 
  static ItemFactory*
221
 
  getItemFactory()
222
 
  {
223
 
    if(!theFactory)
224
 
    {
225
 
      theFactory = Zorba::getInstance(0)->getItemFactory();
226
 
    }
227
 
    return theFactory;
228
 
  }
229
 
};
230
 
 
231
 
} /* namespace zorba */
232
 
} /* namespace graphvizmodule */
233
 
 
234
 
#endif