2
* Copyright 2006-2008 The FLWOR Foundation.
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
17
#ifndef ZORBA_GRAPHVIZMODULE_GRAPHVIZ_H
18
#define ZORBA_GRAPHVIZMODULE_GRAPHVIZ_H
22
#include <zorba/iterator.h>
23
#include <zorba/zorba.h>
24
#include <zorba/function.h>
25
#include <zorba/external_module.h>
29
namespace graphvizmodule
34
/******************************************************************************
35
*****************************************************************************/
36
class GraphvizFunction : public ContextualExternalFunction
39
const GraphvizModule* theModule;
41
GraphvizFunction(const GraphvizModule* aModule)
42
: theModule(aModule) {}
45
getGraphvizTmpFileName(zorba::ItemFactory* aFactory);
48
getAttribute(zorba::ItemFactory* aFactory,
50
const zorba::Item& elem,
54
printTypeAndAttr(zorba::ItemFactory* aFactory,
55
const zorba::Item& in,
59
visitNode(zorba::ItemFactory* aFactory,
60
const zorba::Item& in, std::fstream& os);
63
visitEdge(zorba::ItemFactory* aFactory,
64
const zorba::Item& in, std::fstream& os);
67
printGraph(zorba::ItemFactory* aFactory,
68
const zorba::Item& in, std::fstream& os);
71
gxl2dot(zorba::ItemFactory* aFactory,
72
const zorba::Item& in, std::fstream& os);
75
throwErrorWithQName (zorba::ItemFactory* aFactory,
76
const String& aLocalName,
77
const String& aMessage);
85
/******************************************************************************
86
*****************************************************************************/
87
class DotFunction : public GraphvizFunction
90
DotFunction(const GraphvizModule* aModule)
91
: GraphvizFunction(aModule) {}
93
virtual ~DotFunction() {}
96
getLocalName() const { return "dot"; }
98
virtual zorba::ItemSequence_t
99
evaluate(const Arguments_t&,
100
const zorba::StaticContext*,
101
const zorba::DynamicContext*) const;
104
class LazyDotSequence : public zorba::ItemSequence
106
class InternalIterator : public Iterator
109
LazyDotSequence *theItemSequence;
113
InternalIterator(LazyDotSequence *item_sequence);
116
virtual bool next(Item& aItem);
117
virtual void close();
118
virtual bool isOpen() const;
121
LazyDotSequence(const DotFunction*,
124
virtual Iterator_t getIterator();
127
const DotFunction* theFunc;
128
ItemSequence* theArg;
132
/******************************************************************************
133
*****************************************************************************/
134
class GxlFunction : public GraphvizFunction
137
GxlFunction(const GraphvizModule* aModule)
138
: GraphvizFunction(aModule) {}
140
virtual ~GxlFunction() {}
143
getLocalName() const { return "gxl"; }
145
virtual zorba::ItemSequence_t
146
evaluate(const Arguments_t&,
147
const zorba::StaticContext*,
148
const zorba::DynamicContext*) const;
151
class LazyGxlSequence : public zorba::ItemSequence
153
class InternalIterator : public Iterator
156
LazyGxlSequence *theItemSequence;
160
InternalIterator(LazyGxlSequence *item_sequence);
163
virtual bool next(Item& aItem);
164
virtual void close();
165
virtual bool isOpen() const;
168
LazyGxlSequence(const GxlFunction*,
171
Iterator_t getIterator();
174
const GxlFunction* theFunc;
175
ItemSequence* theArg;
179
/******************************************************************************
180
******************************************************************************/
181
class GraphvizModule : public ExternalModule
184
static ItemFactory* theFactory;
192
bool operator()(const String& s1, const String& s2) const
194
return s1.compare(s2) < 0;
198
typedef std::map<String, ExternalFunction*, ltstr> FuncMap_t;
200
FuncMap_t theFunctions;
204
static const char* theModule;
206
virtual ~GraphvizModule();
214
virtual ExternalFunction*
215
getExternalFunction(const String& aLocalname);
225
theFactory = Zorba::getInstance(0)->getItemFactory();
231
} /* namespace zorba */
232
} /* namespace graphvizmodule */