zorba-coders team mailing list archive
-
zorba-coders team
-
Mailing list archive
-
Message #13003
[Merge] lp:~zorba-coders/zorba/image-module-alone into lp:zorba/image-module
Chris Hillery has proposed merging lp:~zorba-coders/zorba/image-module-alone into lp:zorba/image-module.
Requested reviews:
Zorba Coders (zorba-coders)
For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/image-module-alone/+merge/118227
Removes Graphviz module (will be restored in a separate module branch)
--
https://code.launchpad.net/~zorba-coders/zorba/image-module-alone/+merge/118227
Your team Zorba Coders is requested to review the proposed merge of lp:~zorba-coders/zorba/image-module-alone into lp:zorba/image-module.
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2011-10-09 14:49:07 +0000
+++ CMakeLists.txt 2012-08-04 00:55:23 +0000
@@ -18,11 +18,11 @@
ENABLE_TESTING ()
INCLUDE (CTest)
-SET_CMAKE_MODULE_PATH ()
-
FIND_PACKAGE (Zorba REQUIRED HINTS "${ZORBA_BUILD_DIR}")
INCLUDE ("${Zorba_USE_FILE}")
+SET_CMAKE_MODULE_PATH ()
+
ADD_SUBDIRECTORY ("src")
DONE_DECLARING_ZORBA_URIS ()
=== removed file 'cmake_modules/FindGraphviz.cmake'
--- cmake_modules/FindGraphviz.cmake 2012-07-20 20:25:12 +0000
+++ cmake_modules/FindGraphviz.cmake 1970-01-01 00:00:00 +0000
@@ -1,107 +0,0 @@
-# Copyright 2010 28msec Inc.
-
-# - Try to find Graphviz and the libraries it depends on
-# Once done this will define
-#
-# GRAPHVIZ_FOUND - system has graphviz
-# GRAPHVIZ_INCLUDE_DIRS - the graphviz include directory
-# GRAPHVIZ_LIBRARIES - Link these to use graphviz
-
-IF (GRAPHVIZ_INCLUDE AND GRAPHVIZ_LIBRARY AND GVC_LIBRARY AND CDT_LIBRARY AND PATHPLAN_LIBRARY AND EXPAT_LIBRARY)
- # in cache already
- SET(GRAPHVIZ_FIND_QUIETLY TRUE)
-ENDIF (GRAPHVIZ_INCLUDE AND GRAPHVIZ_LIBRARY AND GVC_LIBRARY AND CDT_LIBRARY AND PATHPLAN_LIBRARY AND EXPAT_LIBRARY)
-
-FIND_PATH(
- GRAPHVIZ_INCLUDE
- NAMES graph.h
- PATHS ${GRAPHVIZ_INCLUDE_DIR}
- PATH_SUFFIXES graphviz)
-
-FIND_LIBRARY(
- GRAPHVIZ_LIBRARY
- NAMES graph
- PATHS ${GRAPHVIZ_LIBRARY_DIR})
-
-
-IF(GRAPHVIZ_LIBRARY)
- GET_FILENAME_COMPONENT(GRAPHVIZ_LIBRARY_DIR_ ${GRAPHVIZ_LIBRARY} PATH)
-
- FIND_LIBRARY(
- GVC_LIBRARY
- NAMES gvc
- PATHS ${GRAPHVIZ_LIBRARY_DIR_} ${GVC_LIBRARY_DIR})
-
- FIND_LIBRARY(
- CDT_LIBRARY
- NAMES cdt
- PATHS ${GRAPHVIZ_LIBRARY_DIR_} ${CDT_LIBRARY_DIR})
-
- FIND_LIBRARY(
- PATHPLAN_LIBRARY
- NAMES pathplan
- PATHS ${GRAPHVIZ_LIBRARY_DIR_} ${PATHPLAN_LIBRARY_DIR})
-
- # for expat and libz and xdot, we have to make sure that we use the library that is used by gvc
- GET_FILENAME_COMPONENT(GVC_DIR ${GVC_LIBRARY} PATH)
- FIND_LIBRARY(
- Z_LIBRARY
- NAMES z
- HINTS ${GVC_DIR})
-
- FIND_LIBRARY(
- EXPAT_LIBRARY
- NAMES expat
- HINTS ${GVC_DIR})
-
- # On Mac, libgvc has a dependency to libxdot. Therefore, the library is search here to enable the install command in coreSDK/OSX.cmake
- FIND_LIBRARY(
- XDOT_LIBRARY
- NAMES xdot
- HINTS ${GVC_DIR})
-
-ENDIF(GRAPHVIZ_LIBRARY)
-
-IF (GRAPHVIZ_INCLUDE AND GRAPHVIZ_LIBRARY AND GVC_LIBRARY AND CDT_LIBRARY AND PATHPLAN_LIBRARY)
- SET(GRAPHVIZ_FOUND TRUE)
- SET(GRAPHVIZ_LIBRARIES "${GRAPHVIZ_LIBRARY}" "${GVC_LIBRARY}" "${CDT_LIBRARY}" "${PATHPLAN_LIBRARY}")
-
- SET(GRAPHVIZ_INCLUDE_DIRS "${GRAPHVIZ_INCLUDE}")
-ELSE (GRAPHVIZ_INCLUDE AND GRAPHVIZ_LIBRARY AND GVC_LIBRARY AND CDT_LIBRARY AND PATHPLAN_LIBRARY)
- SET(GRAPHVIZ_FOUND FALSE)
-ENDIF (GRAPHVIZ_INCLUDE AND GRAPHVIZ_LIBRARY AND GVC_LIBRARY AND CDT_LIBRARY AND PATHPLAN_LIBRARY)
-
-IF (GRAPHVIZ_FOUND)
- IF (EXPAT_LIBRARY)
- LIST(APPEND GRAPHVIZ_LIBRARIES "${EXPAT_LIBRARY}")
- ELSE (EXPAT_LIBRARY)
- IF(NOT WIN32)
- #SET(GRAPHVIZ_FOUND FALSE)
- ENDIF(NOT WIN32)
- ENDIF (EXPAT_LIBRARY)
-
- IF (Z_LIBRARY)
- LIST(APPEND GRAPHVIZ_LIBRARIES "${Z_LIBRARY}")
- ELSE (Z_LIBRARY)
- IF(NOT WIN32)
- #SET(GRAPHVIZ_FOUND FALSE)
- ENDIF(NOT WIN32)
- ENDIF (Z_LIBRARY)
-ENDIF (GRAPHVIZ_FOUND)
-
-IF(GRAPHVIZ_FOUND)
- IF(NOT GRAPHVIZ_FIND_QUIETLY)
- MESSAGE(STATUS "Found Graphviz: ${GRAPHVIZ_LIBRARY}")
- MESSAGE(STATUS " : ${GRAPHVIZ_INCLUDE}")
- MESSAGE(STATUS " : ${GVC_LIBRARY}")
- MESSAGE(STATUS " : ${CDT_LIBRARY}")
- MESSAGE(STATUS " : ${PATHPLAN_LIBRARY}")
- MESSAGE(STATUS " : ${Z_LIBRARY}")
- MESSAGE(STATUS " : ${EXPAT_LIBRARY}")
- MESSAGE(STATUS " : ${XDOT_LIBRARY}")
- ENDIF(NOT GRAPHVIZ_FIND_QUIETLY)
-ELSE(GRAPHVIZ_FOUND)
- MESSAGE(STATUS "Could not find Graphviz")
-ENDIF(GRAPHVIZ_FOUND)
-
-MARK_AS_ADVANCED(GRAPHVIZ_INCLUDE GRAPHVIZ_LIBRARY GRAPHVIZ_INCLUDE_DIRS GRAPHVIZ_LIBRARIES GVC_LIBRARY CDT_LIBRARY PATHPLAN_LIBRARY EXPAT_LIBRARY Z_LIBRARY)
=== removed file 'cmake_modules/Windows/FindGraphviz.cmake'
--- cmake_modules/Windows/FindGraphviz.cmake 2012-07-20 20:25:12 +0000
+++ cmake_modules/Windows/FindGraphviz.cmake 1970-01-01 00:00:00 +0000
@@ -1,41 +0,0 @@
-# Copyright 2010 The FLWOR Foundation.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# - Try to find the Graphviz lib on Windows
-#
-# This is a proxy module that calls the FindGraphviz.cmake module. Before
-# doing that, we try to guess where Graphviz might be on the user's machine.
-# The user should provide ZORBA_THIRD_PARTY_REQUIREMENTS which is a path where
-# the Graphviz directory can be found. The Graphviz directory must have "graphviz"
-# (case insensitive) in its name.
-#
-# This module helps the Windows user to avoid providing the following two
-# variables when building Zorba:
-# -D GRAPHVIZ_INCLUDE="path_to_3rd_party_dir\*graphviz*\src"
-# -D GRAPHVIZ_LIBRARY="path_to_3rd_party_dir\*graphviz*\bin\[Release]\graphviz.lib"
-#
-# See the FindGraphviz.cmake module shipped with Zorba for more information.
-
-FIND_PACKAGE_WIN32 (
- NAME "Graphviz"
- FOUND_VAR "GRAPHVIZ_FOUND"
- SEARCH_NAMES "graphviz"
-)
-
-IF (GRAPHVIZ_FOUND)
-
- # find the needed DLL's
- FIND_PACKAGE_DLLS_WIN32 (${FOUND_LOCATION} graph.dll)
-
-ENDIF (GRAPHVIZ_FOUND)
=== modified file 'src/com/zorba-xquery/www/modules/image/CMakeLists.txt'
--- src/com/zorba-xquery/www/modules/image/CMakeLists.txt 2012-07-20 20:25:12 +0000
+++ src/com/zorba-xquery/www/modules/image/CMakeLists.txt 2012-08-04 00:55:23 +0000
@@ -86,31 +86,3 @@
ENDIF (ImageMagick_FOUND)
ENDIF(ZORBA_SUPPRESS_ImageMagick)
MESSAGE(STATUS "")
-
-
-########################################################################
-# Graphviz
-########################################################################
-IF(ZORBA_SUPPRESS_GRAPHVIZ)
- MESSAGE(STATUS "ZORBA_SUPPRESS_Graphviz is true - not searching for Graphviz.")
-ELSE (ZORBA_SUPPRESS_GRAPHVIZ)
-
- MESSAGE (STATUS "Looking for Graphviz")
- FIND_PACKAGE(Graphviz)
-
- IF (GRAPHVIZ_FOUND)
- MESSAGE(STATUS "Found Graphviz library -- "${GRAPHVIZ_LIBRARIES})
-
- INCLUDE_DIRECTORIES(${GRAPHVIZ_INCLUDE_DIRS})
- INCLUDE_DIRECTORIES("graphviz.xq.src")
- DECLARE_ZORBA_MODULE (VERSION 1.0 FILE "graphviz.xq"
- URI "http://www.zorba-xquery.com/modules/image/graphviz"
- LINK_LIBRARIES "${GRAPHVIZ_LIBRARIES}")
-
- ADD_TEST_DIRECTORY("${PROJECT_SOURCE_DIR}/test_graphviz")
-
- ELSE (GRAPHVIZ_FOUND)
- MESSAGE(STATUS "Graphviz library not found.")
- ENDIF (GRAPHVIZ_FOUND)
-ENDIF (ZORBA_SUPPRESS_GRAPHVIZ)
-MESSAGE(STATUS "")
=== removed directory 'src/com/zorba-xquery/www/modules/image/graphviz.xq.src'
=== removed file 'src/com/zorba-xquery/www/modules/image/graphviz.xq.src/graphviz.cpp'
--- src/com/zorba-xquery/www/modules/image/graphviz.xq.src/graphviz.cpp 2012-07-20 20:25:12 +0000
+++ src/com/zorba-xquery/www/modules/image/graphviz.xq.src/graphviz.cpp 1970-01-01 00:00:00 +0000
@@ -1,615 +0,0 @@
-/*
- * Copyright 2006-2008 The FLWOR Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "graphviz.h"
-
-#include <cassert>
-#include <fstream>
-#include <sstream>
-#ifdef WIN32
-# include <io.h>
-#endif
-
-#include <stdio.h>
-#ifdef WIN32
- #include <direct.h>
- #define GetCurrentDir _getcwd
-#else
- #include <unistd.h>
- #define GetCurrentDir getcwd
-#endif
-
-#include <types.h>
-#include <graph.h>
-#include <gvc.h>
-
-#include <zorba/diagnostic_list.h>
-#include <zorba/user_exception.h>
-#include <zorba/empty_sequence.h>
-#include <zorba/singleton_item_sequence.h>
-
-namespace zorba
-{
- namespace graphvizmodule
- {
-
-/******************************************************************************
- *****************************************************************************/
-String
-GraphvizFunction::getURI() const
-{
- return theModule->getURI();
-}
-
-/******************************************************************************
- *****************************************************************************/
-std::string
-GraphvizFunction::getGraphvizTmpFileName(zorba::ItemFactory* aFactory) {
- char lTmpDir[FILENAME_MAX];
-
- if (!GetCurrentDir(lTmpDir, sizeof(lTmpDir)))
- {
- GraphvizFunction::throwErrorWithQName(aFactory, "IM003", "Test");
- }
- zorba::String test(lTmpDir);
- std::ostringstream lTmpFileNameTemplate;
- lTmpFileNameTemplate << test << "/zorba.XXXXXX";
-
- char* lTemporaryString = (char*) malloc(lTmpFileNameTemplate.str().size()+1);
- strcpy(lTemporaryString, lTmpFileNameTemplate.str().c_str());
- std::string lRes = mktemp(lTemporaryString); // the replaced string is copied by assigning it to the string
- free(lTemporaryString);
- return lRes;
-}
-
-/******************************************************************************
- *****************************************************************************/
-bool
-GraphvizFunction::getAttribute(zorba::ItemFactory* aFactory,
- const char* attrname,
- const Item& elem,
- Item& attr)
-{
- Item lIdQName = aFactory->createQName("", "", attrname);
-
- Iterator_t lAttributes = elem.getAttributes();
- lAttributes->open();
- while (lAttributes->next(attr)) {
- Item lNodeName;
- attr.getNodeName(lNodeName);
- if (lNodeName.getLocalName() == lIdQName.getLocalName()) {
- return true;
- }
- }
- attr = NULL;
- return false;
-}
-
-/******************************************************************************
- *****************************************************************************/
-void
-GraphvizFunction::printTypeAndAttr(
- ItemFactory* aFactory,
- const Item& in,
- std::fstream& os)
-{
- Item lItem;
- Item lTypeQName = aFactory->createQName("", "", "type");
- Item lAttrQName = aFactory->createQName("", "", "attr");
-
- Iterator_t lChildren = in.getChildren();
-
- lChildren->open();
- while (lChildren->next(lItem)) {
-
- // needed?
- if (!lItem.isNode())
- continue;
-
- Item lNodeName;
- lItem.getNodeName(lNodeName);
-
- if (lNodeName.getLocalName() != lAttrQName.getLocalName()) {
- Item lNameAttr;
- if (!getAttribute(aFactory, "name", lItem, lNameAttr)) {
- GraphvizFunction::throwErrorWithQName(aFactory, "IM003", "GXL parse error: attr node does not have a name attribute");
- }
-
- os << " \"" << lNameAttr.getStringValue() << "\"=\"";
-
- // get the values of all bool, string, float, and int elements
- Iterator_t lAttrChildren = lItem.getChildren();
- Item lChild;
- lAttrChildren->open();
- while (lAttrChildren->next(lChild)) {
- if (!lChild.isNode())
- continue;
-
- Item lNodeName;
- lChild.getNodeName(lNodeName);
- String lChildName = lNodeName.getLocalName();
- if ( (lChildName == "bool") || (lChildName == "string")
- || (lChildName == "float") || (lChildName == "int")) {
- os << lChild.getStringValue();
- }
- }
-
- os << "\"" << std::endl;
-
- } else if (lNodeName.getStringValue() == lTypeQName.getStringValue()) {
- Item lHRefAttr;
- if (!getAttribute(aFactory, "href", lItem, lHRefAttr)) {
- GraphvizFunction::throwErrorWithQName(aFactory, "IM003", "GXL parse error: type node does not have a href attribute");
- }
-
- os << " _gxl_type=\"" << lHRefAttr.getStringValue() << "\"" << std::endl;
- }
- }
-}
-
-/******************************************************************************
- *****************************************************************************/
-void
-GraphvizFunction::visitNode(
- ItemFactory* aFactory,
- const Item& in, std::fstream& os)
-{
- Item lItem;
- if (!getAttribute(aFactory, "id", in, lItem)) {
- GraphvizFunction::throwErrorWithQName(aFactory, "IM003", "GXL parse error: node does not have an id attribute");
- }
-
- // start node with id attribute as name
- os << " \"" << lItem.getStringValue() << "\" [ " << std::endl;
-
- printTypeAndAttr(aFactory, in, os);
-
- // end of node
- os << " ]" << std::endl;
-
-} /* GraphvizFunction::visitNode */
-
-/******************************************************************************
- *****************************************************************************/
-void
-GraphvizFunction::visitEdge(
- ItemFactory* aFactory,
- const Item& in, std::fstream& os)
-{
- Item lIdAttr;
- Item lFromAttr;
- Item lToAttr;
-
- if (!getAttribute(aFactory, "id", in, lIdAttr)) {
- GraphvizFunction::throwErrorWithQName(aFactory, "IM003", "GXL parse error: edge does not have an 'id' attribute");
- }
- if (!getAttribute(aFactory, "to", in, lToAttr)) {
- GraphvizFunction::throwErrorWithQName(aFactory, "IM003", "GXL parse error: edge does not have a 'to' attribute");
- }
- if (!getAttribute(aFactory, "from", in, lFromAttr)) {
- GraphvizFunction::throwErrorWithQName(aFactory, "IM003", "GXL parse error: edge does not have a 'from' attribute");
- }
-
- os << " \"" << lFromAttr.getStringValue() << "\" -> \"" << lToAttr.getStringValue() << "\" [ " << std::endl
- << " _gxl_id=\"" << lIdAttr.getStringValue() << "\"" << std::endl;
-
- printTypeAndAttr(aFactory, in, os);
-
- os << " ]" << std::endl;
-} /* GraphvizFunction::visitEdge */
-
-/******************************************************************************
- *****************************************************************************/
-void
-GraphvizFunction::printGraph(
- ItemFactory* aFactory,
- const Item& in, std::fstream& os)
-{
- // create helper qnames for comparison
- Item lNodeQName = aFactory->createQName("", "", "node");
- Item lEdgeQName = aFactory->createQName("", "", "edge");
- Item lRelQName = aFactory->createQName("", "", "rel");
-
- // print the graph with all its children
- Item lGraphId;
- if (!getAttribute(aFactory, "id", in, lGraphId)) {
- GraphvizFunction::throwErrorWithQName(aFactory, "IM003", "GXL parse error: edge does not have an 'id' attribute");
- }
-
- os << "digraph \"" << lGraphId.getStringValue() << "\" {" << std::endl;
-
- // visit nodes and edges (TODO add rel elements)
- Iterator_t lChildren = in.getChildren();
- lChildren->open();
- Item item;
- while (lChildren->next(item)) {
- Item lNodeName;
- item.getNodeName(lNodeName);
- if (lNodeName.getLocalName() == lNodeQName.getLocalName()) {
- visitNode(aFactory, item, os);
- } else if (lNodeName.getLocalName() == lEdgeQName.getLocalName()) {
- visitEdge(aFactory, item, os);
- }
- }
-
- os << "}" << std::endl;
-} /* GraphvizFunction::printGraph */
-
-/******************************************************************************
- *****************************************************************************/
-void
-GraphvizFunction::gxl2dot(
- ItemFactory* aFactory,
- const Item& in, std::fstream& os)
-{
- Item lGXLQName = aFactory->createQName("", "", "gxl");
- Item lGraphQName = aFactory->createQName("", "", "graph");
-
- if (!in.isNode()) {
- GraphvizFunction::throwErrorWithQName(aFactory, "IM003", "GXL parse error: item is not a node");
- }
-
- Item lNodeName;
- in.getNodeName(lNodeName);
- if (lNodeName.getLocalName() != lGXLQName.getLocalName()) {
- Item lNodeName;
- in.getNodeName(lNodeName);
-
- std::ostringstream lErrorMsg;
- lErrorMsg << "GXL parse error: only element with name "
- << lGXLQName.getStringValue() << " allowed (got " << lNodeName.getStringValue()
- << ").";
- GraphvizFunction::throwErrorWithQName(aFactory, "IM003", lErrorMsg.str());
- }
-
- Iterator_t lGraphs = in.getChildren();
- lGraphs->open();
-
- Item lGraph;
- while(lGraphs->next(lGraph)) {
- if (!lGraph.isNode()) {
- GraphvizFunction::throwErrorWithQName(aFactory, "IM003", "GXL parse error: item is not a node");
- }
-
- lGraph.getNodeName(lNodeName);
- if (lNodeName.getLocalName() != lGraphQName.getLocalName()) {
- std::ostringstream lErrorMsg;
- Item lNodeName;
- lGraph.getNodeName(lNodeName);
-
- lErrorMsg << "GXL parse error: only elements with name "
- << lGraphQName.getStringValue() << " allowed (got "
- << lNodeName.getLocalName() << ").";
- GraphvizFunction::throwErrorWithQName(aFactory, "IM003", lErrorMsg.str());
- }
-
- printGraph(aFactory, lGraph, os);
-
- }
-
-} /* GraphvizFunction::gxl2dot */
-
-/******************************************************************************
- *****************************************************************************/
-void
-GraphvizFunction::throwErrorWithQName (ItemFactory* aFactory,
- const String& aLocalName,
- const String& aMessage) {
- String lNamespace = "http://www.zorba-xquery.com/modules/image/error";
- Item lQName = aFactory->createQName(lNamespace, "", aLocalName);
- throw USER_EXCEPTION(lQName, aMessage);
-}
-
-/******************************************************************************
- *****************************************************************************/
-DotFunction::LazyDotSequence::LazyDotSequence(
- const DotFunction* aFunc,
- ItemSequence* aArg)
- : theFunc(aFunc),
- theArg(aArg)
-{
-}
-
-/******************************************************************************
- *****************************************************************************/
-Iterator_t DotFunction::LazyDotSequence::getIterator()
-{
- return new DotFunction::LazyDotSequence::InternalIterator(this);
-}
-
-DotFunction::LazyDotSequence::InternalIterator::InternalIterator(LazyDotSequence *item_sequence) :
- theItemSequence(item_sequence), is_open(false)
-{
- arg_iter = item_sequence->theArg->getIterator();
-}
-
-void DotFunction::LazyDotSequence::InternalIterator::open()
-{
- is_open = true;
- arg_iter->open();
-}
-
-void DotFunction::LazyDotSequence::InternalIterator::close()
-{
- is_open = false;
- arg_iter->close();
-}
-
-bool DotFunction::LazyDotSequence::InternalIterator::isOpen() const
-{
- return is_open;
-}
-
-bool
-DotFunction::LazyDotSequence::InternalIterator::next(Item& aItem)
-{
- if(!is_open)
- {
- GraphvizFunction::throwErrorWithQName(theItemSequence->theFunc->theModule->getItemFactory(), "IM003", "DotFunction::LazyDotSequence Iterator consumed without open");
- }
- Item lItem;
- Agraph_t *lGraph = 0;
- String lGraphInput;
- GVC_t *lGvc = 0;
- std::ifstream lSVGFile;
-
- if (!arg_iter->next(lItem)) // exhausted
- return false;
-
- lGvc = gvContext();
-
- try {
- lGraphInput = lItem.getStringValue();
-
- lGraph = agmemread(const_cast<char*>(lGraphInput.c_str()));
- if (!lGraph) {
- GraphvizFunction::throwErrorWithQName(theItemSequence->theFunc->theModule->getItemFactory(), "IM003", "could not read input");
- }
-
- if ( gvLayout(lGvc, lGraph, const_cast<char*>("dot")) != 0 ) {
- GraphvizFunction::throwErrorWithQName(theItemSequence->theFunc->theModule->getItemFactory(), "IM003", "could not generate layout");
- }
-
- std::string lTmpFile = theItemSequence->theFunc->getGraphvizTmpFileName(theItemSequence->theFunc->theModule->getItemFactory());
-
- if ( gvRenderFilename(lGvc, lGraph, const_cast<char*>("svg"),
- const_cast<char*>(lTmpFile.c_str())) != 0 ) {
- GraphvizFunction::throwErrorWithQName(theItemSequence->theFunc->theModule->getItemFactory(), "IM003", "could not render graph");
- }
-
- lSVGFile.open(lTmpFile.c_str());
- if (lSVGFile.bad()) {
- std::ostringstream lErrorMsg;
- lErrorMsg << "could not read from file "
- << lTmpFile.c_str();
- GraphvizFunction::throwErrorWithQName(theItemSequence->theFunc->theModule->getItemFactory(), "IM003", lErrorMsg.str());
- }
-
- aItem = Zorba::getInstance(0)->getXmlDataManager()->parseXML(lSVGFile);
-
- gvFreeLayout(lGvc, lGraph);
- agclose(lGraph);
- gvFreeContext(lGvc);
-
- remove(lTmpFile.c_str());
- } catch (...) {
- aItem = NULL;
- if (lGraph) {
- gvFreeLayout(lGvc, lGraph);
- agclose(lGraph);
- }
- gvFreeContext(lGvc);
- throw;
- }
-
- return true;
-
-} /* DotFunction::LazyDotSequence::next */
-
-/******************************************************************************
- *****************************************************************************/
-Iterator_t GxlFunction::LazyGxlSequence::getIterator()
-{
- return new GxlFunction::LazyGxlSequence::InternalIterator(this);
-}
-
-GxlFunction::LazyGxlSequence::InternalIterator::InternalIterator(LazyGxlSequence *item_sequence) :
- theItemSequence(item_sequence), is_open(false)
-{
- arg_iter = item_sequence->theArg->getIterator();
-}
-
-void GxlFunction::LazyGxlSequence::InternalIterator::open()
-{
- is_open = true;
- arg_iter->open();
-}
-
-void GxlFunction::LazyGxlSequence::InternalIterator::close()
-{
- is_open = false;
- arg_iter->close();
-}
-
-bool GxlFunction::LazyGxlSequence::InternalIterator::isOpen() const
-{
- return is_open;
-}
-
-bool
-GxlFunction::LazyGxlSequence::InternalIterator::next(Item& aItem)
-{
- if(!is_open)
- {
- GraphvizFunction::throwErrorWithQName(theItemSequence->theFunc->theModule->getItemFactory(), "IM003", "GxlFunction::LazyGxlSequence Iterator consumed without open");
- }
- Item lItem;
- Agraph_t *lGraph = 0;
- GVC_t *lGvc = 0;
- std::fstream lSVGFile;
- FILE *lFile = 0;
-
- if (!arg_iter->next(lItem)) // exhausted
- return false;
-
- lGvc = gvContext();
-
- try {
-
- std::string lTmpFile = theItemSequence->theFunc->getGraphvizTmpFileName(theItemSequence->theFunc->theModule->getItemFactory());
- lSVGFile.open(lTmpFile.c_str(),
- std::fstream::in | std::fstream::out | std::fstream::trunc);
-
- gxl2dot(theItemSequence->theFunc->theModule->getItemFactory(), lItem, lSVGFile);
- lSVGFile.close();
-
- lFile = fopen(lTmpFile.c_str(), "r");
- if (!lFile) {
- std::ostringstream lErrorMsg;
- lErrorMsg << "could not read from file " << lTmpFile.c_str();
- GraphvizFunction::throwErrorWithQName(theItemSequence->theFunc->theModule->getItemFactory(), "IM003", lErrorMsg.str());
- }
-
- lGraph = agread(lFile);
- fclose(lFile);
-
- if (!lGraph) {
- GraphvizFunction::throwErrorWithQName(theItemSequence->theFunc->theModule->getItemFactory(), "IM003", "could not read input");
- }
-
- int blub = gvLayout(lGvc, lGraph, const_cast<char*>("dot"));
- if ( blub != 0 ) {
- GraphvizFunction::throwErrorWithQName(theItemSequence->theFunc->theModule->getItemFactory(), "IM003", "could not generate layout");
- }
-
- if ( gvRenderFilename(lGvc, lGraph, const_cast<char*>("svg"),
- const_cast<char*>(lTmpFile.c_str())) != 0 ) {
- GraphvizFunction::throwErrorWithQName(theItemSequence->theFunc->theModule->getItemFactory(), "IM003", "could not render graph");
- }
-
- lSVGFile.open(lTmpFile.c_str(), std::ifstream::in);
- if (lSVGFile.bad()) {
- std::ostringstream lErrorMsg;
- lErrorMsg << "could not read from file " << lTmpFile.c_str();
- GraphvizFunction::throwErrorWithQName(theItemSequence->theFunc->theModule->getItemFactory(), "IM003", lErrorMsg.str());
- }
-
- aItem = Zorba::getInstance(0)->getXmlDataManager()->parseXML(lSVGFile);
-
- gvFreeLayout(lGvc, lGraph);
- agclose(lGraph);
- gvFreeContext(lGvc);
-
- remove(lTmpFile.c_str());
- } catch (...) {
- if (lGraph) {
- gvFreeLayout(lGvc, lGraph);
- agclose(lGraph);
- }
- gvFreeContext(lGvc);
- throw;
- }
-
- return true;
-
-} /* GxlFunction::LazyGxlSequence::next */
-
-/******************************************************************************
- *****************************************************************************/
-GxlFunction::LazyGxlSequence::LazyGxlSequence(
- const GxlFunction* aFunc,
- ItemSequence* aArg)
- : theFunc(aFunc),
- theArg(aArg)
-{
-}
-
-/******************************************************************************
- *****************************************************************************/
-zorba::ItemSequence_t
-DotFunction::evaluate(
- const Arguments_t& aArgs,
- const zorba::StaticContext* aSctx,
- const zorba::DynamicContext *aDctx) const
-{
- return ItemSequence_t(new LazyDotSequence(this, aArgs[0]));
-} /* DotFunction::evaluate */
-
-/******************************************************************************
- *****************************************************************************/
-zorba::ItemSequence_t
-GxlFunction::evaluate(
- const Arguments_t& aArgs,
- const zorba::StaticContext* aSctx,
- const zorba::DynamicContext *aDctx) const
-{
- return ItemSequence_t(new LazyGxlSequence(this, aArgs[0]));
-} /* GxlFunction::evaluate */
-
-/******************************************************************************
- *****************************************************************************/
-ItemFactory* GraphvizModule::theFactory = 0;
-
-const char* GraphvizModule::theModule = "http://www.zorba-xquery.com/modules/image/graphviz";
-
-GraphvizModule::~GraphvizModule()
-{
- for (FuncMap_t::const_iterator lIter = theFunctions.begin();
- lIter != theFunctions.end(); ++lIter) {
- delete lIter->second;
- }
- theFunctions.clear();
-}
-
-ExternalFunction*
-GraphvizModule::getExternalFunction(const String& aLocalname)
-{
- ExternalFunction*& lFunc = theFunctions[aLocalname];
- if (!lFunc) {
- if (aLocalname == "dot")
- {
- lFunc = new DotFunction(this);
- } else if (aLocalname == "gxl")
- {
- lFunc = new GxlFunction(this);
- }
- }
- return lFunc;
-}
-
-void
-GraphvizModule::destroy()
-{
- if (!dynamic_cast<GraphvizModule*>(this)) {
- return;
- }
- delete this;
-}
-
- } /* namespace zorba */
-} /* namespace graphvizmodule */
-
-/******************************************************************************
- *****************************************************************************/
-#ifdef WIN32
-# define DLL_EXPORT __declspec(dllexport)
-#else
-# define DLL_EXPORT __attribute__ ((visibility("default")))
-#endif
-
-extern "C" DLL_EXPORT zorba::ExternalModule* createModule() {
- return new zorba::graphvizmodule::GraphvizModule();
-}
=== removed file 'src/com/zorba-xquery/www/modules/image/graphviz.xq.src/graphviz.h'
--- src/com/zorba-xquery/www/modules/image/graphviz.xq.src/graphviz.h 2012-07-20 20:25:12 +0000
+++ src/com/zorba-xquery/www/modules/image/graphviz.xq.src/graphviz.h 1970-01-01 00:00:00 +0000
@@ -1,234 +0,0 @@
-/*
- * Copyright 2006-2008 The FLWOR Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ZORBA_GRAPHVIZMODULE_GRAPHVIZ_H
-#define ZORBA_GRAPHVIZMODULE_GRAPHVIZ_H
-
-#include <map>
-
-#include <zorba/iterator.h>
-#include <zorba/zorba.h>
-#include <zorba/function.h>
-#include <zorba/external_module.h>
-
-namespace zorba
-{
-namespace graphvizmodule
-{
-
-class GraphvizModule;
-
-/******************************************************************************
- *****************************************************************************/
-class GraphvizFunction : public ContextualExternalFunction
-{
- protected:
- const GraphvizModule* theModule;
-
- GraphvizFunction(const GraphvizModule* aModule)
- : theModule(aModule) {}
-
- static std::string
- getGraphvizTmpFileName(zorba::ItemFactory* aFactory);
-
- static bool
- getAttribute(zorba::ItemFactory* aFactory,
- const char* attrname,
- const zorba::Item& elem,
- zorba::Item& attr);
-
- static void
- printTypeAndAttr(zorba::ItemFactory* aFactory,
- const zorba::Item& in,
- std::fstream& os);
-
- static void
- visitNode(zorba::ItemFactory* aFactory,
- const zorba::Item& in, std::fstream& os);
-
- static void
- visitEdge(zorba::ItemFactory* aFactory,
- const zorba::Item& in, std::fstream& os);
-
- static void
- printGraph(zorba::ItemFactory* aFactory,
- const zorba::Item& in, std::fstream& os);
-
- static void
- gxl2dot(zorba::ItemFactory* aFactory,
- const zorba::Item& in, std::fstream& os);
-
- static void
- throwErrorWithQName (zorba::ItemFactory* aFactory,
- const String& aLocalName,
- const String& aMessage);
-
- public:
-
- virtual String
- getURI() const;
-};
-
-/******************************************************************************
- *****************************************************************************/
-class DotFunction : public GraphvizFunction
-{
-public:
- DotFunction(const GraphvizModule* aModule)
- : GraphvizFunction(aModule) {}
-
- virtual ~DotFunction() {}
-
- virtual String
- getLocalName() const { return "dot"; }
-
- virtual zorba::ItemSequence_t
- evaluate(const Arguments_t&,
- const zorba::StaticContext*,
- const zorba::DynamicContext*) const;
-
-protected:
- class LazyDotSequence : public zorba::ItemSequence
- {
- class InternalIterator : public Iterator
- {
- private:
- LazyDotSequence *theItemSequence;
- Iterator_t arg_iter;
- bool is_open;
- public:
- InternalIterator(LazyDotSequence *item_sequence);
-
- virtual void open();
- virtual bool next(Item& aItem);
- virtual void close();
- virtual bool isOpen() const;
- };
- public:
- LazyDotSequence(const DotFunction*,
- ItemSequence* aArg);
-
- virtual Iterator_t getIterator();
-
- protected:
- const DotFunction* theFunc;
- ItemSequence* theArg;
- };
-};
-
-/******************************************************************************
- *****************************************************************************/
-class GxlFunction : public GraphvizFunction
-{
-public:
- GxlFunction(const GraphvizModule* aModule)
- : GraphvizFunction(aModule) {}
-
- virtual ~GxlFunction() {}
-
- virtual String
- getLocalName() const { return "gxl"; }
-
- virtual zorba::ItemSequence_t
- evaluate(const Arguments_t&,
- const zorba::StaticContext*,
- const zorba::DynamicContext*) const;
-
-protected:
- class LazyGxlSequence : public zorba::ItemSequence
- {
- class InternalIterator : public Iterator
- {
- private:
- LazyGxlSequence *theItemSequence;
- Iterator_t arg_iter;
- bool is_open;
- public:
- InternalIterator(LazyGxlSequence *item_sequence);
-
- virtual void open();
- virtual bool next(Item& aItem);
- virtual void close();
- virtual bool isOpen() const;
- };
- public:
- LazyGxlSequence(const GxlFunction*,
- ItemSequence* aArg);
-
- Iterator_t getIterator();
-
- protected:
- const GxlFunction* theFunc;
- ItemSequence* theArg;
- };
-};
-
-/******************************************************************************
- ******************************************************************************/
-class GraphvizModule : public ExternalModule
-{
-private:
- static ItemFactory* theFactory;
-
-protected:
- class ltstr
- {
- public:
-
-
- bool operator()(const String& s1, const String& s2) const
- {
- return s1.compare(s2) < 0;
- }
- };
-
- typedef std::map<String, ExternalFunction*, ltstr> FuncMap_t;
-
- FuncMap_t theFunctions;
-
-public:
-
- static const char* theModule;
-
- virtual ~GraphvizModule();
-
- virtual String
- getURI() const
- {
- return theModule;
- }
-
- virtual ExternalFunction*
- getExternalFunction(const String& aLocalname);
-
- virtual void
- destroy();
-
- static ItemFactory*
- getItemFactory()
- {
- if(!theFactory)
- {
- theFactory = Zorba::getInstance(0)->getItemFactory();
- }
- return theFactory;
- }
-};
-
-} /* namespace zorba */
-} /* namespace graphvizmodule */
-
-#endif
=== removed directory 'test_graphviz'
=== removed directory 'test_graphviz/ExpQueryResults'
=== removed file 'test_graphviz/ExpQueryResults/dot.xml.res'
--- test_graphviz/ExpQueryResults/dot.xml.res 2012-07-20 20:25:12 +0000
+++ test_graphviz/ExpQueryResults/dot.xml.res 1970-01-01 00:00:00 +0000
@@ -1,1 +0,0 @@
-true
\ No newline at end of file
=== removed directory 'test_graphviz/Queries'
=== removed file 'test_graphviz/Queries/dot.xq'
--- test_graphviz/Queries/dot.xq 2012-07-20 20:25:12 +0000
+++ test_graphviz/Queries/dot.xq 1970-01-01 00:00:00 +0000
@@ -1,3 +0,0 @@
-import module namespace dot = "http://www.zorba-xquery.com/modules/image/graphviz";
-
-fn:exists(dot:dot("digraph mygraph { p -> q }", ()))
\ No newline at end of file
Follow ups
-
[Merge] lp:~zorba-coders/zorba/image-module-alone into lp:zorba/image-module
From: noreply, 2012-08-04
-
[Merge] lp:~zorba-coders/zorba/image-module-alone into lp:zorba/image-module
From: Zorba Build Bot, 2012-08-04
-
[Merge] lp:~zorba-coders/zorba/image-module-alone into lp:zorba/image-module
From: Zorba Build Bot, 2012-08-04
-
[Merge] lp:~zorba-coders/zorba/image-module-alone into lp:zorba/image-module
From: Juan Zacarias, 2012-08-04
-
Re: [Merge] lp:~zorba-coders/zorba/image-module-alone into lp:zorba/image-module
From: Juan Zacarias, 2012-08-04
-
[Merge] lp:~zorba-coders/zorba/image-module-alone into lp:zorba/image-module
From: Zorba Build Bot, 2012-08-04
-
Re: [Merge] lp:~zorba-coders/zorba/image-module-alone into lp:zorba/image-module
From: Zorba Build Bot, 2012-08-04
-
[Merge] lp:~zorba-coders/zorba/image-module-alone into lp:zorba/image-module
From: Zorba Build Bot, 2012-08-04
-
[Merge] lp:~zorba-coders/zorba/image-module-alone into lp:zorba/image-module
From: Zorba Build Bot, 2012-08-04
-
[Merge] lp:~zorba-coders/zorba/image-module-alone into lp:zorba/image-module
From: Chris Hillery, 2012-08-04
-
[Merge] lp:~zorba-coders/zorba/image-module-alone into lp:zorba/image-module
From: Chris Hillery, 2012-08-04
-
Re: [Merge] lp:~zorba-coders/zorba/image-module-alone into lp:zorba/image-module
From: Chris Hillery, 2012-08-04