From 8726b833d44712cfb8e9b7764c90ee3bfd60641a Mon Sep 17 00:00:00 2001 From: Oreste Panaia Date: Fri, 28 Sep 2012 21:52:28 +0800 Subject: [PATCH] removed long static standard c++ string from header file --- .gitignore | 6 + config/js2c.sh | 2 +- js/server/js-ahuacatl.h | 4430 ++++++++++++++++++------------------ js/server/js-server.h | 1172 +++++----- lib/Scheduler/ListenTask.h | 8 +- 5 files changed, 2812 insertions(+), 2806 deletions(-) diff --git a/.gitignore b/.gitignore index 4475d80938..6f60d65a47 100644 --- a/.gitignore +++ b/.gitignore @@ -153,3 +153,9 @@ UnitTests/Philadelphia/Makefile.py UnitTests/Philadelphia/Runner.cpp .v8-build-* VC++ +VisualStudio/Arango Front End Library/Debug/* +VisualStudio/Arango MRuby Library/Debug/* +VisualStudio/Arango V8 Library/Debug/* +VisualStudio/ArangoDB/Debug/* +VisualStudio/Arangod Binary/Debug/* +VisualStudio/Debug/* diff --git a/config/js2c.sh b/config/js2c.sh index b0b9b145bf..2c9c2db27f 100755 --- a/config/js2c.sh +++ b/config/js2c.sh @@ -3,4 +3,4 @@ NAME=`echo $1 | sed -e 's:^\(.*/\)*js/\(.*\)\.js$:\2:' | tr "/-" "__"` cat $1 \ | sed -e 's:\(["\]\):\\\1:g' \ - | awk 'BEGIN {print "static string JS_'$NAME' = " } { print " \"" $0 "\\n\"" } END { print ";"}' + | awk 'BEGIN {print "static string JS_'$NAME' = string(\"\") " } { print " + \"" $0 "\\n\"" } END { print ";"}' diff --git a/js/server/js-ahuacatl.h b/js/server/js-ahuacatl.h index 4be387e424..de87c5a3aa 100644 --- a/js/server/js-ahuacatl.h +++ b/js/server/js-ahuacatl.h @@ -1,2216 +1,2216 @@ -static string JS_server_ahuacatl = - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief Ahuacatl, internal query functions \n" - "///\n" - "/// @file\n" - "///\n" - "/// DISCLAIMER\n" - "///\n" - "/// Copyright 2010-2012 triagens GmbH, Cologne, Germany\n" - "///\n" - "/// Licensed under the Apache License, Version 2.0 (the \"License\");\n" - "/// you may not use this file except in compliance with the License.\n" - "/// You may obtain a copy of the License at\n" - "///\n" - "/// http://www.apache.org/licenses/LICENSE-2.0\n" - "///\n" - "/// Unless required by applicable law or agreed to in writing, software\n" - "/// distributed under the License is distributed on an \"AS IS\" BASIS,\n" - "/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" - "/// See the License for the specific language governing permissions and\n" - "/// limitations under the License.\n" - "///\n" - "/// Copyright holder is triAGENS GmbH, Cologne, Germany\n" - "///\n" - "/// @author Jan Steemann\n" - "/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "var internal = require(\"internal\");\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief type weight used for sorting and comparing\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "var AHUACATL_TYPEWEIGHT_NULL = 0;\n" - "var AHUACATL_TYPEWEIGHT_BOOL = 1;\n" - "var AHUACATL_TYPEWEIGHT_NUMBER = 2;\n" - "var AHUACATL_TYPEWEIGHT_STRING = 4;\n" - "var AHUACATL_TYPEWEIGHT_LIST = 8;\n" - "var AHUACATL_TYPEWEIGHT_DOCUMENT = 16;\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- helper functions\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup Ahuacatl\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief throw a runtime exception\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_THROW (error, data) {\n" - " var err = new ArangoError\n" - "\n" - " err.errorNum = error.code;\n" - " if (data) {\n" - " err.errorMessage = error.message.replace(/%s/, data);\n" - " }\n" - " else {\n" - " err.errorMessage = error.message;\n" - " }\n" - "\n" - " throw err;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief find an index of a certain type for a collection\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_INDEX (collection, indexTypes) {\n" - " var indexes = collection.getIndexesNL();\n" - "\n" - " for (var i = 0; i < indexes.length; ++i) {\n" - " var index = indexes[i];\n" - "\n" - " for (var j = 0; j < indexTypes.length; ++j) {\n" - " if (index.type == indexTypes[j]) {\n" - " return index.id;\n" - " }\n" - " }\n" - " }\n" - "\n" - " return null;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief normalize a value for comparison, sorting etc.\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_NORMALIZE (value) {\n" - " if (value === null || value === undefined) {\n" - " return null;\n" - " }\n" - " if (typeof(value) !== \"object\") {\n" - " return value;\n" - " }\n" - "\n" - " if (Array.isArray(value)) {\n" - " var result = [ ];\n" - " var length = value.length;\n" - " for (var i = 0; i < length; ++i) {\n" - " result.push(AHUACATL_NORMALIZE(value[i]));\n" - " }\n" - " \n" - " return result;\n" - " } \n" - " else {\n" - " var attributes = [ ];\n" - " for (var attribute in value) {\n" - " if (!value.hasOwnProperty(attribute)) {\n" - " continue;\n" - " }\n" - " attributes.push(attribute);\n" - " }\n" - " attributes.sort();\n" - "\n" - " var result = { };\n" - " var length = attributes.length;\n" - " for (var i = 0; i < length; ++i) {\n" - " result[attributes[i]] = AHUACATL_NORMALIZE(value[attributes[i]]);\n" - " }\n" - "\n" - " return result;\n" - " }\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief clone an object\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_CLONE (obj) {\n" - " if (obj == null) {\n" - " return obj;\n" - " }\n" - "\n" - " if (typeof(obj) != \"object\") {\n" - " return obj;\n" - " }\n" - "\n" - " if (Array.isArray(obj)) {\n" - " var copy = [];\n" - " var length = obj.length;\n" - " for (var i = 0; i < length; ++i) {\n" - " copy[i] = AHUACATL_CLONE(obj[i]);\n" - " }\n" - " return copy;\n" - " }\n" - "\n" - " if (obj instanceof Object) {\n" - " var copy = {};\n" - " for (var attr in obj) {\n" - " if (obj.hasOwnProperty(attr)) {\n" - " copy[attr] = AHUACATL_CLONE(obj[attr]);\n" - " }\n" - " }\n" - " return copy;\n" - " }\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief validate function call argument\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_ARG_CHECK (actualValue, expectedType, functionName) {\n" - " if (AHUACATL_TYPEWEIGHT(actualValue) !== expectedType) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, functionName);\n" - " }\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief call a function\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_FCALL (name, parameters) {\n" - " return name.apply(null, parameters);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief return the numeric value or undefined if it is out of range\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_NUMERIC_VALUE (value) {\n" - " if (isNaN(value) || !isFinite(value)) {\n" - " return null;\n" - " }\n" - "\n" - " return value;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief fix a value for a comparison\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_FIX (value) {\n" - " if (value === undefined) {\n" - " return null;\n" - " }\n" - "\n" - " return value;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief get the name for a type\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_TYPENAME (value) {\n" - " switch (value) {\n" - " case AHUCATL_TYPEWEIGHT_BOOL:\n" - " return 'boolean';\n" - " case AHUCATL_TYPEWEIGHT_NUMBER:\n" - " return 'number';\n" - " case AHUCATL_TYPEWEIGHT_STRING:\n" - " return 'string';\n" - " case AHUCATL_TYPEWEIGHT_LIST:\n" - " return 'list';\n" - " case AHUCATL_TYPEWEIGHT_DOCUMENT:\n" - " return 'document';\n" - " case AHUCATL_TYPEWEIGHT_NULL:\n" - " default:\n" - " return 'null';\n" - " }\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief get the sort type of an operand\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_TYPEWEIGHT (value) {\n" - " if (value === undefined || value === null) {\n" - " return AHUACATL_TYPEWEIGHT_NULL;\n" - " }\n" - "\n" - " if (Array.isArray(value)) {\n" - " return AHUACATL_TYPEWEIGHT_LIST;\n" - " }\n" - "\n" - " switch (typeof(value)) {\n" - " case 'boolean':\n" - " return AHUACATL_TYPEWEIGHT_BOOL;\n" - " case 'number':\n" - " if (isNaN(value) || !isFinite(value)) {\n" - " // not a number => undefined\n" - " return AHUACATL_TYPEWEIGHT_NULL; \n" - " }\n" - " return AHUACATL_TYPEWEIGHT_NUMBER;\n" - " case 'string':\n" - " return AHUACATL_TYPEWEIGHT_STRING;\n" - " case 'object':\n" - " return AHUACATL_TYPEWEIGHT_DOCUMENT;\n" - " }\n" - "\n" - " return AHUACATL_TYPEWEIGHT_NULL;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief get the keys of an array or object in a comparable way\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_KEYS (value, doSort) {\n" - " var keys = [];\n" - " \n" - " if (Array.isArray(value)) {\n" - " var n = value.length;\n" - " for (var j = 0; j < n; ++j) {\n" - " keys.push(j);\n" - " }\n" - " }\n" - " else {\n" - " for (var k in value) {\n" - " if (value.hasOwnProperty(k)) {\n" - " keys.push(k);\n" - " }\n" - " }\n" - "\n" - " if (doSort) {\n" - " // object keys need to be sorted by names\n" - " keys.sort();\n" - " }\n" - " }\n" - "\n" - " return keys;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief get the keys of an array or object in a comparable way\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_KEYLIST (lhs, rhs) {\n" - " var keys = [];\n" - " \n" - " if (Array.isArray(lhs)) {\n" - " // lhs & rhs are lists\n" - " var n;\n" - " if (lhs.length > rhs.length) {\n" - " n = lhs.length;\n" - " }\n" - " else {\n" - " n = rhs.length;\n" - " }\n" - " for (var j = 0; j < n; ++j) {\n" - " keys.push(j);\n" - " }\n" - " return keys;\n" - " }\n" - "\n" - " // lhs & rhs are arrays\n" - " var k;\n" - " for (k in lhs) {\n" - " keys.push(k);\n" - " }\n" - " for (k in rhs) {\n" - " if (lhs.hasOwnProperty(k)) {\n" - " continue;\n" - " }\n" - " keys.push(k);\n" - " }\n" - "\n" - " // object keys need to be sorted by names\n" - " keys.sort();\n" - "\n" - " return keys;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief get an indexed value from an array or document (e.g. users[3])\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_GET_INDEX (value, index) {\n" - " if (AHUACATL_TYPEWEIGHT(value) == AHUACATL_TYPEWEIGHT_NULL) {\n" - " return null;\n" - " }\n" - " \n" - " if (AHUACATL_TYPEWEIGHT(value) != AHUACATL_TYPEWEIGHT_LIST &&\n" - " AHUACATL_TYPEWEIGHT(value) != AHUACATL_TYPEWEIGHT_DOCUMENT) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_LIST_EXPECTED);\n" - " }\n" - "\n" - " var result = value[index];\n" - "\n" - " if (AHUACATL_TYPEWEIGHT(result) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " return null;\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief get an attribute from a document (e.g. users.name)\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_DOCUMENT_MEMBER (value, attributeName) {\n" - " if (AHUACATL_TYPEWEIGHT(value) == AHUACATL_TYPEWEIGHT_NULL) {\n" - " return null;\n" - " }\n" - "\n" - " if (AHUACATL_TYPEWEIGHT(value) != AHUACATL_TYPEWEIGHT_DOCUMENT) {\n" - " return null;\n" - " }\n" - "\n" - " var result = value[attributeName];\n" - "\n" - " if (AHUACATL_TYPEWEIGHT(result) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " return null;\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief assert that a value is a list, fail otherwise\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_LIST (value) {\n" - " if (AHUACATL_TYPEWEIGHT(value) !== AHUACATL_TYPEWEIGHT_LIST) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_LIST_EXPECTED);\n" - " }\n" - "\n" - " return value;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief get all documents from the specified collection\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_GET_DOCUMENTS (collection) {\n" - " return internal.db[collection].ALL_NL(0, null).documents;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief get documents from the specified collection using the primary index\n" - "/// (single index value)\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_GET_DOCUMENTS_PRIMARY (collection, idx, id) {\n" - " try {\n" - " return [ internal.db[collection].document_nl(id) ];\n" - " }\n" - " catch (e) {\n" - " return [ ];\n" - " }\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief get documents from the specified collection using the primary index\n" - "/// (multiple index values)\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_GET_DOCUMENTS_PRIMARY_LIST (collection, idx, values) {\n" - " var result = [ ];\n" - "\n" - " for (var i in values) {\n" - " var id = values[i];\n" - " try {\n" - " var d = internal.db[collection].document_nl(id);\n" - " result.push(d);\n" - " }\n" - " catch (e) {\n" - " }\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief get documents from the specified collection using a hash index\n" - "/// (single index value)\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_GET_DOCUMENTS_HASH (collection, idx, example) {\n" - " return internal.db[collection].BY_EXAMPLE_HASH_NL(idx, example).documents;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief get documents from the specified collection using a hash index\n" - "/// (multiple index values)\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_GET_DOCUMENTS_HASH_LIST (collection, idx, attribute, values) {\n" - " var result = [ ];\n" - "\n" - " for (var i in values) {\n" - " var value = values[i];\n" - " var example = { };\n" - "\n" - " example[attribute] = value;\n" - "\n" - " var documents = internal.db[collection].BY_EXAMPLE_HASH_NL(idx, example).documents;\n" - " for (var j in documents) {\n" - " result.push(documents[j]);\n" - " }\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief get documents from the specified collection using a bitarray\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_GET_DOCUMENTS_BITARRAY (collection, idx, example) {\n" - " return internal.db[collection].BY_CONDITION_BITARRAY(idx, example).documents;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief get documents from the specified collection using a bitarray\n" - "/// (multiple index values) TODO: replace by 'IN index operator'\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_GET_DOCUMENTS_BITARRAY_LIST (collection, idx, attribute, values) {\n" - " var result = [ ];\n" - "\n" - " for (var i in values) {\n" - " var value = values[i];\n" - " var example = { };\n" - "\n" - " example[attribute] = value;\n" - "\n" - " var documents = internal.db[collection].BY_EXAMPLE_BITARRAY(idx, example).documents;\n" - " for (var j in documents) {\n" - " result.push(documents[j]);\n" - " }\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "\n" - "\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief get documents from the specified collection using a skiplist\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_GET_DOCUMENTS_SKIPLIST (collection, idx, example) {\n" - " return internal.db[collection].BY_CONDITION_SKIPLIST_NL(idx, example).documents;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief get documents from the specified collection using a skiplist\n" - "/// (multiple index values)\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_GET_DOCUMENTS_SKIPLIST_LIST (collection, idx, attribute, values) {\n" - " var result = [ ];\n" - "\n" - " for (var i in values) {\n" - " var value = values[i];\n" - " var example = { };\n" - "\n" - " example[attribute] = value;\n" - "\n" - " var documents = internal.db[collection].BY_EXAMPLE_SKIPLIST_NL(idx, example).documents;\n" - " for (var j in documents) {\n" - " result.push(documents[j]);\n" - " }\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief get names of all collections\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_COLLECTIONS () {\n" - " var collections = internal.db._collections();\n" - " var result = [ ];\n" - "\n" - " for (var i = 0; i < collections.length; ++i) {\n" - " result.push({ \"_id\" : collections[i]._id, \"name\" : collections[i].name() });\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- logical operations\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup Ahuacatl\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief execute ternary operator\n" - "///\n" - "/// the condition operand must be a boolean value, returns either the truepart\n" - "/// or the falsepart \n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_TERNARY_OPERATOR (condition, truePart, falsePart) {\n" - " if (AHUACATL_TYPEWEIGHT(condition) !== AHUACATL_TYPEWEIGHT_BOOL) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_LOGICAL_VALUE);\n" - " }\n" - "\n" - " if (condition) {\n" - " return truePart;\n" - " }\n" - " return falsePart;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform logical and\n" - "///\n" - "/// both operands must be boolean values, returns a boolean, uses short-circuit\n" - "/// evaluation\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_LOGICAL_AND (lhs, rhs) {\n" - " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_BOOL ||\n" - " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_BOOL) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_LOGICAL_VALUE);\n" - " }\n" - "\n" - " if (!lhs) {\n" - " return false;\n" - " }\n" - "\n" - " return rhs;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform logical or\n" - "///\n" - "/// both operands must be boolean values, returns a boolean, uses short-circuit\n" - "/// evaluation\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_LOGICAL_OR (lhs, rhs) {\n" - " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_BOOL ||\n" - " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_BOOL) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_LOGICAL_VALUE);\n" - " }\n" - " \n" - " if (lhs) {\n" - " return true;\n" - " }\n" - "\n" - " return rhs;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform logical negation\n" - "///\n" - "/// the operand must be a boolean values, returns a boolean\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_LOGICAL_NOT (lhs) {\n" - " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_BOOL) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_LOGICAL_VALUE);\n" - " }\n" - "\n" - " return !lhs;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- comparison operations\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup Ahuacatl\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform equality check \n" - "///\n" - "/// returns true if the operands are equal, false otherwise\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_RELATIONAL_EQUAL (lhs, rhs) {\n" - " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" - " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" - "\n" - " if (leftWeight != rightWeight) {\n" - " return false;\n" - " }\n" - "\n" - " // lhs and rhs have the same type\n" - "\n" - " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" - " // arrays and objects\n" - " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" - "\n" - " for (var i in keys) {\n" - " var key = keys[i];\n" - " var result = AHUACATL_RELATIONAL_EQUAL(lhs[key], rhs[key]);\n" - " if (result === false) {\n" - " return result;\n" - " }\n" - " }\n" - " return true;\n" - " }\n" - "\n" - " // primitive type\n" - " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " lhs = null;\n" - " }\n" - " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " rhs = null;\n" - " }\n" - "\n" - " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" - " return COMPARE_STRING(lhs, rhs) == 0;\n" - " }\n" - "\n" - " return (lhs === rhs);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform inequality check \n" - "///\n" - "/// returns true if the operands are unequal, false otherwise\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_RELATIONAL_UNEQUAL (lhs, rhs) {\n" - " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" - " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" - " \n" - " if (leftWeight != rightWeight) {\n" - " return true;\n" - " }\n" - "\n" - " // lhs and rhs have the same type\n" - "\n" - " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" - " // arrays and objects\n" - " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" - "\n" - " for (var i in keys) {\n" - " var key = keys[i];\n" - " var result = AHUACATL_RELATIONAL_UNEQUAL(lhs[key], rhs[key]);\n" - " if (result === true) {\n" - " return result;\n" - " }\n" - " }\n" - "\n" - " return false;\n" - " }\n" - "\n" - " // primitive type\n" - " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " lhs = null;\n" - " }\n" - " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " rhs = null;\n" - " }\n" - "\n" - " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" - " return COMPARE_STRING(lhs, rhs) != 0;\n" - " }\n" - "\n" - " return (lhs !== rhs);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform greater than check (inner function)\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_RELATIONAL_GREATER_REC (lhs, rhs) {\n" - " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" - " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" - " \n" - " if (leftWeight > rightWeight) {\n" - " return true;\n" - " }\n" - " if (leftWeight < rightWeight) {\n" - " return false;\n" - " }\n" - "\n" - " // lhs and rhs have the same type\n" - "\n" - " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" - " // arrays and objects\n" - " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" - "\n" - " for (var i in keys) {\n" - " var key = keys[i];\n" - " var result = AHUACATL_RELATIONAL_GREATER_REC(lhs[key], rhs[key]);\n" - " if (result !== null) {\n" - " return result;\n" - " }\n" - " }\n" - " \n" - " return null;\n" - " }\n" - "\n" - " // primitive type\n" - " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " lhs = null;\n" - " }\n" - " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " rhs = null;\n" - " }\n" - "\n" - " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" - " return COMPARE_STRING(lhs, rhs) > 0;\n" - " }\n" - "\n" - " if (lhs === rhs) {\n" - " return null;\n" - " }\n" - "\n" - " return (lhs > rhs);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform greater than check \n" - "///\n" - "/// returns true if the left operand is greater than the right operand\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_RELATIONAL_GREATER (lhs, rhs) {\n" - " var result = AHUACATL_RELATIONAL_GREATER_REC(lhs, rhs);\n" - "\n" - " if (result === null) {\n" - " result = false;\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform greater equal check (inner function)\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_RELATIONAL_GREATEREQUAL_REC (lhs, rhs) {\n" - " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" - " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" - " \n" - " if (leftWeight > rightWeight) {\n" - " return true;\n" - " }\n" - " if (leftWeight < rightWeight) {\n" - " return false;\n" - " }\n" - "\n" - " // lhs and rhs have the same type\n" - "\n" - " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" - " // arrays and objects\n" - " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" - "\n" - " for (var i in keys) {\n" - " var key = keys[i];\n" - " var result = AHUACATL_RELATIONAL_GREATEREQUAL_REC(lhs[key], rhs[key]);\n" - " if (result !== null) {\n" - " return result;\n" - " }\n" - " }\n" - " \n" - " return null;\n" - " }\n" - "\n" - " // primitive type\n" - " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " lhs = null;\n" - " }\n" - " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " rhs = null;\n" - " }\n" - "\n" - " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" - " return COMPARE_STRING(lhs, rhs) >= 0;\n" - " }\n" - "\n" - " if (lhs === rhs) {\n" - " return null;\n" - " }\n" - "\n" - " return (lhs >= rhs);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform greater equal check \n" - "///\n" - "/// returns true if the left operand is greater or equal to the right operand\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_RELATIONAL_GREATEREQUAL (lhs, rhs) {\n" - " var result = AHUACATL_RELATIONAL_GREATEREQUAL_REC(lhs, rhs);\n" - "\n" - " if (result === null) {\n" - " result = true;\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform less than check (inner function)\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_RELATIONAL_LESS_REC (lhs, rhs) {\n" - " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" - " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" - " \n" - " if (leftWeight < rightWeight) {\n" - " return true;\n" - " }\n" - " if (leftWeight > rightWeight) {\n" - " return false;\n" - " }\n" - "\n" - " // lhs and rhs have the same type\n" - "\n" - " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" - " // arrays and objects\n" - " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" - "\n" - " for (var i in keys) {\n" - " var key = keys[i];\n" - " var result = AHUACATL_RELATIONAL_LESS_REC(lhs[key], rhs[key]);\n" - " if (result !== null) {\n" - " return result;\n" - " }\n" - " }\n" - " \n" - " return null;\n" - " }\n" - "\n" - " // primitive type\n" - " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " lhs = null;\n" - " }\n" - " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " rhs = null;\n" - " }\n" - "\n" - " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" - " return COMPARE_STRING(lhs, rhs) < 0;\n" - " }\n" - "\n" - " if (lhs === rhs) {\n" - " return null;\n" - " }\n" - "\n" - " return (lhs < rhs);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform less than check \n" - "///\n" - "/// returns true if the left operand is less than the right operand\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_RELATIONAL_LESS (lhs, rhs) {\n" - " var result = AHUACATL_RELATIONAL_LESS_REC(lhs, rhs);\n" - "\n" - " if (result === null) {\n" - " result = false;\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform less equal check (inner function)\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_RELATIONAL_LESSEQUAL_REC (lhs, rhs) {\n" - " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" - " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" - " \n" - " if (leftWeight < rightWeight) {\n" - " return true;\n" - " }\n" - " if (leftWeight > rightWeight) {\n" - " return false;\n" - " }\n" - "\n" - " // lhs and rhs have the same type\n" - "\n" - " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" - " // arrays and objects\n" - " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" - "\n" - " for (var i in keys) {\n" - " var key = keys[i];\n" - " var result = AHUACATL_RELATIONAL_LESSEQUAL_REC(lhs[key], rhs[key]);\n" - " if (result !== null) {\n" - " return result;\n" - " }\n" - " }\n" - "\n" - " return null;\n" - " }\n" - " \n" - " // primitive type\n" - " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " lhs = null;\n" - " }\n" - " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " rhs = null;\n" - " }\n" - " \n" - " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" - " return COMPARE_STRING(lhs, rhs) <= 0;\n" - " }\n" - " \n" - " if (lhs === rhs) {\n" - " return null;\n" - " }\n" - "\n" - " return (lhs <= rhs);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform less equal check \n" - "///\n" - "/// returns true if the left operand is less or equal to the right operand\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_RELATIONAL_LESSEQUAL (lhs, rhs) {\n" - " var result = AHUACATL_RELATIONAL_LESSEQUAL_REC(lhs, rhs);\n" - "\n" - " if (result === null) {\n" - " result = true;\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform comparison\n" - "///\n" - "/// returns -1 if the left operand is less than the right operand, 1 if it is\n" - "/// greater, 0 if both operands are equal\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_RELATIONAL_CMP (lhs, rhs) {\n" - " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" - " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" - " \n" - " if (leftWeight < rightWeight) {\n" - " return -1;\n" - " }\n" - " if (leftWeight > rightWeight) {\n" - " return 1;\n" - " }\n" - "\n" - " // lhs and rhs have the same type\n" - "\n" - " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" - " // arrays and objects\n" - " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" - "\n" - " for (var i in keys) {\n" - " var key = keys[i];\n" - " var result = AHUACATL_RELATIONAL_CMP(lhs[key], rhs[key]);\n" - " if (result !== 0) {\n" - " return result;\n" - " }\n" - " }\n" - " \n" - " return 0;\n" - " }\n" - "\n" - " // primitive type\n" - " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " lhs = null;\n" - " }\n" - " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " rhs = null;\n" - " }\n" - "\n" - " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" - " return COMPARE_STRING(lhs, rhs);\n" - " }\n" - "\n" - " if (lhs < rhs) {\n" - " return -1;\n" - " }\n" - " \n" - " if (lhs > rhs) {\n" - " return 1;\n" - " }\n" - "\n" - " return 0;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform in list check \n" - "///\n" - "/// returns true if the left operand is contained in the right operand\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_RELATIONAL_IN (lhs, rhs) {\n" - " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" - " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" - " \n" - " if (rightWeight !== AHUACATL_TYPEWEIGHT_LIST) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_LIST_EXPECTED);\n" - " }\n" - "\n" - " var numRight = rhs.length;\n" - " for (var i = 0; i < numRight; ++i) {\n" - " if (AHUACATL_RELATIONAL_EQUAL(lhs, rhs[i])) {\n" - " return true;\n" - " }\n" - " }\n" - "\n" - " return false;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- arithmetic operations\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup Ahuacatl\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform unary plus operation\n" - "///\n" - "/// the operand must be numeric or this function will fail\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_UNARY_PLUS (value) {\n" - " if (AHUACATL_TYPEWEIGHT(value) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" - " }\n" - "\n" - " var result = AHUACATL_NUMERIC_VALUE(value);\n" - " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform unary minus operation\n" - "///\n" - "/// the operand must be numeric or this function will fail\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_UNARY_MINUS (value) {\n" - " if (AHUACATL_TYPEWEIGHT(value) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" - " }\n" - "\n" - " var result = AHUACATL_NUMERIC_VALUE(-value);\n" - " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform artithmetic plus\n" - "///\n" - "/// both operands must be numeric or this function will fail\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_ARITHMETIC_PLUS (lhs, rhs) { \n" - " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||\n" - " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" - " }\n" - "\n" - " var result = AHUACATL_NUMERIC_VALUE(lhs + rhs);\n" - " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform artithmetic minus\n" - "///\n" - "/// both operands must be numeric or this function will fail\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_ARITHMETIC_MINUS (lhs, rhs) {\n" - " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||\n" - " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" - " }\n" - "\n" - " var result = AHUACATL_NUMERIC_VALUE(lhs - rhs);\n" - " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform artithmetic multiplication\n" - "///\n" - "/// both operands must be numeric or this function will fail\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_ARITHMETIC_TIMES (lhs, rhs) {\n" - " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||\n" - " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" - " }\n" - "\n" - " var result = AHUACATL_NUMERIC_VALUE(lhs * rhs);\n" - " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform artithmetic division\n" - "///\n" - "/// both operands must be numeric or this function will fail\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_ARITHMETIC_DIVIDE (lhs, rhs) {\n" - " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||\n" - " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" - " }\n" - " \n" - " if (rhs == 0) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_DIVISION_BY_ZERO);\n" - " }\n" - "\n" - " var result = AHUACATL_NUMERIC_VALUE(lhs / rhs);\n" - " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform artithmetic modulus\n" - "///\n" - "/// both operands must be numeric or this function will fail\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_ARITHMETIC_MODULUS (lhs, rhs) {\n" - " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||\n" - " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" - " }\n" - "\n" - " if (rhs == 0) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_DIVISION_BY_ZERO);\n" - " }\n" - "\n" - " var result = AHUACATL_NUMERIC_VALUE(lhs % rhs);\n" - " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- string functions\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup Ahuacatl\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform string concatenation\n" - "///\n" - "/// all operands must be strings or this function will fail\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_STRING_CONCAT () {\n" - " var result = '';\n" - "\n" - " for (var i in arguments) {\n" - " var element = arguments[i];\n" - "\n" - " if (AHUACATL_TYPEWEIGHT(element) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " continue;\n" - " }\n" - "\n" - " AHUACATL_ARG_CHECK(element, AHUACATL_TYPEWEIGHT_STRING, \"CONCAT\");\n" - "\n" - " result += element;\n" - " }\n" - "\n" - " return result; \n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief perform string concatenation using a separator character\n" - "///\n" - "/// all operands must be strings or this function will fail\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_STRING_CONCAT_SEPARATOR () {\n" - " var separator;\n" - " var found = false;\n" - " var result = '';\n" - "\n" - " for (var i in arguments) {\n" - " var element = arguments[i];\n" - "\n" - " if (i > 0 && AHUACATL_TYPEWEIGHT(element) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " continue;\n" - " }\n" - " \n" - " AHUACATL_ARG_CHECK(element, AHUACATL_TYPEWEIGHT_STRING, \"CONCAT_SEPARATOR\");\n" - "\n" - " if (i == 0) {\n" - " separator = element;\n" - " continue;\n" - " }\n" - " else if (found) {\n" - " result += separator;\n" - " }\n" - "\n" - " found = true;\n" - "\n" - " result += element;\n" - " }\n" - "\n" - " return result; \n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief return the length of a string in characters (not bytes)\n" - "///\n" - "/// the input operand must be a string or this function will fail\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_STRING_LENGTH (value) {\n" - " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"STRING_LENGTH\");\n" - "\n" - " return value.length;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief convert a string to lower case\n" - "///\n" - "/// the input operand must be a string or this function will fail\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_STRING_LOWER (value) {\n" - " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"LOWER\");\n" - "\n" - " return value.toLowerCase();\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief convert a string to upper case\n" - "///\n" - "/// the input operand must be a string or this function will fail\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_STRING_UPPER (value) {\n" - " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"UPPER\");\n" - "\n" - " return value.toUpperCase();\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief return a substring of the string\n" - "///\n" - "/// the input operand must be a string or this function will fail\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_STRING_SUBSTRING (value, offset, count) {\n" - " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"SUBSTRING\");\n" - " AHUACATL_ARG_CHECK(offset, AHUACATL_TYPEWEIGHT_NUMBER, \"SUBSTRING\");\n" - "\n" - " return value.substr(offset, count);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief searches a substring in a string\n" - "///\n" - "/// the two input operands must be strings or this function will fail\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_STRING_CONTAINS (value, search) {\n" - " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"CONTAINS\");\n" - " AHUACATL_ARG_CHECK(search, AHUACATL_TYPEWEIGHT_STRING, \"CONTAINS\");\n" - "\n" - " if (search.length == 0) {\n" - " return false;\n" - " }\n" - "\n" - " return value.indexOf(search) != -1;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- typecast functions\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup Ahuacatl\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief cast to a bool\n" - "///\n" - "/// the operand can have any type, always returns a bool\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_CAST_BOOL (value) {\n" - " switch (AHUACATL_TYPEWEIGHT(value)) {\n" - " case AHUACATL_TYPEWEIGHT_NULL:\n" - " return false;\n" - " case AHUACATL_TYPEWEIGHT_BOOL:\n" - " return value;\n" - " case AHUACATL_TYPEWEIGHT_NUMBER:\n" - " return (value != 0);\n" - " case AHUACATL_TYPEWEIGHT_STRING: \n" - " return (value !== '');\n" - " case AHUACATL_TYPEWEIGHT_LIST:\n" - " return (value.length > 0);\n" - " case AHUACATL_TYPEWEIGHT_DOCUMENT:\n" - " return (AHUACATL_KEYS(value, false).length > 0);\n" - " }\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief cast to a number\n" - "///\n" - "/// the operand can have any type, always returns a number\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_CAST_NUMBER (value) {\n" - " switch (AHUACATL_TYPEWEIGHT(value)) {\n" - " case AHUACATL_TYPEWEIGHT_NULL:\n" - " case AHUACATL_TYPEWEIGHT_LIST:\n" - " case AHUACATL_TYPEWEIGHT_DOCUMENT:\n" - " return 0.0;\n" - " case AHUACATL_TYPEWEIGHT_BOOL:\n" - " return (value ? 1 : 0);\n" - " case AHUACATL_TYPEWEIGHT_NUMBER:\n" - " return value;\n" - " case AHUACATL_TYPEWEIGHT_STRING:\n" - " var result = parseFloat(value);\n" - " return ((AHUACATL_TYPEWEIGHT(result) === AHUACATL_TYPEWEIGHT_NUMBER) ? result : 0);\n" - " }\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief cast to a string\n" - "///\n" - "/// the operand can have any type, always returns a string\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_CAST_STRING (value) {\n" - " switch (AHUACATL_TYPEWEIGHT(value)) {\n" - " case AHUACATL_TYPEWEIGHT_STRING:\n" - " return value;\n" - " case AHUACATL_TYPEWEIGHT_NULL:\n" - " return 'null';\n" - " case AHUACATL_TYPEWEIGHT_BOOL:\n" - " return (value ? 'true' : 'false');\n" - " case AHUACATL_TYPEWEIGHT_NUMBER:\n" - " case AHUACATL_TYPEWEIGHT_LIST:\n" - " case AHUACATL_TYPEWEIGHT_DOCUMENT:\n" - " return value.toString();\n" - " }\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- typecheck functions\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup Ahuacatl\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief test if value is of type null\n" - "///\n" - "/// returns a bool\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_IS_NULL (value) {\n" - " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_NULL);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief test if value is of type bool\n" - "///\n" - "/// returns a bool\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_IS_BOOL (value) {\n" - " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_BOOL);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief test if value is of type number\n" - "///\n" - "/// returns a bool\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_IS_NUMBER (value) {\n" - " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_NUMBER);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief test if value is of type string\n" - "///\n" - "/// returns a bool\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_IS_STRING (value) {\n" - " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_STRING);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief test if value is of type list\n" - "///\n" - "/// returns a bool\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_IS_LIST (value) {\n" - " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_LIST);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief test if value is of type document\n" - "///\n" - "/// returns a bool\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_IS_DOCUMENT (value) {\n" - " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_DOCUMENT);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- numeric functions\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup Ahuacatl\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief integer closest to value, not greater than value\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_NUMBER_FLOOR (value) {\n" - " if (!AHUACATL_IS_NUMBER(value)) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"FLOOR\");\n" - " }\n" - " \n" - " return Math.floor(value);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief integer closest to value and not less than value\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_NUMBER_CEIL (value) {\n" - " if (!AHUACATL_IS_NUMBER(value)) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"CEIL\");\n" - " }\n" - " \n" - " return Math.ceil(value);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief integer closest to value \n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_NUMBER_ROUND (value) {\n" - " if (!AHUACATL_IS_NUMBER(value)) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"ROUND\");\n" - " }\n" - " \n" - " return Math.round(value);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief absolute value\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_NUMBER_ABS (value) {\n" - " if (!AHUACATL_IS_NUMBER(value)) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"ABS\");\n" - " }\n" - " \n" - " return Math.abs(value);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief a random value between 0 and 1\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_NUMBER_RAND () {\n" - " return Math.random();\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- high level query functions\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup Ahuacatl\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief sort the results\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_SORT (value, sortFunction) {\n" - " AHUACATL_LIST(value);\n" - " \n" - " var n = value.length;\n" - " if (n > 0) {\n" - " value.sort(sortFunction);\n" - " }\n" - "\n" - " return value;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief group the results\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_GROUP (value, sortFunction, groupFunction, into) {\n" - " AHUACATL_LIST(value);\n" - "\n" - " var n = value.length;\n" - " if (n == 0) {\n" - " return [ ];\n" - " }\n" - "\n" - " AHUACATL_SORT(value, sortFunction);\n" - "\n" - " var result = [ ];\n" - " var currentGroup = undefined;\n" - " var oldGroup = undefined;\n" - " \n" - " for (var i = 0; i < n; ++i) {\n" - " var row = value[i];\n" - " var groupValue = groupFunction(row);\n" - "\n" - " if (AHUACATL_RELATIONAL_UNEQUAL(oldGroup, groupValue)) {\n" - " oldGroup = AHUACATL_CLONE(groupValue);\n" - "\n" - " if (currentGroup) {\n" - " result.push(AHUACATL_CLONE(currentGroup));\n" - " }\n" - " \n" - " currentGroup = groupValue;\n" - " if (into) {\n" - " currentGroup[into] = [ ];\n" - " }\n" - " }\n" - "\n" - " if (into) {\n" - " currentGroup[into].push(AHUACATL_CLONE(row));\n" - " }\n" - " }\n" - "\n" - " if (currentGroup) {\n" - " result.push(AHUACATL_CLONE(currentGroup));\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief limit the number of results\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_LIMIT (value, offset, count) {\n" - " AHUACATL_LIST(value);\n" - "\n" - " if (count < 0) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" - " }\n" - "\n" - " return value.slice(offset, offset + count);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- list processing functions\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup Ahuacatl\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief get the length of a list\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_LENGTH () {\n" - " var value = arguments[0];\n" - "\n" - " AHUACATL_LIST(value);\n" - "\n" - " return value.length;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief get the first element of a list\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_FIRST () {\n" - " var value = arguments[0];\n" - "\n" - " AHUACATL_LIST(value);\n" - "\n" - " if (value.length == 0) {\n" - " return null;\n" - " }\n" - "\n" - " return value[0];\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief get the last element of a list\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_LAST () {\n" - " var value = arguments[0];\n" - "\n" - " AHUACATL_LIST(value);\n" - "\n" - " if (value.length == 0) {\n" - " return null;\n" - " }\n" - "\n" - " return value[value.length - 1];\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief reverse the elements in a list\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_REVERSE () {\n" - " var value = arguments[0];\n" - "\n" - " AHUACATL_LIST(value);\n" - "\n" - " return value.reverse();\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief return a list of unique elements from the list\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_UNIQUE () {\n" - " var value = arguments[0];\n" - "\n" - " AHUACATL_LIST(value);\n" - "\n" - " var length = value.length;\n" - " var keys = { };\n" - " for (var i = 0; i < length; ++i) {\n" - " var normalized = AHUACATL_NORMALIZE(value[i]);\n" - " keys[JSON.stringify(normalized)] = normalized;\n" - " }\n" - "\n" - " var result = [];\n" - " for (var i in keys) {\n" - " result.push(keys[i]);\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief create the union (all) of all arguments\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_UNION () {\n" - " var result = [ ];\n" - "\n" - " for (var i in arguments) {\n" - " var element = arguments[i];\n" - "\n" - " if (AHUACATL_TYPEWEIGHT(element) !== AHUACATL_TYPEWEIGHT_LIST) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"UNION\");\n" - " }\n" - "\n" - " for (var k in element) {\n" - " if (!element.hasOwnProperty(k)) {\n" - " continue;\n" - " }\n" - "\n" - " result.push(element[k]);\n" - " }\n" - " }\n" - "\n" - " return result; \n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief maximum of all values\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_MAX () {\n" - " var result = null;\n" - " var value = arguments[0];\n" - "\n" - " AHUACATL_LIST(value);\n" - "\n" - " for (var i in value) {\n" - " var currentValue = value[i];\n" - " \n" - " if (AHUACATL_TYPEWEIGHT(currentValue) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " continue;\n" - " }\n" - "\n" - " if (result === null || AHUACATL_RELATIONAL_GREATER(currentValue, result)) {\n" - " result = currentValue;\n" - " }\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief minimum of all values\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_MIN () {\n" - " var result = null;\n" - " var value = arguments[0];\n" - "\n" - " AHUACATL_LIST(value);\n" - "\n" - " for (var i in value) {\n" - " var currentValue = value[i];\n" - " \n" - " if (AHUACATL_TYPEWEIGHT(currentValue) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " continue;\n" - " }\n" - " \n" - " if (result === null || AHUACATL_RELATIONAL_LESS(currentValue, result)) {\n" - " result = currentValue;\n" - " }\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief sum of all values\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_SUM () {\n" - " var result = null;\n" - " var value = arguments[0];\n" - "\n" - " AHUACATL_LIST(value);\n" - "\n" - " for (var i in value) {\n" - " var currentValue = value[i];\n" - " \n" - " if (AHUACATL_TYPEWEIGHT(currentValue) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " continue;\n" - " }\n" - "\n" - " if (AHUACATL_TYPEWEIGHT(currentValue) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"SUM\");\n" - " }\n" - " \n" - " if (result === null) {\n" - " result = currentValue;\n" - " }\n" - " else {\n" - " result += currentValue;\n" - " }\n" - " }\n" - "\n" - " return AHUACATL_NUMERIC_VALUE(result);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- geo functions\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup Ahuacatl\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief return at most documents near a certain point\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_GEO_NEAR () {\n" - " var collection = arguments[0];\n" - " var latitude = arguments[1];\n" - " var longitude = arguments[2];\n" - " var limit = arguments[3];\n" - " var distanceAttribute = arguments[4];\n" - "\n" - " var idx = AHUACATL_INDEX(internal.db[collection], [ \"geo1\", \"geo2\" ]); \n" - " if (idx == null) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_GEO_INDEX_MISSING, collection);\n" - " }\n" - "\n" - " var result = internal.db[collection].NEAR_NL(idx, latitude, longitude, limit);\n" - " if (distanceAttribute == null) {\n" - " return result.documents;\n" - " }\n" - "\n" - " // inject distances\n" - " var documents = result.documents;\n" - " var distances = result.distances;\n" - " var n = documents.length;\n" - " for (var i = 0; i < n; ++i) {\n" - " documents[i][distanceAttribute] = distances[i];\n" - " }\n" - "\n" - " return documents;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief return documents within around a certain point\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_GEO_WITHIN () {\n" - " var collection = arguments[0];\n" - " var latitude = arguments[1];\n" - " var longitude = arguments[2];\n" - " var radius = arguments[3];\n" - " var distanceAttribute = arguments[4];\n" - "\n" - " var idx = AHUACATL_INDEX(internal.db[collection], [ \"geo1\", \"geo2\" ]); \n" - " if (idx == null) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_GEO_INDEX_MISSING, collection);\n" - " }\n" - "\n" - " var result = internal.db[collection].WITHIN_NL(idx, latitude, longitude, radius);\n" - " if (distanceAttribute == null) {\n" - " return result.documents;\n" - " }\n" - "\n" - " // inject distances\n" - " var documents = result.documents;\n" - " var distances = result.distances;\n" - " var n = documents.length;\n" - " for (var i = 0; i < n; ++i) {\n" - " documents[i][distanceAttribute] = distances[i];\n" - " }\n" - "\n" - " return documents;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- graph functions\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup Ahuacatl\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief find all paths through a graph\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_GRAPH_PATHS () {\n" - " var vertices = arguments[0];\n" - " var edgeCollection = arguments[1];\n" - " var direction = arguments[2] != undefined ? arguments[2] : \"outbound\";\n" - " var followCycles = arguments[3] ? arguments[3] : false;\n" - "\n" - " var minLength = 0;\n" - " var maxLength = 10;\n" - " var searchDirection;\n" - "\n" - " AHUACATL_LIST(vertices);\n" - "\n" - " // validate arguments\n" - " if (direction == \"outbound\") {\n" - " searchDirection = 1;\n" - " }\n" - " else if (direction == \"inbound\") {\n" - " searchDirection = 2;\n" - " }\n" - " else if (direction == \"any\") {\n" - " searchDirection = 3;\n" - " maxLength = 3;\n" - " }\n" - " else {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"PATHS\");\n" - " }\n" - "\n" - " if (minLength < 0 || maxLength < 0 || minLength > maxLength) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"PATHS\");\n" - " }\n" - "\n" - " var searchAttributes = { \n" - " \"edgeCollection\" : internal.db[edgeCollection],\n" - " \"minLength\" : minLength, \n" - " \"maxLength\" : maxLength, \n" - " \"direction\" : searchDirection,\n" - " \"followCycles\" : followCycles,\n" - " };\n" - "\n" - " // TODO: restrict allEdges to edges with certain _from values etc.\n" - "\n" - " var result = [ ];\n" - " var n = vertices.length;\n" - " for (var i = 0; i < n; ++i) {\n" - " var vertex = vertices[i];\n" - " var visited = { };\n" - " visited[vertex._id] = true;\n" - " var connected = AHUACATL_GRAPH_SUBNODES(searchAttributes, vertex._id, visited, [ ], [ vertex ], 0);\n" - " for (j = 0; j < connected.length; ++j) {\n" - " result.push(connected[j]);\n" - " }\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief find all paths through a graph, internal part called recursively\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_GRAPH_SUBNODES (searchAttributes, vertexId, visited, edges, vertices, level) {\n" - " var result = [ ];\n" - "\n" - " if (level >= searchAttributes.minLength) {\n" - " result.push({ \n" - " \"vertices\" : vertices, \n" - " \"edges\" : edges,\n" - " \"source\" : vertices[0],\n" - " \"destination\" : vertices[vertices.length - 1],\n" - " });\n" - " }\n" - "\n" - " if (level + 1 > searchAttributes.maxLength) {\n" - " return result;\n" - " }\n" - "\n" - " var subEdges;\n" - "\n" - " if (searchAttributes.direction == 1) {\n" - " subEdges = searchAttributes.edgeCollection.outEdges(vertexId);\n" - " }\n" - " else if (searchAttributes.direction == 2) {\n" - " subEdges = searchAttributes.edgeCollection.inEdges(vertexId);\n" - " }\n" - " else if (searchAttributes.direction == 3) {\n" - " subEdges = searchAttributes.edgeCollection.edges(vertexId);\n" - " }\n" - "\n" - " for (var i = 0; i < subEdges.length; ++i) {\n" - " var subEdge = subEdges[i];\n" - " var targets = [ ];\n" - "\n" - " if (searchAttributes.direction & 1) {\n" - " targets.push(subEdge._to);\n" - " }\n" - " if (searchAttributes.direction & 2) {\n" - " targets.push(subEdge._from);\n" - " }\n" - "\n" - " for (var j = 0; j < targets.length; ++j) {\n" - " var targetId = targets[j];\n" - " \n" - " if (!searchAttributes.followCycles) {\n" - " if (visited[targetId]) {\n" - " continue;\n" - " }\n" - " visited[targetId] = true;\n" - " }\n" - "\n" - " var clonedEdges = AHUACATL_CLONE(edges);\n" - " var clonedVertices = AHUACATL_CLONE(vertices);\n" - " clonedEdges.push(subEdge);\n" - " clonedVertices.push(internal.db._document_nl(targetId));\n" - " \n" - " var connected = AHUACATL_GRAPH_SUBNODES(searchAttributes, targetId, AHUACATL_CLONE(visited), clonedEdges, clonedVertices, level + 1);\n" - " for (k = 0; k < connected.length; ++k) {\n" - " result.push(connected[k]);\n" - " }\n" - "\n" - " if (!searchAttributes.followCycles) {\n" - " delete visited[targetId];\n" - " }\n" - " }\n" - " }\n" - "\n" - " return result;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- misc functions\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup Ahuacatl\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief return value if it's not null, otherwise return alternative\n" - "///\n" - "/// the operands can have any type\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_NOT_NULL (value, alternative) {\n" - " if (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " return alternative;\n" - " }\n" - "\n" - " return value;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief check whether a document has an attribute\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_HAS () {\n" - " var element = arguments[0];\n" - " var name = arguments[1];\n" - " \n" - " if (AHUACATL_TYPEWEIGHT(element) === AHUACATL_TYPEWEIGHT_NULL) {\n" - " return false;\n" - " }\n" - "\n" - " if (AHUACATL_TYPEWEIGHT(element) !== AHUACATL_TYPEWEIGHT_DOCUMENT) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"HAS\");\n" - " }\n" - "\n" - " return element.hasOwnProperty(name);\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief merge all arguments\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_MERGE () {\n" - " var result = { };\n" - "\n" - " for (var i in arguments) {\n" - " var element = arguments[i];\n" - "\n" - " if (AHUACATL_TYPEWEIGHT(element) !== AHUACATL_TYPEWEIGHT_DOCUMENT) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"MERGE\");\n" - " }\n" - "\n" - " for (var k in element) {\n" - " if (!element.hasOwnProperty(k)) {\n" - " continue;\n" - " }\n" - "\n" - " result[k] = element[k];\n" - " }\n" - " }\n" - "\n" - " return result; \n" - "}\n" - "\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief passthru the argument\n" - "///\n" - "/// this function is marked as non-deterministic so its argument withstands\n" - "/// query optimisation. this function can be used for testing\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_PASSTHRU () {\n" - " var value = arguments[0];\n" - "\n" - " return value;\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief always fail\n" - "///\n" - "/// this function is non-deterministic so it is not executed at query \n" - "/// optimisation time. this function can be used for testing\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "function AHUACATL_FAIL () {\n" - " var message = arguments[0];\n" - "\n" - " if (AHUACATL_TYPEWEIGHT(message) === AHUACATL_TYPEWEIGHT_STRING) {\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_FAIL_CALLED, message);\n" - " }\n" - "\n" - " AHUACATL_THROW(internal.errors.ERROR_QUERY_FAIL_CALLED, \"\");\n" - "}\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" +static string JS_server_ahuacatl = string("") + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief Ahuacatl, internal query functions \n" + + "///\n" + + "/// @file\n" + + "///\n" + + "/// DISCLAIMER\n" + + "///\n" + + "/// Copyright 2010-2012 triagens GmbH, Cologne, Germany\n" + + "///\n" + + "/// Licensed under the Apache License, Version 2.0 (the \"License\");\n" + + "/// you may not use this file except in compliance with the License.\n" + + "/// You may obtain a copy of the License at\n" + + "///\n" + + "/// http://www.apache.org/licenses/LICENSE-2.0\n" + + "///\n" + + "/// Unless required by applicable law or agreed to in writing, software\n" + + "/// distributed under the License is distributed on an \"AS IS\" BASIS,\n" + + "/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + + "/// See the License for the specific language governing permissions and\n" + + "/// limitations under the License.\n" + + "///\n" + + "/// Copyright holder is triAGENS GmbH, Cologne, Germany\n" + + "///\n" + + "/// @author Jan Steemann\n" + + "/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "var internal = require(\"internal\");\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief type weight used for sorting and comparing\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "var AHUACATL_TYPEWEIGHT_NULL = 0;\n" + + "var AHUACATL_TYPEWEIGHT_BOOL = 1;\n" + + "var AHUACATL_TYPEWEIGHT_NUMBER = 2;\n" + + "var AHUACATL_TYPEWEIGHT_STRING = 4;\n" + + "var AHUACATL_TYPEWEIGHT_LIST = 8;\n" + + "var AHUACATL_TYPEWEIGHT_DOCUMENT = 16;\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- helper functions\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup Ahuacatl\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief throw a runtime exception\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_THROW (error, data) {\n" + + " var err = new ArangoError\n" + + "\n" + + " err.errorNum = error.code;\n" + + " if (data) {\n" + + " err.errorMessage = error.message.replace(/%s/, data);\n" + + " }\n" + + " else {\n" + + " err.errorMessage = error.message;\n" + + " }\n" + + "\n" + + " throw err;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief find an index of a certain type for a collection\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_INDEX (collection, indexTypes) {\n" + + " var indexes = collection.getIndexesNL();\n" + + "\n" + + " for (var i = 0; i < indexes.length; ++i) {\n" + + " var index = indexes[i];\n" + + "\n" + + " for (var j = 0; j < indexTypes.length; ++j) {\n" + + " if (index.type == indexTypes[j]) {\n" + + " return index.id;\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " return null;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief normalize a value for comparison, sorting etc.\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_NORMALIZE (value) {\n" + + " if (value === null || value === undefined) {\n" + + " return null;\n" + + " }\n" + + " if (typeof(value) !== \"object\") {\n" + + " return value;\n" + + " }\n" + + "\n" + + " if (Array.isArray(value)) {\n" + + " var result = [ ];\n" + + " var length = value.length;\n" + + " for (var i = 0; i < length; ++i) {\n" + + " result.push(AHUACATL_NORMALIZE(value[i]));\n" + + " }\n" + + " \n" + + " return result;\n" + + " } \n" + + " else {\n" + + " var attributes = [ ];\n" + + " for (var attribute in value) {\n" + + " if (!value.hasOwnProperty(attribute)) {\n" + + " continue;\n" + + " }\n" + + " attributes.push(attribute);\n" + + " }\n" + + " attributes.sort();\n" + + "\n" + + " var result = { };\n" + + " var length = attributes.length;\n" + + " for (var i = 0; i < length; ++i) {\n" + + " result[attributes[i]] = AHUACATL_NORMALIZE(value[attributes[i]]);\n" + + " }\n" + + "\n" + + " return result;\n" + + " }\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief clone an object\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_CLONE (obj) {\n" + + " if (obj == null) {\n" + + " return obj;\n" + + " }\n" + + "\n" + + " if (typeof(obj) != \"object\") {\n" + + " return obj;\n" + + " }\n" + + "\n" + + " if (Array.isArray(obj)) {\n" + + " var copy = [];\n" + + " var length = obj.length;\n" + + " for (var i = 0; i < length; ++i) {\n" + + " copy[i] = AHUACATL_CLONE(obj[i]);\n" + + " }\n" + + " return copy;\n" + + " }\n" + + "\n" + + " if (obj instanceof Object) {\n" + + " var copy = {};\n" + + " for (var attr in obj) {\n" + + " if (obj.hasOwnProperty(attr)) {\n" + + " copy[attr] = AHUACATL_CLONE(obj[attr]);\n" + + " }\n" + + " }\n" + + " return copy;\n" + + " }\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief validate function call argument\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_ARG_CHECK (actualValue, expectedType, functionName) {\n" + + " if (AHUACATL_TYPEWEIGHT(actualValue) !== expectedType) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, functionName);\n" + + " }\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief call a function\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_FCALL (name, parameters) {\n" + + " return name.apply(null, parameters);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief return the numeric value or undefined if it is out of range\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_NUMERIC_VALUE (value) {\n" + + " if (isNaN(value) || !isFinite(value)) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " return value;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief fix a value for a comparison\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_FIX (value) {\n" + + " if (value === undefined) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " return value;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief get the name for a type\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_TYPENAME (value) {\n" + + " switch (value) {\n" + + " case AHUCATL_TYPEWEIGHT_BOOL:\n" + + " return 'boolean';\n" + + " case AHUCATL_TYPEWEIGHT_NUMBER:\n" + + " return 'number';\n" + + " case AHUCATL_TYPEWEIGHT_STRING:\n" + + " return 'string';\n" + + " case AHUCATL_TYPEWEIGHT_LIST:\n" + + " return 'list';\n" + + " case AHUCATL_TYPEWEIGHT_DOCUMENT:\n" + + " return 'document';\n" + + " case AHUCATL_TYPEWEIGHT_NULL:\n" + + " default:\n" + + " return 'null';\n" + + " }\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief get the sort type of an operand\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_TYPEWEIGHT (value) {\n" + + " if (value === undefined || value === null) {\n" + + " return AHUACATL_TYPEWEIGHT_NULL;\n" + + " }\n" + + "\n" + + " if (Array.isArray(value)) {\n" + + " return AHUACATL_TYPEWEIGHT_LIST;\n" + + " }\n" + + "\n" + + " switch (typeof(value)) {\n" + + " case 'boolean':\n" + + " return AHUACATL_TYPEWEIGHT_BOOL;\n" + + " case 'number':\n" + + " if (isNaN(value) || !isFinite(value)) {\n" + + " // not a number => undefined\n" + + " return AHUACATL_TYPEWEIGHT_NULL; \n" + + " }\n" + + " return AHUACATL_TYPEWEIGHT_NUMBER;\n" + + " case 'string':\n" + + " return AHUACATL_TYPEWEIGHT_STRING;\n" + + " case 'object':\n" + + " return AHUACATL_TYPEWEIGHT_DOCUMENT;\n" + + " }\n" + + "\n" + + " return AHUACATL_TYPEWEIGHT_NULL;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief get the keys of an array or object in a comparable way\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_KEYS (value, doSort) {\n" + + " var keys = [];\n" + + " \n" + + " if (Array.isArray(value)) {\n" + + " var n = value.length;\n" + + " for (var j = 0; j < n; ++j) {\n" + + " keys.push(j);\n" + + " }\n" + + " }\n" + + " else {\n" + + " for (var k in value) {\n" + + " if (value.hasOwnProperty(k)) {\n" + + " keys.push(k);\n" + + " }\n" + + " }\n" + + "\n" + + " if (doSort) {\n" + + " // object keys need to be sorted by names\n" + + " keys.sort();\n" + + " }\n" + + " }\n" + + "\n" + + " return keys;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief get the keys of an array or object in a comparable way\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_KEYLIST (lhs, rhs) {\n" + + " var keys = [];\n" + + " \n" + + " if (Array.isArray(lhs)) {\n" + + " // lhs & rhs are lists\n" + + " var n;\n" + + " if (lhs.length > rhs.length) {\n" + + " n = lhs.length;\n" + + " }\n" + + " else {\n" + + " n = rhs.length;\n" + + " }\n" + + " for (var j = 0; j < n; ++j) {\n" + + " keys.push(j);\n" + + " }\n" + + " return keys;\n" + + " }\n" + + "\n" + + " // lhs & rhs are arrays\n" + + " var k;\n" + + " for (k in lhs) {\n" + + " keys.push(k);\n" + + " }\n" + + " for (k in rhs) {\n" + + " if (lhs.hasOwnProperty(k)) {\n" + + " continue;\n" + + " }\n" + + " keys.push(k);\n" + + " }\n" + + "\n" + + " // object keys need to be sorted by names\n" + + " keys.sort();\n" + + "\n" + + " return keys;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief get an indexed value from an array or document (e.g. users[3])\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_GET_INDEX (value, index) {\n" + + " if (AHUACATL_TYPEWEIGHT(value) == AHUACATL_TYPEWEIGHT_NULL) {\n" + + " return null;\n" + + " }\n" + + " \n" + + " if (AHUACATL_TYPEWEIGHT(value) != AHUACATL_TYPEWEIGHT_LIST &&\n" + + " AHUACATL_TYPEWEIGHT(value) != AHUACATL_TYPEWEIGHT_DOCUMENT) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_LIST_EXPECTED);\n" + + " }\n" + + "\n" + + " var result = value[index];\n" + + "\n" + + " if (AHUACATL_TYPEWEIGHT(result) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief get an attribute from a document (e.g. users.name)\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_DOCUMENT_MEMBER (value, attributeName) {\n" + + " if (AHUACATL_TYPEWEIGHT(value) == AHUACATL_TYPEWEIGHT_NULL) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " if (AHUACATL_TYPEWEIGHT(value) != AHUACATL_TYPEWEIGHT_DOCUMENT) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " var result = value[attributeName];\n" + + "\n" + + " if (AHUACATL_TYPEWEIGHT(result) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief assert that a value is a list, fail otherwise\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_LIST (value) {\n" + + " if (AHUACATL_TYPEWEIGHT(value) !== AHUACATL_TYPEWEIGHT_LIST) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_LIST_EXPECTED);\n" + + " }\n" + + "\n" + + " return value;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief get all documents from the specified collection\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_GET_DOCUMENTS (collection) {\n" + + " return internal.db[collection].ALL_NL(0, null).documents;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief get documents from the specified collection using the primary index\n" + + "/// (single index value)\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_GET_DOCUMENTS_PRIMARY (collection, idx, id) {\n" + + " try {\n" + + " return [ internal.db[collection].document_nl(id) ];\n" + + " }\n" + + " catch (e) {\n" + + " return [ ];\n" + + " }\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief get documents from the specified collection using the primary index\n" + + "/// (multiple index values)\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_GET_DOCUMENTS_PRIMARY_LIST (collection, idx, values) {\n" + + " var result = [ ];\n" + + "\n" + + " for (var i in values) {\n" + + " var id = values[i];\n" + + " try {\n" + + " var d = internal.db[collection].document_nl(id);\n" + + " result.push(d);\n" + + " }\n" + + " catch (e) {\n" + + " }\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief get documents from the specified collection using a hash index\n" + + "/// (single index value)\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_GET_DOCUMENTS_HASH (collection, idx, example) {\n" + + " return internal.db[collection].BY_EXAMPLE_HASH_NL(idx, example).documents;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief get documents from the specified collection using a hash index\n" + + "/// (multiple index values)\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_GET_DOCUMENTS_HASH_LIST (collection, idx, attribute, values) {\n" + + " var result = [ ];\n" + + "\n" + + " for (var i in values) {\n" + + " var value = values[i];\n" + + " var example = { };\n" + + "\n" + + " example[attribute] = value;\n" + + "\n" + + " var documents = internal.db[collection].BY_EXAMPLE_HASH_NL(idx, example).documents;\n" + + " for (var j in documents) {\n" + + " result.push(documents[j]);\n" + + " }\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief get documents from the specified collection using a bitarray\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_GET_DOCUMENTS_BITARRAY (collection, idx, example) {\n" + + " return internal.db[collection].BY_CONDITION_BITARRAY(idx, example).documents;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief get documents from the specified collection using a bitarray\n" + + "/// (multiple index values) TODO: replace by 'IN index operator'\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_GET_DOCUMENTS_BITARRAY_LIST (collection, idx, attribute, values) {\n" + + " var result = [ ];\n" + + "\n" + + " for (var i in values) {\n" + + " var value = values[i];\n" + + " var example = { };\n" + + "\n" + + " example[attribute] = value;\n" + + "\n" + + " var documents = internal.db[collection].BY_EXAMPLE_BITARRAY(idx, example).documents;\n" + + " for (var j in documents) {\n" + + " result.push(documents[j]);\n" + + " }\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "\n" + + "\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief get documents from the specified collection using a skiplist\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_GET_DOCUMENTS_SKIPLIST (collection, idx, example) {\n" + + " return internal.db[collection].BY_CONDITION_SKIPLIST_NL(idx, example).documents;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief get documents from the specified collection using a skiplist\n" + + "/// (multiple index values)\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_GET_DOCUMENTS_SKIPLIST_LIST (collection, idx, attribute, values) {\n" + + " var result = [ ];\n" + + "\n" + + " for (var i in values) {\n" + + " var value = values[i];\n" + + " var example = { };\n" + + "\n" + + " example[attribute] = value;\n" + + "\n" + + " var documents = internal.db[collection].BY_EXAMPLE_SKIPLIST_NL(idx, example).documents;\n" + + " for (var j in documents) {\n" + + " result.push(documents[j]);\n" + + " }\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief get names of all collections\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_COLLECTIONS () {\n" + + " var collections = internal.db._collections();\n" + + " var result = [ ];\n" + + "\n" + + " for (var i = 0; i < collections.length; ++i) {\n" + + " result.push({ \"_id\" : collections[i]._id, \"name\" : collections[i].name() });\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- logical operations\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup Ahuacatl\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief execute ternary operator\n" + + "///\n" + + "/// the condition operand must be a boolean value, returns either the truepart\n" + + "/// or the falsepart \n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_TERNARY_OPERATOR (condition, truePart, falsePart) {\n" + + " if (AHUACATL_TYPEWEIGHT(condition) !== AHUACATL_TYPEWEIGHT_BOOL) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_LOGICAL_VALUE);\n" + + " }\n" + + "\n" + + " if (condition) {\n" + + " return truePart;\n" + + " }\n" + + " return falsePart;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform logical and\n" + + "///\n" + + "/// both operands must be boolean values, returns a boolean, uses short-circuit\n" + + "/// evaluation\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_LOGICAL_AND (lhs, rhs) {\n" + + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_BOOL ||\n" + + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_BOOL) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_LOGICAL_VALUE);\n" + + " }\n" + + "\n" + + " if (!lhs) {\n" + + " return false;\n" + + " }\n" + + "\n" + + " return rhs;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform logical or\n" + + "///\n" + + "/// both operands must be boolean values, returns a boolean, uses short-circuit\n" + + "/// evaluation\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_LOGICAL_OR (lhs, rhs) {\n" + + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_BOOL ||\n" + + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_BOOL) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_LOGICAL_VALUE);\n" + + " }\n" + + " \n" + + " if (lhs) {\n" + + " return true;\n" + + " }\n" + + "\n" + + " return rhs;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform logical negation\n" + + "///\n" + + "/// the operand must be a boolean values, returns a boolean\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_LOGICAL_NOT (lhs) {\n" + + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_BOOL) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_LOGICAL_VALUE);\n" + + " }\n" + + "\n" + + " return !lhs;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- comparison operations\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup Ahuacatl\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform equality check \n" + + "///\n" + + "/// returns true if the operands are equal, false otherwise\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_RELATIONAL_EQUAL (lhs, rhs) {\n" + + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" + + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" + + "\n" + + " if (leftWeight != rightWeight) {\n" + + " return false;\n" + + " }\n" + + "\n" + + " // lhs and rhs have the same type\n" + + "\n" + + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" + + " // arrays and objects\n" + + " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" + + "\n" + + " for (var i in keys) {\n" + + " var key = keys[i];\n" + + " var result = AHUACATL_RELATIONAL_EQUAL(lhs[key], rhs[key]);\n" + + " if (result === false) {\n" + + " return result;\n" + + " }\n" + + " }\n" + + " return true;\n" + + " }\n" + + "\n" + + " // primitive type\n" + + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " lhs = null;\n" + + " }\n" + + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " rhs = null;\n" + + " }\n" + + "\n" + + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" + + " return COMPARE_STRING(lhs, rhs) == 0;\n" + + " }\n" + + "\n" + + " return (lhs === rhs);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform inequality check \n" + + "///\n" + + "/// returns true if the operands are unequal, false otherwise\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_RELATIONAL_UNEQUAL (lhs, rhs) {\n" + + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" + + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" + + " \n" + + " if (leftWeight != rightWeight) {\n" + + " return true;\n" + + " }\n" + + "\n" + + " // lhs and rhs have the same type\n" + + "\n" + + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" + + " // arrays and objects\n" + + " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" + + "\n" + + " for (var i in keys) {\n" + + " var key = keys[i];\n" + + " var result = AHUACATL_RELATIONAL_UNEQUAL(lhs[key], rhs[key]);\n" + + " if (result === true) {\n" + + " return result;\n" + + " }\n" + + " }\n" + + "\n" + + " return false;\n" + + " }\n" + + "\n" + + " // primitive type\n" + + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " lhs = null;\n" + + " }\n" + + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " rhs = null;\n" + + " }\n" + + "\n" + + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" + + " return COMPARE_STRING(lhs, rhs) != 0;\n" + + " }\n" + + "\n" + + " return (lhs !== rhs);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform greater than check (inner function)\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_RELATIONAL_GREATER_REC (lhs, rhs) {\n" + + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" + + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" + + " \n" + + " if (leftWeight > rightWeight) {\n" + + " return true;\n" + + " }\n" + + " if (leftWeight < rightWeight) {\n" + + " return false;\n" + + " }\n" + + "\n" + + " // lhs and rhs have the same type\n" + + "\n" + + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" + + " // arrays and objects\n" + + " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" + + "\n" + + " for (var i in keys) {\n" + + " var key = keys[i];\n" + + " var result = AHUACATL_RELATIONAL_GREATER_REC(lhs[key], rhs[key]);\n" + + " if (result !== null) {\n" + + " return result;\n" + + " }\n" + + " }\n" + + " \n" + + " return null;\n" + + " }\n" + + "\n" + + " // primitive type\n" + + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " lhs = null;\n" + + " }\n" + + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " rhs = null;\n" + + " }\n" + + "\n" + + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" + + " return COMPARE_STRING(lhs, rhs) > 0;\n" + + " }\n" + + "\n" + + " if (lhs === rhs) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " return (lhs > rhs);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform greater than check \n" + + "///\n" + + "/// returns true if the left operand is greater than the right operand\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_RELATIONAL_GREATER (lhs, rhs) {\n" + + " var result = AHUACATL_RELATIONAL_GREATER_REC(lhs, rhs);\n" + + "\n" + + " if (result === null) {\n" + + " result = false;\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform greater equal check (inner function)\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_RELATIONAL_GREATEREQUAL_REC (lhs, rhs) {\n" + + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" + + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" + + " \n" + + " if (leftWeight > rightWeight) {\n" + + " return true;\n" + + " }\n" + + " if (leftWeight < rightWeight) {\n" + + " return false;\n" + + " }\n" + + "\n" + + " // lhs and rhs have the same type\n" + + "\n" + + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" + + " // arrays and objects\n" + + " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" + + "\n" + + " for (var i in keys) {\n" + + " var key = keys[i];\n" + + " var result = AHUACATL_RELATIONAL_GREATEREQUAL_REC(lhs[key], rhs[key]);\n" + + " if (result !== null) {\n" + + " return result;\n" + + " }\n" + + " }\n" + + " \n" + + " return null;\n" + + " }\n" + + "\n" + + " // primitive type\n" + + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " lhs = null;\n" + + " }\n" + + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " rhs = null;\n" + + " }\n" + + "\n" + + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" + + " return COMPARE_STRING(lhs, rhs) >= 0;\n" + + " }\n" + + "\n" + + " if (lhs === rhs) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " return (lhs >= rhs);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform greater equal check \n" + + "///\n" + + "/// returns true if the left operand is greater or equal to the right operand\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_RELATIONAL_GREATEREQUAL (lhs, rhs) {\n" + + " var result = AHUACATL_RELATIONAL_GREATEREQUAL_REC(lhs, rhs);\n" + + "\n" + + " if (result === null) {\n" + + " result = true;\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform less than check (inner function)\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_RELATIONAL_LESS_REC (lhs, rhs) {\n" + + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" + + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" + + " \n" + + " if (leftWeight < rightWeight) {\n" + + " return true;\n" + + " }\n" + + " if (leftWeight > rightWeight) {\n" + + " return false;\n" + + " }\n" + + "\n" + + " // lhs and rhs have the same type\n" + + "\n" + + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" + + " // arrays and objects\n" + + " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" + + "\n" + + " for (var i in keys) {\n" + + " var key = keys[i];\n" + + " var result = AHUACATL_RELATIONAL_LESS_REC(lhs[key], rhs[key]);\n" + + " if (result !== null) {\n" + + " return result;\n" + + " }\n" + + " }\n" + + " \n" + + " return null;\n" + + " }\n" + + "\n" + + " // primitive type\n" + + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " lhs = null;\n" + + " }\n" + + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " rhs = null;\n" + + " }\n" + + "\n" + + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" + + " return COMPARE_STRING(lhs, rhs) < 0;\n" + + " }\n" + + "\n" + + " if (lhs === rhs) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " return (lhs < rhs);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform less than check \n" + + "///\n" + + "/// returns true if the left operand is less than the right operand\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_RELATIONAL_LESS (lhs, rhs) {\n" + + " var result = AHUACATL_RELATIONAL_LESS_REC(lhs, rhs);\n" + + "\n" + + " if (result === null) {\n" + + " result = false;\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform less equal check (inner function)\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_RELATIONAL_LESSEQUAL_REC (lhs, rhs) {\n" + + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" + + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" + + " \n" + + " if (leftWeight < rightWeight) {\n" + + " return true;\n" + + " }\n" + + " if (leftWeight > rightWeight) {\n" + + " return false;\n" + + " }\n" + + "\n" + + " // lhs and rhs have the same type\n" + + "\n" + + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" + + " // arrays and objects\n" + + " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" + + "\n" + + " for (var i in keys) {\n" + + " var key = keys[i];\n" + + " var result = AHUACATL_RELATIONAL_LESSEQUAL_REC(lhs[key], rhs[key]);\n" + + " if (result !== null) {\n" + + " return result;\n" + + " }\n" + + " }\n" + + "\n" + + " return null;\n" + + " }\n" + + " \n" + + " // primitive type\n" + + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " lhs = null;\n" + + " }\n" + + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " rhs = null;\n" + + " }\n" + + " \n" + + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" + + " return COMPARE_STRING(lhs, rhs) <= 0;\n" + + " }\n" + + " \n" + + " if (lhs === rhs) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " return (lhs <= rhs);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform less equal check \n" + + "///\n" + + "/// returns true if the left operand is less or equal to the right operand\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_RELATIONAL_LESSEQUAL (lhs, rhs) {\n" + + " var result = AHUACATL_RELATIONAL_LESSEQUAL_REC(lhs, rhs);\n" + + "\n" + + " if (result === null) {\n" + + " result = true;\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform comparison\n" + + "///\n" + + "/// returns -1 if the left operand is less than the right operand, 1 if it is\n" + + "/// greater, 0 if both operands are equal\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_RELATIONAL_CMP (lhs, rhs) {\n" + + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" + + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" + + " \n" + + " if (leftWeight < rightWeight) {\n" + + " return -1;\n" + + " }\n" + + " if (leftWeight > rightWeight) {\n" + + " return 1;\n" + + " }\n" + + "\n" + + " // lhs and rhs have the same type\n" + + "\n" + + " if (leftWeight >= AHUACATL_TYPEWEIGHT_LIST) {\n" + + " // arrays and objects\n" + + " var keys = AHUACATL_KEYLIST(lhs, rhs);\n" + + "\n" + + " for (var i in keys) {\n" + + " var key = keys[i];\n" + + " var result = AHUACATL_RELATIONAL_CMP(lhs[key], rhs[key]);\n" + + " if (result !== 0) {\n" + + " return result;\n" + + " }\n" + + " }\n" + + " \n" + + " return 0;\n" + + " }\n" + + "\n" + + " // primitive type\n" + + " if (AHUACATL_TYPEWEIGHT(lhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " lhs = null;\n" + + " }\n" + + " if (AHUACATL_TYPEWEIGHT(rhs) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " rhs = null;\n" + + " }\n" + + "\n" + + " if (leftWeight === AHUACATL_TYPEWEIGHT_STRING) {\n" + + " return COMPARE_STRING(lhs, rhs);\n" + + " }\n" + + "\n" + + " if (lhs < rhs) {\n" + + " return -1;\n" + + " }\n" + + " \n" + + " if (lhs > rhs) {\n" + + " return 1;\n" + + " }\n" + + "\n" + + " return 0;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform in list check \n" + + "///\n" + + "/// returns true if the left operand is contained in the right operand\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_RELATIONAL_IN (lhs, rhs) {\n" + + " var leftWeight = AHUACATL_TYPEWEIGHT(lhs);\n" + + " var rightWeight = AHUACATL_TYPEWEIGHT(rhs);\n" + + " \n" + + " if (rightWeight !== AHUACATL_TYPEWEIGHT_LIST) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_LIST_EXPECTED);\n" + + " }\n" + + "\n" + + " var numRight = rhs.length;\n" + + " for (var i = 0; i < numRight; ++i) {\n" + + " if (AHUACATL_RELATIONAL_EQUAL(lhs, rhs[i])) {\n" + + " return true;\n" + + " }\n" + + " }\n" + + "\n" + + " return false;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- arithmetic operations\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup Ahuacatl\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform unary plus operation\n" + + "///\n" + + "/// the operand must be numeric or this function will fail\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_UNARY_PLUS (value) {\n" + + " if (AHUACATL_TYPEWEIGHT(value) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" + + " }\n" + + "\n" + + " var result = AHUACATL_NUMERIC_VALUE(value);\n" + + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform unary minus operation\n" + + "///\n" + + "/// the operand must be numeric or this function will fail\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_UNARY_MINUS (value) {\n" + + " if (AHUACATL_TYPEWEIGHT(value) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" + + " }\n" + + "\n" + + " var result = AHUACATL_NUMERIC_VALUE(-value);\n" + + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform artithmetic plus\n" + + "///\n" + + "/// both operands must be numeric or this function will fail\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_ARITHMETIC_PLUS (lhs, rhs) { \n" + + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||\n" + + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" + + " }\n" + + "\n" + + " var result = AHUACATL_NUMERIC_VALUE(lhs + rhs);\n" + + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform artithmetic minus\n" + + "///\n" + + "/// both operands must be numeric or this function will fail\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_ARITHMETIC_MINUS (lhs, rhs) {\n" + + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||\n" + + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" + + " }\n" + + "\n" + + " var result = AHUACATL_NUMERIC_VALUE(lhs - rhs);\n" + + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform artithmetic multiplication\n" + + "///\n" + + "/// both operands must be numeric or this function will fail\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_ARITHMETIC_TIMES (lhs, rhs) {\n" + + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||\n" + + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" + + " }\n" + + "\n" + + " var result = AHUACATL_NUMERIC_VALUE(lhs * rhs);\n" + + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform artithmetic division\n" + + "///\n" + + "/// both operands must be numeric or this function will fail\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_ARITHMETIC_DIVIDE (lhs, rhs) {\n" + + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||\n" + + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" + + " }\n" + + " \n" + + " if (rhs == 0) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_DIVISION_BY_ZERO);\n" + + " }\n" + + "\n" + + " var result = AHUACATL_NUMERIC_VALUE(lhs / rhs);\n" + + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform artithmetic modulus\n" + + "///\n" + + "/// both operands must be numeric or this function will fail\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_ARITHMETIC_MODULUS (lhs, rhs) {\n" + + " if (AHUACATL_TYPEWEIGHT(lhs) !== AHUACATL_TYPEWEIGHT_NUMBER ||\n" + + " AHUACATL_TYPEWEIGHT(rhs) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_INVALID_ARITHMETIC_VALUE);\n" + + " }\n" + + "\n" + + " if (rhs == 0) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_DIVISION_BY_ZERO);\n" + + " }\n" + + "\n" + + " var result = AHUACATL_NUMERIC_VALUE(lhs % rhs);\n" + + " if (AHUACATL_TYPEWEIGHT(result) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- string functions\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup Ahuacatl\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform string concatenation\n" + + "///\n" + + "/// all operands must be strings or this function will fail\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_STRING_CONCAT () {\n" + + " var result = '';\n" + + "\n" + + " for (var i in arguments) {\n" + + " var element = arguments[i];\n" + + "\n" + + " if (AHUACATL_TYPEWEIGHT(element) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " continue;\n" + + " }\n" + + "\n" + + " AHUACATL_ARG_CHECK(element, AHUACATL_TYPEWEIGHT_STRING, \"CONCAT\");\n" + + "\n" + + " result += element;\n" + + " }\n" + + "\n" + + " return result; \n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief perform string concatenation using a separator character\n" + + "///\n" + + "/// all operands must be strings or this function will fail\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_STRING_CONCAT_SEPARATOR () {\n" + + " var separator;\n" + + " var found = false;\n" + + " var result = '';\n" + + "\n" + + " for (var i in arguments) {\n" + + " var element = arguments[i];\n" + + "\n" + + " if (i > 0 && AHUACATL_TYPEWEIGHT(element) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " continue;\n" + + " }\n" + + " \n" + + " AHUACATL_ARG_CHECK(element, AHUACATL_TYPEWEIGHT_STRING, \"CONCAT_SEPARATOR\");\n" + + "\n" + + " if (i == 0) {\n" + + " separator = element;\n" + + " continue;\n" + + " }\n" + + " else if (found) {\n" + + " result += separator;\n" + + " }\n" + + "\n" + + " found = true;\n" + + "\n" + + " result += element;\n" + + " }\n" + + "\n" + + " return result; \n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief return the length of a string in characters (not bytes)\n" + + "///\n" + + "/// the input operand must be a string or this function will fail\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_STRING_LENGTH (value) {\n" + + " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"STRING_LENGTH\");\n" + + "\n" + + " return value.length;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief convert a string to lower case\n" + + "///\n" + + "/// the input operand must be a string or this function will fail\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_STRING_LOWER (value) {\n" + + " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"LOWER\");\n" + + "\n" + + " return value.toLowerCase();\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief convert a string to upper case\n" + + "///\n" + + "/// the input operand must be a string or this function will fail\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_STRING_UPPER (value) {\n" + + " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"UPPER\");\n" + + "\n" + + " return value.toUpperCase();\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief return a substring of the string\n" + + "///\n" + + "/// the input operand must be a string or this function will fail\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_STRING_SUBSTRING (value, offset, count) {\n" + + " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"SUBSTRING\");\n" + + " AHUACATL_ARG_CHECK(offset, AHUACATL_TYPEWEIGHT_NUMBER, \"SUBSTRING\");\n" + + "\n" + + " return value.substr(offset, count);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief searches a substring in a string\n" + + "///\n" + + "/// the two input operands must be strings or this function will fail\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_STRING_CONTAINS (value, search) {\n" + + " AHUACATL_ARG_CHECK(value, AHUACATL_TYPEWEIGHT_STRING, \"CONTAINS\");\n" + + " AHUACATL_ARG_CHECK(search, AHUACATL_TYPEWEIGHT_STRING, \"CONTAINS\");\n" + + "\n" + + " if (search.length == 0) {\n" + + " return false;\n" + + " }\n" + + "\n" + + " return value.indexOf(search) != -1;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- typecast functions\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup Ahuacatl\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief cast to a bool\n" + + "///\n" + + "/// the operand can have any type, always returns a bool\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_CAST_BOOL (value) {\n" + + " switch (AHUACATL_TYPEWEIGHT(value)) {\n" + + " case AHUACATL_TYPEWEIGHT_NULL:\n" + + " return false;\n" + + " case AHUACATL_TYPEWEIGHT_BOOL:\n" + + " return value;\n" + + " case AHUACATL_TYPEWEIGHT_NUMBER:\n" + + " return (value != 0);\n" + + " case AHUACATL_TYPEWEIGHT_STRING: \n" + + " return (value !== '');\n" + + " case AHUACATL_TYPEWEIGHT_LIST:\n" + + " return (value.length > 0);\n" + + " case AHUACATL_TYPEWEIGHT_DOCUMENT:\n" + + " return (AHUACATL_KEYS(value, false).length > 0);\n" + + " }\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief cast to a number\n" + + "///\n" + + "/// the operand can have any type, always returns a number\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_CAST_NUMBER (value) {\n" + + " switch (AHUACATL_TYPEWEIGHT(value)) {\n" + + " case AHUACATL_TYPEWEIGHT_NULL:\n" + + " case AHUACATL_TYPEWEIGHT_LIST:\n" + + " case AHUACATL_TYPEWEIGHT_DOCUMENT:\n" + + " return 0.0;\n" + + " case AHUACATL_TYPEWEIGHT_BOOL:\n" + + " return (value ? 1 : 0);\n" + + " case AHUACATL_TYPEWEIGHT_NUMBER:\n" + + " return value;\n" + + " case AHUACATL_TYPEWEIGHT_STRING:\n" + + " var result = parseFloat(value);\n" + + " return ((AHUACATL_TYPEWEIGHT(result) === AHUACATL_TYPEWEIGHT_NUMBER) ? result : 0);\n" + + " }\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief cast to a string\n" + + "///\n" + + "/// the operand can have any type, always returns a string\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_CAST_STRING (value) {\n" + + " switch (AHUACATL_TYPEWEIGHT(value)) {\n" + + " case AHUACATL_TYPEWEIGHT_STRING:\n" + + " return value;\n" + + " case AHUACATL_TYPEWEIGHT_NULL:\n" + + " return 'null';\n" + + " case AHUACATL_TYPEWEIGHT_BOOL:\n" + + " return (value ? 'true' : 'false');\n" + + " case AHUACATL_TYPEWEIGHT_NUMBER:\n" + + " case AHUACATL_TYPEWEIGHT_LIST:\n" + + " case AHUACATL_TYPEWEIGHT_DOCUMENT:\n" + + " return value.toString();\n" + + " }\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- typecheck functions\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup Ahuacatl\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief test if value is of type null\n" + + "///\n" + + "/// returns a bool\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_IS_NULL (value) {\n" + + " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_NULL);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief test if value is of type bool\n" + + "///\n" + + "/// returns a bool\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_IS_BOOL (value) {\n" + + " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_BOOL);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief test if value is of type number\n" + + "///\n" + + "/// returns a bool\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_IS_NUMBER (value) {\n" + + " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_NUMBER);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief test if value is of type string\n" + + "///\n" + + "/// returns a bool\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_IS_STRING (value) {\n" + + " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_STRING);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief test if value is of type list\n" + + "///\n" + + "/// returns a bool\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_IS_LIST (value) {\n" + + " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_LIST);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief test if value is of type document\n" + + "///\n" + + "/// returns a bool\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_IS_DOCUMENT (value) {\n" + + " return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_DOCUMENT);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- numeric functions\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup Ahuacatl\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief integer closest to value, not greater than value\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_NUMBER_FLOOR (value) {\n" + + " if (!AHUACATL_IS_NUMBER(value)) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"FLOOR\");\n" + + " }\n" + + " \n" + + " return Math.floor(value);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief integer closest to value and not less than value\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_NUMBER_CEIL (value) {\n" + + " if (!AHUACATL_IS_NUMBER(value)) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"CEIL\");\n" + + " }\n" + + " \n" + + " return Math.ceil(value);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief integer closest to value \n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_NUMBER_ROUND (value) {\n" + + " if (!AHUACATL_IS_NUMBER(value)) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"ROUND\");\n" + + " }\n" + + " \n" + + " return Math.round(value);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief absolute value\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_NUMBER_ABS (value) {\n" + + " if (!AHUACATL_IS_NUMBER(value)) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"ABS\");\n" + + " }\n" + + " \n" + + " return Math.abs(value);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief a random value between 0 and 1\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_NUMBER_RAND () {\n" + + " return Math.random();\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- high level query functions\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup Ahuacatl\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief sort the results\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_SORT (value, sortFunction) {\n" + + " AHUACATL_LIST(value);\n" + + " \n" + + " var n = value.length;\n" + + " if (n > 0) {\n" + + " value.sort(sortFunction);\n" + + " }\n" + + "\n" + + " return value;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief group the results\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_GROUP (value, sortFunction, groupFunction, into) {\n" + + " AHUACATL_LIST(value);\n" + + "\n" + + " var n = value.length;\n" + + " if (n == 0) {\n" + + " return [ ];\n" + + " }\n" + + "\n" + + " AHUACATL_SORT(value, sortFunction);\n" + + "\n" + + " var result = [ ];\n" + + " var currentGroup = undefined;\n" + + " var oldGroup = undefined;\n" + + " \n" + + " for (var i = 0; i < n; ++i) {\n" + + " var row = value[i];\n" + + " var groupValue = groupFunction(row);\n" + + "\n" + + " if (AHUACATL_RELATIONAL_UNEQUAL(oldGroup, groupValue)) {\n" + + " oldGroup = AHUACATL_CLONE(groupValue);\n" + + "\n" + + " if (currentGroup) {\n" + + " result.push(AHUACATL_CLONE(currentGroup));\n" + + " }\n" + + " \n" + + " currentGroup = groupValue;\n" + + " if (into) {\n" + + " currentGroup[into] = [ ];\n" + + " }\n" + + " }\n" + + "\n" + + " if (into) {\n" + + " currentGroup[into].push(AHUACATL_CLONE(row));\n" + + " }\n" + + " }\n" + + "\n" + + " if (currentGroup) {\n" + + " result.push(AHUACATL_CLONE(currentGroup));\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief limit the number of results\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_LIMIT (value, offset, count) {\n" + + " AHUACATL_LIST(value);\n" + + "\n" + + " if (count < 0) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_NUMBER_OUT_OF_RANGE);\n" + + " }\n" + + "\n" + + " return value.slice(offset, offset + count);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- list processing functions\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup Ahuacatl\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief get the length of a list\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_LENGTH () {\n" + + " var value = arguments[0];\n" + + "\n" + + " AHUACATL_LIST(value);\n" + + "\n" + + " return value.length;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief get the first element of a list\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_FIRST () {\n" + + " var value = arguments[0];\n" + + "\n" + + " AHUACATL_LIST(value);\n" + + "\n" + + " if (value.length == 0) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " return value[0];\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief get the last element of a list\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_LAST () {\n" + + " var value = arguments[0];\n" + + "\n" + + " AHUACATL_LIST(value);\n" + + "\n" + + " if (value.length == 0) {\n" + + " return null;\n" + + " }\n" + + "\n" + + " return value[value.length - 1];\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief reverse the elements in a list\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_REVERSE () {\n" + + " var value = arguments[0];\n" + + "\n" + + " AHUACATL_LIST(value);\n" + + "\n" + + " return value.reverse();\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief return a list of unique elements from the list\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_UNIQUE () {\n" + + " var value = arguments[0];\n" + + "\n" + + " AHUACATL_LIST(value);\n" + + "\n" + + " var length = value.length;\n" + + " var keys = { };\n" + + " for (var i = 0; i < length; ++i) {\n" + + " var normalized = AHUACATL_NORMALIZE(value[i]);\n" + + " keys[JSON.stringify(normalized)] = normalized;\n" + + " }\n" + + "\n" + + " var result = [];\n" + + " for (var i in keys) {\n" + + " result.push(keys[i]);\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief create the union (all) of all arguments\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_UNION () {\n" + + " var result = [ ];\n" + + "\n" + + " for (var i in arguments) {\n" + + " var element = arguments[i];\n" + + "\n" + + " if (AHUACATL_TYPEWEIGHT(element) !== AHUACATL_TYPEWEIGHT_LIST) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"UNION\");\n" + + " }\n" + + "\n" + + " for (var k in element) {\n" + + " if (!element.hasOwnProperty(k)) {\n" + + " continue;\n" + + " }\n" + + "\n" + + " result.push(element[k]);\n" + + " }\n" + + " }\n" + + "\n" + + " return result; \n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief maximum of all values\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_MAX () {\n" + + " var result = null;\n" + + " var value = arguments[0];\n" + + "\n" + + " AHUACATL_LIST(value);\n" + + "\n" + + " for (var i in value) {\n" + + " var currentValue = value[i];\n" + + " \n" + + " if (AHUACATL_TYPEWEIGHT(currentValue) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " continue;\n" + + " }\n" + + "\n" + + " if (result === null || AHUACATL_RELATIONAL_GREATER(currentValue, result)) {\n" + + " result = currentValue;\n" + + " }\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief minimum of all values\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_MIN () {\n" + + " var result = null;\n" + + " var value = arguments[0];\n" + + "\n" + + " AHUACATL_LIST(value);\n" + + "\n" + + " for (var i in value) {\n" + + " var currentValue = value[i];\n" + + " \n" + + " if (AHUACATL_TYPEWEIGHT(currentValue) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " continue;\n" + + " }\n" + + " \n" + + " if (result === null || AHUACATL_RELATIONAL_LESS(currentValue, result)) {\n" + + " result = currentValue;\n" + + " }\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief sum of all values\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_SUM () {\n" + + " var result = null;\n" + + " var value = arguments[0];\n" + + "\n" + + " AHUACATL_LIST(value);\n" + + "\n" + + " for (var i in value) {\n" + + " var currentValue = value[i];\n" + + " \n" + + " if (AHUACATL_TYPEWEIGHT(currentValue) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " continue;\n" + + " }\n" + + "\n" + + " if (AHUACATL_TYPEWEIGHT(currentValue) !== AHUACATL_TYPEWEIGHT_NUMBER) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"SUM\");\n" + + " }\n" + + " \n" + + " if (result === null) {\n" + + " result = currentValue;\n" + + " }\n" + + " else {\n" + + " result += currentValue;\n" + + " }\n" + + " }\n" + + "\n" + + " return AHUACATL_NUMERIC_VALUE(result);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- geo functions\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup Ahuacatl\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief return at most documents near a certain point\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_GEO_NEAR () {\n" + + " var collection = arguments[0];\n" + + " var latitude = arguments[1];\n" + + " var longitude = arguments[2];\n" + + " var limit = arguments[3];\n" + + " var distanceAttribute = arguments[4];\n" + + "\n" + + " var idx = AHUACATL_INDEX(internal.db[collection], [ \"geo1\", \"geo2\" ]); \n" + + " if (idx == null) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_GEO_INDEX_MISSING, collection);\n" + + " }\n" + + "\n" + + " var result = internal.db[collection].NEAR_NL(idx, latitude, longitude, limit);\n" + + " if (distanceAttribute == null) {\n" + + " return result.documents;\n" + + " }\n" + + "\n" + + " // inject distances\n" + + " var documents = result.documents;\n" + + " var distances = result.distances;\n" + + " var n = documents.length;\n" + + " for (var i = 0; i < n; ++i) {\n" + + " documents[i][distanceAttribute] = distances[i];\n" + + " }\n" + + "\n" + + " return documents;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief return documents within around a certain point\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_GEO_WITHIN () {\n" + + " var collection = arguments[0];\n" + + " var latitude = arguments[1];\n" + + " var longitude = arguments[2];\n" + + " var radius = arguments[3];\n" + + " var distanceAttribute = arguments[4];\n" + + "\n" + + " var idx = AHUACATL_INDEX(internal.db[collection], [ \"geo1\", \"geo2\" ]); \n" + + " if (idx == null) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_GEO_INDEX_MISSING, collection);\n" + + " }\n" + + "\n" + + " var result = internal.db[collection].WITHIN_NL(idx, latitude, longitude, radius);\n" + + " if (distanceAttribute == null) {\n" + + " return result.documents;\n" + + " }\n" + + "\n" + + " // inject distances\n" + + " var documents = result.documents;\n" + + " var distances = result.distances;\n" + + " var n = documents.length;\n" + + " for (var i = 0; i < n; ++i) {\n" + + " documents[i][distanceAttribute] = distances[i];\n" + + " }\n" + + "\n" + + " return documents;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- graph functions\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup Ahuacatl\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief find all paths through a graph\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_GRAPH_PATHS () {\n" + + " var vertices = arguments[0];\n" + + " var edgeCollection = arguments[1];\n" + + " var direction = arguments[2] != undefined ? arguments[2] : \"outbound\";\n" + + " var followCycles = arguments[3] ? arguments[3] : false;\n" + + "\n" + + " var minLength = 0;\n" + + " var maxLength = 10;\n" + + " var searchDirection;\n" + + "\n" + + " AHUACATL_LIST(vertices);\n" + + "\n" + + " // validate arguments\n" + + " if (direction == \"outbound\") {\n" + + " searchDirection = 1;\n" + + " }\n" + + " else if (direction == \"inbound\") {\n" + + " searchDirection = 2;\n" + + " }\n" + + " else if (direction == \"any\") {\n" + + " searchDirection = 3;\n" + + " maxLength = 3;\n" + + " }\n" + + " else {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"PATHS\");\n" + + " }\n" + + "\n" + + " if (minLength < 0 || maxLength < 0 || minLength > maxLength) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"PATHS\");\n" + + " }\n" + + "\n" + + " var searchAttributes = { \n" + + " \"edgeCollection\" : internal.db[edgeCollection],\n" + + " \"minLength\" : minLength, \n" + + " \"maxLength\" : maxLength, \n" + + " \"direction\" : searchDirection,\n" + + " \"followCycles\" : followCycles,\n" + + " };\n" + + "\n" + + " // TODO: restrict allEdges to edges with certain _from values etc.\n" + + "\n" + + " var result = [ ];\n" + + " var n = vertices.length;\n" + + " for (var i = 0; i < n; ++i) {\n" + + " var vertex = vertices[i];\n" + + " var visited = { };\n" + + " visited[vertex._id] = true;\n" + + " var connected = AHUACATL_GRAPH_SUBNODES(searchAttributes, vertex._id, visited, [ ], [ vertex ], 0);\n" + + " for (j = 0; j < connected.length; ++j) {\n" + + " result.push(connected[j]);\n" + + " }\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief find all paths through a graph, internal part called recursively\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_GRAPH_SUBNODES (searchAttributes, vertexId, visited, edges, vertices, level) {\n" + + " var result = [ ];\n" + + "\n" + + " if (level >= searchAttributes.minLength) {\n" + + " result.push({ \n" + + " \"vertices\" : vertices, \n" + + " \"edges\" : edges,\n" + + " \"source\" : vertices[0],\n" + + " \"destination\" : vertices[vertices.length - 1],\n" + + " });\n" + + " }\n" + + "\n" + + " if (level + 1 > searchAttributes.maxLength) {\n" + + " return result;\n" + + " }\n" + + "\n" + + " var subEdges;\n" + + "\n" + + " if (searchAttributes.direction == 1) {\n" + + " subEdges = searchAttributes.edgeCollection.outEdges(vertexId);\n" + + " }\n" + + " else if (searchAttributes.direction == 2) {\n" + + " subEdges = searchAttributes.edgeCollection.inEdges(vertexId);\n" + + " }\n" + + " else if (searchAttributes.direction == 3) {\n" + + " subEdges = searchAttributes.edgeCollection.edges(vertexId);\n" + + " }\n" + + "\n" + + " for (var i = 0; i < subEdges.length; ++i) {\n" + + " var subEdge = subEdges[i];\n" + + " var targets = [ ];\n" + + "\n" + + " if (searchAttributes.direction & 1) {\n" + + " targets.push(subEdge._to);\n" + + " }\n" + + " if (searchAttributes.direction & 2) {\n" + + " targets.push(subEdge._from);\n" + + " }\n" + + "\n" + + " for (var j = 0; j < targets.length; ++j) {\n" + + " var targetId = targets[j];\n" + + " \n" + + " if (!searchAttributes.followCycles) {\n" + + " if (visited[targetId]) {\n" + + " continue;\n" + + " }\n" + + " visited[targetId] = true;\n" + + " }\n" + + "\n" + + " var clonedEdges = AHUACATL_CLONE(edges);\n" + + " var clonedVertices = AHUACATL_CLONE(vertices);\n" + + " clonedEdges.push(subEdge);\n" + + " clonedVertices.push(internal.db._document_nl(targetId));\n" + + " \n" + + " var connected = AHUACATL_GRAPH_SUBNODES(searchAttributes, targetId, AHUACATL_CLONE(visited), clonedEdges, clonedVertices, level + 1);\n" + + " for (k = 0; k < connected.length; ++k) {\n" + + " result.push(connected[k]);\n" + + " }\n" + + "\n" + + " if (!searchAttributes.followCycles) {\n" + + " delete visited[targetId];\n" + + " }\n" + + " }\n" + + " }\n" + + "\n" + + " return result;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- misc functions\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup Ahuacatl\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief return value if it's not null, otherwise return alternative\n" + + "///\n" + + "/// the operands can have any type\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_NOT_NULL (value, alternative) {\n" + + " if (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " return alternative;\n" + + " }\n" + + "\n" + + " return value;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief check whether a document has an attribute\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_HAS () {\n" + + " var element = arguments[0];\n" + + " var name = arguments[1];\n" + + " \n" + + " if (AHUACATL_TYPEWEIGHT(element) === AHUACATL_TYPEWEIGHT_NULL) {\n" + + " return false;\n" + + " }\n" + + "\n" + + " if (AHUACATL_TYPEWEIGHT(element) !== AHUACATL_TYPEWEIGHT_DOCUMENT) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"HAS\");\n" + + " }\n" + + "\n" + + " return element.hasOwnProperty(name);\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief merge all arguments\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_MERGE () {\n" + + " var result = { };\n" + + "\n" + + " for (var i in arguments) {\n" + + " var element = arguments[i];\n" + + "\n" + + " if (AHUACATL_TYPEWEIGHT(element) !== AHUACATL_TYPEWEIGHT_DOCUMENT) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FUNCTION_ARGUMENT_TYPE_MISMATCH, \"MERGE\");\n" + + " }\n" + + "\n" + + " for (var k in element) {\n" + + " if (!element.hasOwnProperty(k)) {\n" + + " continue;\n" + + " }\n" + + "\n" + + " result[k] = element[k];\n" + + " }\n" + + " }\n" + + "\n" + + " return result; \n" + + "}\n" + + "\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief passthru the argument\n" + + "///\n" + + "/// this function is marked as non-deterministic so its argument withstands\n" + + "/// query optimisation. this function can be used for testing\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_PASSTHRU () {\n" + + " var value = arguments[0];\n" + + "\n" + + " return value;\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief always fail\n" + + "///\n" + + "/// this function is non-deterministic so it is not executed at query \n" + + "/// optimisation time. this function can be used for testing\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "function AHUACATL_FAIL () {\n" + + " var message = arguments[0];\n" + + "\n" + + " if (AHUACATL_TYPEWEIGHT(message) === AHUACATL_TYPEWEIGHT_STRING) {\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FAIL_CALLED, message);\n" + + " }\n" + + "\n" + + " AHUACATL_THROW(internal.errors.ERROR_QUERY_FAIL_CALLED, \"\");\n" + + "}\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" ; diff --git a/js/server/js-server.h b/js/server/js-server.h index 5e4ad22530..05b733978a 100644 --- a/js/server/js-server.h +++ b/js/server/js-server.h @@ -1,587 +1,587 @@ -static string JS_server_server = - "/*jslint indent: 2,\n" - " nomen: true,\n" - " maxlen: 100,\n" - " sloppy: true,\n" - " vars: true,\n" - " white: true,\n" - " plusplus: true */\n" - "/*global require, db, edges, ModuleCache, Module,\n" - " ArangoCollection, ArangoDatabase,\n" - " ArangoError, ShapedJson,\n" - " SYS_DEFINE_ACTION */\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief JavaScript server functions\n" - "///\n" - "/// @file\n" - "///\n" - "/// DISCLAIMER\n" - "///\n" - "/// Copyright 2011-2012 triagens GmbH, Cologne, Germany\n" - "///\n" - "/// Licensed under the Apache License, Version 2.0 (the \"License\");\n" - "/// you may not use this file except in compliance with the License.\n" - "/// You may obtain a copy of the License at\n" - "///\n" - "/// http://www.apache.org/licenses/LICENSE-2.0\n" - "///\n" - "/// Unless required by applicable law or agreed to in writing, software\n" - "/// distributed under the License is distributed on an \"AS IS\" BASIS,\n" - "/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" - "/// See the License for the specific language governing permissions and\n" - "/// limitations under the License.\n" - "///\n" - "/// Copyright holder is triAGENS GmbH, Cologne, Germany\n" - "///\n" - "/// @author Dr. Frank Celler\n" - "/// @author Copyright 2011-2012, triAGENS GmbH, Cologne, Germany\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- Module \"internal\"\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup V8ModuleInternal\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief internal module\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "(function () {\n" - " var internal = require(\"internal\");\n" - " var console = require(\"console\");\n" - "\n" - " internal.db = db;\n" - " internal.edges = db;\n" - " internal.ArangoCollection = ArangoCollection;\n" - "\n" - " if (typeof SYS_DEFINE_ACTION === \"undefined\") {\n" - " internal.defineAction = function() {\n" - " console.error(\"SYS_DEFINE_ACTION not available\");\n" - " };\n" - " }\n" - " else {\n" - " internal.defineAction = SYS_DEFINE_ACTION;\n" - " }\n" - "\n" - " if (typeof SYS_EXECUTE_GLOBAL_CONTEXT_FUNCTION === \"undefined\") {\n" - " internal.executeGlobalContextFunction = function() {\n" - " console.error(\"SYS_EXECUTE_GLOBAL_CONTEXT_FUNCTION not available\");\n" - " };\n" - " }\n" - " else {\n" - " internal.executeGlobalContextFunction = SYS_EXECUTE_GLOBAL_CONTEXT_FUNCTION;\n" - " }\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- Module \"simple-query\"\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup V8ModuleSimpleQuery\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief simple-query module\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " try {\n" - " require(\"simple-query\");\n" - " }\n" - " catch (err) {\n" - " console.error(\"while loading 'simple-query' module: %s\", err);\n" - " }\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- Module \"monkeypatches\"\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup V8ModuleMonkeypatches\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief monkeypatches module\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " try {\n" - " require(\"monkeypatches\");\n" - " }\n" - " catch (err) {\n" - " console.error(\"while loading 'monkeypatches' module: %s\", err);\n" - " }\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- ShapedJson\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup V8Shell\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief prints a shaped json\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ShapedJson.prototype._PRINT = function(seen, path, names, level) {\n" - " if (this instanceof ShapedJson) {\n" - " internal.printObject(this, seen, path, names, level);\n" - " }\n" - " else {\n" - " internal.output(this.toString());\n" - " }\n" - " };\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- ArangoError\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup V8Shell\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief prints an error\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoError.prototype._PRINT = function() {\n" - " var errorNum = this.errorNum;\n" - " var errorMessage = this.errorMessage;\n" - "\n" - " internal.output(\"[ArangoError \", errorNum, \": \", errorMessage, \"]\");\n" - " };\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief converts error to string\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoError.prototype.toString = function() {\n" - " var errorNum = this.errorNum;\n" - " var errorMessage = this.errorMessage;\n" - "\n" - " return \"[ArangoError \" + errorNum + \": \" + errorMessage + \"]\";\n" - " };\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- ArangoDatabase\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup V8Shell\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief drops a collection\n" - "///\n" - "/// @FUN{db._drop(@FA{collection})}\n" - "///\n" - "/// Drops a @FA{collection} and all its indexes.\n" - "///\n" - "/// @FUN{db._drop(@FA{collection-identifier})}\n" - "///\n" - "/// Drops a collection identified by @FA{collection-identifier} and all its\n" - "/// indexes. No error is thrown if there is no such collection.\n" - "///\n" - "/// @FUN{db._drop(@FA{collection-name})}\n" - "///\n" - "/// Drops a collection named @FA{collection-name} and all its indexes. No error\n" - "/// is thrown if there is no such collection.\n" - "///\n" - "/// @EXAMPLES\n" - "///\n" - "/// Drops a collection:\n" - "///\n" - "/// @verbinclude shell_collection-drop-db\n" - "///\n" - "/// Drops a collection identified by name:\n" - "///\n" - "/// @verbinclude shell_collection-drop-name-db\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoDatabase.prototype._drop = function(name) {\n" - " var collection = name;\n" - "\n" - " if (! (name instanceof ArangoCollection)) {\n" - " collection = internal.db._collection(name);\n" - " }\n" - "\n" - " if (collection === null) {\n" - " return;\n" - " }\n" - "\n" - " return collection.drop();\n" - " };\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief truncates a collection\n" - "///\n" - "/// @FUN{db._truncate(@FA{collection})}\n" - "///\n" - "/// Truncates a @FA{collection}, removing all documents but keeping all its\n" - "/// indexes.\n" - "///\n" - "/// @FUN{db._truncate(@FA{collection-identifier})}\n" - "///\n" - "/// Truncates a collection identified by @FA{collection-identified}. No error is\n" - "/// thrown if there is no such collection.\n" - "///\n" - "/// @FUN{db._truncate(@FA{collection-name})}\n" - "///\n" - "/// Truncates a collection named @FA{collection-name}. No error is thrown if\n" - "/// there is no such collection.\n" - "///\n" - "/// @EXAMPLES\n" - "///\n" - "/// Truncates a collection:\n" - "///\n" - "/// @verbinclude shell_collection-truncate-db\n" - "///\n" - "/// Truncates a collection identified by name:\n" - "///\n" - "/// @verbinclude shell_collection-truncate-name-db\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoDatabase.prototype._truncate = function(name) {\n" - " var collection = name;\n" - "\n" - " if (! (name instanceof ArangoCollection)) {\n" - " collection = internal.db._collection(name);\n" - " }\n" - "\n" - " if (collection === null) {\n" - " return;\n" - " }\n" - "\n" - " collection.truncate();\n" - " };\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief finds an index\n" - "///\n" - "/// @FUN{db._index(@FA{index-handle})}\n" - "///\n" - "/// Returns the index with @FA{index-handle} or null if no such index exists.\n" - "///\n" - "/// @EXAMPLES\n" - "///\n" - "/// @verbinclude shell_index-read-db\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoDatabase.prototype._index = function(id) {\n" - " if (id.hasOwnProperty(\"id\")) {\n" - " id = id.id;\n" - " }\n" - "\n" - " var re = /^([0-9]+)\\/([0-9]+)/;\n" - " var pa = re.exec(id);\n" - " var err;\n" - "\n" - " if (pa === null) {\n" - " err = new ArangoError();\n" - " err.errorNum = internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.code;\n" - " err.errorMessage = internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.message;\n" - " throw err;\n" - " }\n" - "\n" - " var col = this._collection(parseInt(pa[1]));\n" - "\n" - " if (col === null) {\n" - " err = new ArangoError();\n" - " err.errorNum = internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code;\n" - " err.errorMessage = internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.message;\n" - " throw err;\n" - " }\n" - "\n" - " var indexes = col.getIndexes();\n" - " var i;\n" - "\n" - " for (i = 0; i < indexes.length; ++i) {\n" - " var index = indexes[i];\n" - "\n" - " if (index.id === id) {\n" - " return index;\n" - " }\n" - " }\n" - "\n" - " return null;\n" - " };\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief drops an index\n" - "///\n" - "/// @FUN{db._dropIndex(@FA{index})}\n" - "///\n" - "/// Drops the @FA{index}. If the index does not exists, then @LIT{false} is\n" - "/// returned. If the index existed and was dropped, then @LIT{true} is\n" - "/// returned. Note that you cannot drop the primary index.\n" - "///\n" - "/// @FUN{db._dropIndex(@FA{index-handle})}\n" - "///\n" - "/// Drops the index with @FA{index-handle}.\n" - "///\n" - "/// @EXAMPLES\n" - "///\n" - "/// @verbinclude shell_index-drop-index-db\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoDatabase.prototype._dropIndex = function(id) {\n" - " if (id.hasOwnProperty(\"id\")) {\n" - " id = id.id;\n" - " }\n" - "\n" - " var re = /^([0-9]+)\\/([0-9]+)/;\n" - " var pa = re.exec(id);\n" - " var err;\n" - "\n" - " if (pa === null) {\n" - " err = new ArangoError();\n" - " err.errorNum = internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.code;\n" - " err.errorMessage = internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.message;\n" - " throw err;\n" - " }\n" - "\n" - " var col = this._collection(parseInt(pa[1]));\n" - "\n" - " if (col === null) {\n" - " err = new ArangoError();\n" - " err.errorNum = internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code;\n" - " err.errorMessage = internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.message;\n" - " throw err;\n" - " }\n" - "\n" - " return col.dropIndex(id);\n" - " };\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief prints a database\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoDatabase.prototype._PRINT = function(seen, path, names, level) {\n" - " internal.output(\"[ArangoDatabase \\\"\" + this._path + \"\\\"]\");\n" - " };\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief strng representation of a database\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoDatabase.prototype.toString = function(seen, path, names, level) {\n" - " return \"[ArangoDatabase \\\"\" + this._path + \"\\\"]\";\n" - " };\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- ArangoCollection\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @addtogroup V8Shell\n" - "/// @{\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief collection is corrupted\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoCollection.STATUS_CORRUPTED = 0;\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief collection is new born\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoCollection.STATUS_NEW_BORN = 1;\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief collection is unloaded\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoCollection.STATUS_UNLOADED = 2;\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief collection is loaded\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoCollection.STATUS_LOADED = 3;\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief collection is unloading\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoCollection.STATUS_UNLOADING = 4;\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief collection is deleted\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoCollection.STATUS_DELETED = 5;\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief document collection\n" - "////////////////////////////////////////////////////////////////////////////////\n" - " \n" - " ArangoCollection.TYPE_DOCUMENT = 2;\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief edge collection\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoCollection.TYPE_EDGE = 3;\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief attachment collection\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoCollection.TYPE_ATTACHMENT = 4;\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief converts collection into an array\n" - "///\n" - "/// @FUN{@FA{collection}.toArray()}\n" - "///\n" - "/// Converts the collection into an array of documents. Never use this call\n" - "/// in a production environment.\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoCollection.prototype.toArray = function() {\n" - " return this.ALL(null, null).documents;\n" - " };\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief truncates a collection\n" - "///\n" - "/// @FUN{@FA{collection}.truncate()}\n" - "///\n" - "/// Truncates a @FA{collection}, removing all documents but keeping all its\n" - "/// indexes.\n" - "///\n" - "/// @EXAMPLES\n" - "///\n" - "/// Truncates a collection:\n" - "///\n" - "/// @verbinclude shell_collection-truncate\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoCollection.prototype.truncate = function() {\n" - " return internal.db._truncate(this);\n" - " };\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief finds an index of a collection\n" - "///\n" - "/// @FUN{@FA{collection}.index(@FA{index-handle})}\n" - "///\n" - "/// Returns the index with @FA{index-handle} or null if no such index exists.\n" - "///\n" - "/// @EXAMPLES\n" - "///\n" - "/// @verbinclude shell_index-read\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoCollection.prototype.index = function(id) {\n" - " var indexes = this.getIndexes();\n" - " var i;\n" - "\n" - " if (typeof id === \"string\") {\n" - " var re = /^([0-9]+)\\/([0-9]+)/;\n" - " var pa = re.exec(id);\n" - "\n" - " if (pa === null) {\n" - " id = this._id + \"/\" + id;\n" - " }\n" - " }\n" - " else if (id.hasOwnProperty(\"id\")) {\n" - " id = id.id;\n" - " }\n" - "\n" - " for (i = 0; i < indexes.length; ++i) {\n" - " var index = indexes[i];\n" - "\n" - " if (index.id === id) {\n" - " return index;\n" - " }\n" - " }\n" - "\n" - " return null;\n" - " };\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief prints a collection\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoCollection.prototype._PRINT = function() {\n" - " var status = type = \"unknown\";\n" - "\n" - " switch (this.status()) {\n" - " case ArangoCollection.STATUS_NEW_BORN: status = \"new born\"; break;\n" - " case ArangoCollection.STATUS_UNLOADED: status = \"unloaded\"; break;\n" - " case ArangoCollection.STATUS_UNLOADING: status = \"unloading\"; break;\n" - " case ArangoCollection.STATUS_LOADED: status = \"loaded\"; break;\n" - " case ArangoCollection.STATUS_CORRUPTED: status = \"corrupted\"; break;\n" - " case ArangoCollection.STATUS_DELETED: status = \"deleted\"; break;\n" - " }\n" - "\n" - " switch (this.type()) {\n" - " case ArangoCollection.TYPE_DOCUMENT: type = \"document\"; break;\n" - " case ArangoCollection.TYPE_EDGE: type = \"edge\"; break;\n" - " case ArangoCollection.TYPE_ATTACHMENT: type = \"attachment\"; break;\n" - " }\n" - "\n" - " internal.output(\"[ArangoCollection \",\n" - " this._id, \n" - " \", \\\"\", this.name(), \"\\\" (type \", type, \", status \", status, \")]\");\n" - " };\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @brief strng representation of a collection\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - " ArangoCollection.prototype.toString = function(seen, path, names, level) {\n" - " return \"[ArangoCollection \" + this._id + \"]\";\n" - " };\n" - "\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "/// @}\n" - "////////////////////////////////////////////////////////////////////////////////\n" - "\n" - "}());\n" - "\n" - "// -----------------------------------------------------------------------------\n" - "// --SECTION-- END-OF-FILE\n" - "// -----------------------------------------------------------------------------\n" - "\n" - "// Local Variables:\n" - "// mode: outline-minor\n" - "// outline-regexp: \"^\\\\(/// @brief\\\\|/// @addtogroup\\\\|// --SECTION--\\\\|/// @page\\\\|/// @\\\\}\\\\)\"\n" - "// End:\n" +static string JS_server_server = string("") + + "/*jslint indent: 2,\n" + + " nomen: true,\n" + + " maxlen: 100,\n" + + " sloppy: true,\n" + + " vars: true,\n" + + " white: true,\n" + + " plusplus: true */\n" + + "/*global require, db, edges, ModuleCache, Module,\n" + + " ArangoCollection, ArangoDatabase,\n" + + " ArangoError, ShapedJson,\n" + + " SYS_DEFINE_ACTION */\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief JavaScript server functions\n" + + "///\n" + + "/// @file\n" + + "///\n" + + "/// DISCLAIMER\n" + + "///\n" + + "/// Copyright 2011-2012 triagens GmbH, Cologne, Germany\n" + + "///\n" + + "/// Licensed under the Apache License, Version 2.0 (the \"License\");\n" + + "/// you may not use this file except in compliance with the License.\n" + + "/// You may obtain a copy of the License at\n" + + "///\n" + + "/// http://www.apache.org/licenses/LICENSE-2.0\n" + + "///\n" + + "/// Unless required by applicable law or agreed to in writing, software\n" + + "/// distributed under the License is distributed on an \"AS IS\" BASIS,\n" + + "/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + + "/// See the License for the specific language governing permissions and\n" + + "/// limitations under the License.\n" + + "///\n" + + "/// Copyright holder is triAGENS GmbH, Cologne, Germany\n" + + "///\n" + + "/// @author Dr. Frank Celler\n" + + "/// @author Copyright 2011-2012, triAGENS GmbH, Cologne, Germany\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- Module \"internal\"\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup V8ModuleInternal\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief internal module\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "(function () {\n" + + " var internal = require(\"internal\");\n" + + " var console = require(\"console\");\n" + + "\n" + + " internal.db = db;\n" + + " internal.edges = db;\n" + + " internal.ArangoCollection = ArangoCollection;\n" + + "\n" + + " if (typeof SYS_DEFINE_ACTION === \"undefined\") {\n" + + " internal.defineAction = function() {\n" + + " console.error(\"SYS_DEFINE_ACTION not available\");\n" + + " };\n" + + " }\n" + + " else {\n" + + " internal.defineAction = SYS_DEFINE_ACTION;\n" + + " }\n" + + "\n" + + " if (typeof SYS_EXECUTE_GLOBAL_CONTEXT_FUNCTION === \"undefined\") {\n" + + " internal.executeGlobalContextFunction = function() {\n" + + " console.error(\"SYS_EXECUTE_GLOBAL_CONTEXT_FUNCTION not available\");\n" + + " };\n" + + " }\n" + + " else {\n" + + " internal.executeGlobalContextFunction = SYS_EXECUTE_GLOBAL_CONTEXT_FUNCTION;\n" + + " }\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- Module \"simple-query\"\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup V8ModuleSimpleQuery\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief simple-query module\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " try {\n" + + " require(\"simple-query\");\n" + + " }\n" + + " catch (err) {\n" + + " console.error(\"while loading 'simple-query' module: %s\", err);\n" + + " }\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- Module \"monkeypatches\"\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup V8ModuleMonkeypatches\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief monkeypatches module\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " try {\n" + + " require(\"monkeypatches\");\n" + + " }\n" + + " catch (err) {\n" + + " console.error(\"while loading 'monkeypatches' module: %s\", err);\n" + + " }\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- ShapedJson\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup V8Shell\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief prints a shaped json\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ShapedJson.prototype._PRINT = function(seen, path, names, level) {\n" + + " if (this instanceof ShapedJson) {\n" + + " internal.printObject(this, seen, path, names, level);\n" + + " }\n" + + " else {\n" + + " internal.output(this.toString());\n" + + " }\n" + + " };\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- ArangoError\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup V8Shell\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief prints an error\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoError.prototype._PRINT = function() {\n" + + " var errorNum = this.errorNum;\n" + + " var errorMessage = this.errorMessage;\n" + + "\n" + + " internal.output(\"[ArangoError \", errorNum, \": \", errorMessage, \"]\");\n" + + " };\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief converts error to string\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoError.prototype.toString = function() {\n" + + " var errorNum = this.errorNum;\n" + + " var errorMessage = this.errorMessage;\n" + + "\n" + + " return \"[ArangoError \" + errorNum + \": \" + errorMessage + \"]\";\n" + + " };\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- ArangoDatabase\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup V8Shell\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief drops a collection\n" + + "///\n" + + "/// @FUN{db._drop(@FA{collection})}\n" + + "///\n" + + "/// Drops a @FA{collection} and all its indexes.\n" + + "///\n" + + "/// @FUN{db._drop(@FA{collection-identifier})}\n" + + "///\n" + + "/// Drops a collection identified by @FA{collection-identifier} and all its\n" + + "/// indexes. No error is thrown if there is no such collection.\n" + + "///\n" + + "/// @FUN{db._drop(@FA{collection-name})}\n" + + "///\n" + + "/// Drops a collection named @FA{collection-name} and all its indexes. No error\n" + + "/// is thrown if there is no such collection.\n" + + "///\n" + + "/// @EXAMPLES\n" + + "///\n" + + "/// Drops a collection:\n" + + "///\n" + + "/// @verbinclude shell_collection-drop-db\n" + + "///\n" + + "/// Drops a collection identified by name:\n" + + "///\n" + + "/// @verbinclude shell_collection-drop-name-db\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoDatabase.prototype._drop = function(name) {\n" + + " var collection = name;\n" + + "\n" + + " if (! (name instanceof ArangoCollection)) {\n" + + " collection = internal.db._collection(name);\n" + + " }\n" + + "\n" + + " if (collection === null) {\n" + + " return;\n" + + " }\n" + + "\n" + + " return collection.drop();\n" + + " };\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief truncates a collection\n" + + "///\n" + + "/// @FUN{db._truncate(@FA{collection})}\n" + + "///\n" + + "/// Truncates a @FA{collection}, removing all documents but keeping all its\n" + + "/// indexes.\n" + + "///\n" + + "/// @FUN{db._truncate(@FA{collection-identifier})}\n" + + "///\n" + + "/// Truncates a collection identified by @FA{collection-identified}. No error is\n" + + "/// thrown if there is no such collection.\n" + + "///\n" + + "/// @FUN{db._truncate(@FA{collection-name})}\n" + + "///\n" + + "/// Truncates a collection named @FA{collection-name}. No error is thrown if\n" + + "/// there is no such collection.\n" + + "///\n" + + "/// @EXAMPLES\n" + + "///\n" + + "/// Truncates a collection:\n" + + "///\n" + + "/// @verbinclude shell_collection-truncate-db\n" + + "///\n" + + "/// Truncates a collection identified by name:\n" + + "///\n" + + "/// @verbinclude shell_collection-truncate-name-db\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoDatabase.prototype._truncate = function(name) {\n" + + " var collection = name;\n" + + "\n" + + " if (! (name instanceof ArangoCollection)) {\n" + + " collection = internal.db._collection(name);\n" + + " }\n" + + "\n" + + " if (collection === null) {\n" + + " return;\n" + + " }\n" + + "\n" + + " collection.truncate();\n" + + " };\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief finds an index\n" + + "///\n" + + "/// @FUN{db._index(@FA{index-handle})}\n" + + "///\n" + + "/// Returns the index with @FA{index-handle} or null if no such index exists.\n" + + "///\n" + + "/// @EXAMPLES\n" + + "///\n" + + "/// @verbinclude shell_index-read-db\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoDatabase.prototype._index = function(id) {\n" + + " if (id.hasOwnProperty(\"id\")) {\n" + + " id = id.id;\n" + + " }\n" + + "\n" + + " var re = /^([0-9]+)\\/([0-9]+)/;\n" + + " var pa = re.exec(id);\n" + + " var err;\n" + + "\n" + + " if (pa === null) {\n" + + " err = new ArangoError();\n" + + " err.errorNum = internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.code;\n" + + " err.errorMessage = internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.message;\n" + + " throw err;\n" + + " }\n" + + "\n" + + " var col = this._collection(parseInt(pa[1]));\n" + + "\n" + + " if (col === null) {\n" + + " err = new ArangoError();\n" + + " err.errorNum = internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code;\n" + + " err.errorMessage = internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.message;\n" + + " throw err;\n" + + " }\n" + + "\n" + + " var indexes = col.getIndexes();\n" + + " var i;\n" + + "\n" + + " for (i = 0; i < indexes.length; ++i) {\n" + + " var index = indexes[i];\n" + + "\n" + + " if (index.id === id) {\n" + + " return index;\n" + + " }\n" + + " }\n" + + "\n" + + " return null;\n" + + " };\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief drops an index\n" + + "///\n" + + "/// @FUN{db._dropIndex(@FA{index})}\n" + + "///\n" + + "/// Drops the @FA{index}. If the index does not exists, then @LIT{false} is\n" + + "/// returned. If the index existed and was dropped, then @LIT{true} is\n" + + "/// returned. Note that you cannot drop the primary index.\n" + + "///\n" + + "/// @FUN{db._dropIndex(@FA{index-handle})}\n" + + "///\n" + + "/// Drops the index with @FA{index-handle}.\n" + + "///\n" + + "/// @EXAMPLES\n" + + "///\n" + + "/// @verbinclude shell_index-drop-index-db\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoDatabase.prototype._dropIndex = function(id) {\n" + + " if (id.hasOwnProperty(\"id\")) {\n" + + " id = id.id;\n" + + " }\n" + + "\n" + + " var re = /^([0-9]+)\\/([0-9]+)/;\n" + + " var pa = re.exec(id);\n" + + " var err;\n" + + "\n" + + " if (pa === null) {\n" + + " err = new ArangoError();\n" + + " err.errorNum = internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.code;\n" + + " err.errorMessage = internal.errors.ERROR_ARANGO_INDEX_HANDLE_BAD.message;\n" + + " throw err;\n" + + " }\n" + + "\n" + + " var col = this._collection(parseInt(pa[1]));\n" + + "\n" + + " if (col === null) {\n" + + " err = new ArangoError();\n" + + " err.errorNum = internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code;\n" + + " err.errorMessage = internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.message;\n" + + " throw err;\n" + + " }\n" + + "\n" + + " return col.dropIndex(id);\n" + + " };\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief prints a database\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoDatabase.prototype._PRINT = function(seen, path, names, level) {\n" + + " internal.output(\"[ArangoDatabase \\\"\" + this._path + \"\\\"]\");\n" + + " };\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief strng representation of a database\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoDatabase.prototype.toString = function(seen, path, names, level) {\n" + + " return \"[ArangoDatabase \\\"\" + this._path + \"\\\"]\";\n" + + " };\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- ArangoCollection\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @addtogroup V8Shell\n" + + "/// @{\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief collection is corrupted\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoCollection.STATUS_CORRUPTED = 0;\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief collection is new born\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoCollection.STATUS_NEW_BORN = 1;\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief collection is unloaded\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoCollection.STATUS_UNLOADED = 2;\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief collection is loaded\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoCollection.STATUS_LOADED = 3;\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief collection is unloading\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoCollection.STATUS_UNLOADING = 4;\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief collection is deleted\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoCollection.STATUS_DELETED = 5;\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief document collection\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + " \n" + + " ArangoCollection.TYPE_DOCUMENT = 2;\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief edge collection\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoCollection.TYPE_EDGE = 3;\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief attachment collection\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoCollection.TYPE_ATTACHMENT = 4;\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief converts collection into an array\n" + + "///\n" + + "/// @FUN{@FA{collection}.toArray()}\n" + + "///\n" + + "/// Converts the collection into an array of documents. Never use this call\n" + + "/// in a production environment.\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoCollection.prototype.toArray = function() {\n" + + " return this.ALL(null, null).documents;\n" + + " };\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief truncates a collection\n" + + "///\n" + + "/// @FUN{@FA{collection}.truncate()}\n" + + "///\n" + + "/// Truncates a @FA{collection}, removing all documents but keeping all its\n" + + "/// indexes.\n" + + "///\n" + + "/// @EXAMPLES\n" + + "///\n" + + "/// Truncates a collection:\n" + + "///\n" + + "/// @verbinclude shell_collection-truncate\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoCollection.prototype.truncate = function() {\n" + + " return internal.db._truncate(this);\n" + + " };\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief finds an index of a collection\n" + + "///\n" + + "/// @FUN{@FA{collection}.index(@FA{index-handle})}\n" + + "///\n" + + "/// Returns the index with @FA{index-handle} or null if no such index exists.\n" + + "///\n" + + "/// @EXAMPLES\n" + + "///\n" + + "/// @verbinclude shell_index-read\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoCollection.prototype.index = function(id) {\n" + + " var indexes = this.getIndexes();\n" + + " var i;\n" + + "\n" + + " if (typeof id === \"string\") {\n" + + " var re = /^([0-9]+)\\/([0-9]+)/;\n" + + " var pa = re.exec(id);\n" + + "\n" + + " if (pa === null) {\n" + + " id = this._id + \"/\" + id;\n" + + " }\n" + + " }\n" + + " else if (id.hasOwnProperty(\"id\")) {\n" + + " id = id.id;\n" + + " }\n" + + "\n" + + " for (i = 0; i < indexes.length; ++i) {\n" + + " var index = indexes[i];\n" + + "\n" + + " if (index.id === id) {\n" + + " return index;\n" + + " }\n" + + " }\n" + + "\n" + + " return null;\n" + + " };\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief prints a collection\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoCollection.prototype._PRINT = function() {\n" + + " var status = type = \"unknown\";\n" + + "\n" + + " switch (this.status()) {\n" + + " case ArangoCollection.STATUS_NEW_BORN: status = \"new born\"; break;\n" + + " case ArangoCollection.STATUS_UNLOADED: status = \"unloaded\"; break;\n" + + " case ArangoCollection.STATUS_UNLOADING: status = \"unloading\"; break;\n" + + " case ArangoCollection.STATUS_LOADED: status = \"loaded\"; break;\n" + + " case ArangoCollection.STATUS_CORRUPTED: status = \"corrupted\"; break;\n" + + " case ArangoCollection.STATUS_DELETED: status = \"deleted\"; break;\n" + + " }\n" + + "\n" + + " switch (this.type()) {\n" + + " case ArangoCollection.TYPE_DOCUMENT: type = \"document\"; break;\n" + + " case ArangoCollection.TYPE_EDGE: type = \"edge\"; break;\n" + + " case ArangoCollection.TYPE_ATTACHMENT: type = \"attachment\"; break;\n" + + " }\n" + + "\n" + + " internal.output(\"[ArangoCollection \",\n" + + " this._id, \n" + + " \", \\\"\", this.name(), \"\\\" (type \", type, \", status \", status, \")]\");\n" + + " };\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @brief strng representation of a collection\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + " ArangoCollection.prototype.toString = function(seen, path, names, level) {\n" + + " return \"[ArangoCollection \" + this._id + \"]\";\n" + + " };\n" + + "\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "/// @}\n" + + "////////////////////////////////////////////////////////////////////////////////\n" + + "\n" + + "}());\n" + + "\n" + + "// -----------------------------------------------------------------------------\n" + + "// --SECTION-- END-OF-FILE\n" + + "// -----------------------------------------------------------------------------\n" + + "\n" + + "// Local Variables:\n" + + "// mode: outline-minor\n" + + "// outline-regexp: \"^\\\\(/// @brief\\\\|/// @addtogroup\\\\|// --SECTION--\\\\|/// @page\\\\|/// @\\\\}\\\\)\"\n" + + "// End:\n" ; diff --git a/lib/Scheduler/ListenTask.h b/lib/Scheduler/ListenTask.h index 1c8ad4f29d..cdce5aa28d 100644 --- a/lib/Scheduler/ListenTask.h +++ b/lib/Scheduler/ListenTask.h @@ -33,10 +33,10 @@ #include #endif -#ifdef TRI_HAVE_WINSOCK2_H -#include -#include -#endif +#ifdef TRI_HAVE_WINSOCK2_H +#include +#include +#endif #include "Scheduler/Task.h"