1
0
Fork 0

added query functions

This commit is contained in:
Jan Steemann 2012-04-23 18:05:28 +02:00
parent 5f95f76841
commit e083e5e00d
12 changed files with 495 additions and 106 deletions

View File

@ -0,0 +1,251 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief Ahuacatl, query language functions
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2010-2012 triagens GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Jan Steemann
/// @author Copyright 2012, triagens GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#include "Ahuacatl/ahuacatl-functions.h"
// -----------------------------------------------------------------------------
// --SECTION-- private macros
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Ahuacatl
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief shorthand to register a query function and process the result
////////////////////////////////////////////////////////////////////////////////
#define REGISTER_FUNCTION(internalName, externalName, deterministic, minArgs, maxArgs) \
result &= TRI_RegisterFunctionAql (functions, internalName, "AHUACATL_" externalName, deterministic, minArgs, maxArgs);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- private functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Ahuacatl
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief hash function used to hash function struct
////////////////////////////////////////////////////////////////////////////////
static uint64_t HashFunction (TRI_associative_pointer_t* array,
void const* element) {
TRI_aql_function_t* function = (TRI_aql_function_t*) element;
return TRI_FnvHashString(function->_externalName);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief comparison function used to determine function name equality
////////////////////////////////////////////////////////////////////////////////
static bool EqualName (TRI_associative_pointer_t* array,
void const* key,
void const* element) {
TRI_aql_function_t* function = (TRI_aql_function_t*) element;
return TRI_EqualString(key, function->_externalName);
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- public functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Ahuacatl
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief initialise the array with the function declarations
////////////////////////////////////////////////////////////////////////////////
TRI_associative_pointer_t* TRI_InitialiseFunctionsAql (void) {
TRI_associative_pointer_t* functions;
bool result = true;
functions = (TRI_associative_pointer_t*) TRI_Allocate(sizeof(TRI_associative_pointer_t));
if (!functions) {
return NULL;
}
TRI_InitAssociativePointer(functions,
TRI_HashStringKeyAssociativePointer,
HashFunction,
EqualName,
NULL);
// cast functions
REGISTER_FUNCTION("TONUMBER", "CAST_NUMBER", true, 1, 1);
REGISTER_FUNCTION("TOSTRING", "CAST_STRING", true, 1, 1);
REGISTER_FUNCTION("TOBOOL", "CAST_BOOL", true, 1, 1);
REGISTER_FUNCTION("TONULL", "CAST_NULL", true, 1, 1);
// type check functions
REGISTER_FUNCTION("ISNULL", "IS_NULL", true, 1, 1);
REGISTER_FUNCTION("ISBOOL", "IS_BOOL", true, 1, 1);
REGISTER_FUNCTION("ISNUMBER", "IS_NUMBER", true, 1, 1);
REGISTER_FUNCTION("ISSTRING", "IS_STRING", true, 1, 1);
REGISTER_FUNCTION("ISLIST", "IS_LIST", true, 1, 1);
REGISTER_FUNCTION("ISDOCUMENT", "IS_DOCUMENT", true, 1, 1);
// string concat
REGISTER_FUNCTION("CONCAT", "STRING_CONCAT", true, 2, 2);
// numeric functions
// string functions
// misc functions
REGISTER_FUNCTION("LENGTH", "LENGTH", true, 1, 1);
if (!result) {
TRI_FreeFunctionsAql(functions);
return NULL;
}
return functions;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief free the array with the function declarations
////////////////////////////////////////////////////////////////////////////////
void TRI_FreeFunctionsAql (TRI_associative_pointer_t* functions) {
size_t i;
for (i = 0; i < functions->_nrAlloc; ++i) {
TRI_aql_function_t* function = (TRI_aql_function_t*) functions->_table[i];
if (!function) {
continue;
}
TRI_Free(function->_externalName);
TRI_Free(function->_internalName);
TRI_Free(function);
}
TRI_DestroyAssociativePointer(functions);
TRI_Free(functions);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief check if a function name is valid
////////////////////////////////////////////////////////////////////////////////
bool TRI_IsValidFunctionAql (TRI_associative_pointer_t* functions,
const char* const externalName) {
if (TRI_LookupByKeyAssociativePointer(functions, externalName)) {
return true;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief get internal function name for an external one
////////////////////////////////////////////////////////////////////////////////
char* TRI_GetInternalNameFunctionAql (TRI_associative_pointer_t* functions,
const char* const externalName) {
TRI_aql_function_t* function;
function = (TRI_aql_function_t*) TRI_LookupByKeyAssociativePointer(functions, externalName);
if (!function) {
return NULL;
}
return function->_internalName;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief register a function name
////////////////////////////////////////////////////////////////////////////////
bool TRI_RegisterFunctionAql (TRI_associative_pointer_t* functions,
const char* const externalName,
const char* const internalName,
const bool isDeterministic,
const int minArgs,
const int maxArgs) {
TRI_aql_function_t* function;
function = (TRI_aql_function_t*) TRI_Allocate(sizeof(TRI_aql_function_t));
if (!function) {
return false;
}
function->_externalName = TRI_DuplicateString(externalName);
if (!function->_externalName) {
TRI_Free(function);
return false;
}
function->_internalName = TRI_DuplicateString(internalName);
if (!function->_internalName) {
TRI_Free(function->_externalName);
TRI_Free(function);
return false;
}
function->_minArgs = minArgs;
function->_maxArgs = maxArgs;
if (TRI_InsertKeyAssociativePointer(functions, externalName, function, false)) {
// function already registered
TRI_Free(function->_externalName);
TRI_Free(function->_internalName);
TRI_Free(function);
return false;
}
return true;
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
// End:

View File

@ -0,0 +1,106 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief Ahuacatl, query language functions
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2010-2012 triagens GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Jan Steemann
/// @author Copyright 2012, triagens GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifndef TRIAGENS_DURHAM_AHUACATL_QUERY_FUNCTIONS_H
#define TRIAGENS_DURHAM_AHUACATL_QUERY_FUNCTIONS_H 1
#include <BasicsC/common.h>
#include <BasicsC/associative.h>
#include <BasicsC/hashes.h>
#include <BasicsC/strings.h>
#ifdef __cplusplus
extern "C" {
#endif
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Ahuacatl
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief query function data structure
////////////////////////////////////////////////////////////////////////////////
typedef struct TRI_aql_function_s {
char* _externalName;
char* _internalName;
int _minArgs;
int _maxArgs;
bool _isDeterministic;
}
TRI_aql_function_t;
////////////////////////////////////////////////////////////////////////////////
/// @brief initialise the array with the function declarations
////////////////////////////////////////////////////////////////////////////////
TRI_associative_pointer_t* TRI_InitialiseFunctionsAql (void);
////////////////////////////////////////////////////////////////////////////////
/// @brief free the array with the function declarations
////////////////////////////////////////////////////////////////////////////////
void TRI_FreeFunctionsAql (TRI_associative_pointer_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief check if a function name is valid
////////////////////////////////////////////////////////////////////////////////
bool TRI_IsValidFunctionAql (TRI_associative_pointer_t*, const char* const);
////////////////////////////////////////////////////////////////////////////////
/// @brief get internal function name for an external one
////////////////////////////////////////////////////////////////////////////////
char* TRI_GetInternalNameFunctionAql (TRI_associative_pointer_t*, const char* const);
////////////////////////////////////////////////////////////////////////////////
/// @brief register a function name
////////////////////////////////////////////////////////////////////////////////
bool TRI_RegisterFunctionAql (TRI_associative_pointer_t*,
const char* const,
const char* const,
const bool,
const int,
const int);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}
#endif
#endif
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
// End:

View File

@ -26,6 +26,7 @@
////////////////////////////////////////////////////////////////////////////////
#include "Ahuacatl/ast-node.h"
#include "Ahuacatl/ahuacatl-functions.h"
// -----------------------------------------------------------------------------
// --SECTION-- private macros
@ -1368,13 +1369,27 @@ TRI_aql_node_t* TRI_CreateNodeFcallAql (TRI_aql_parse_context_t* const context,
const char* const name,
const TRI_aql_node_t* const parameters) {
TRI_aql_node_fcall_t* node;
TRI_aql_function_t* function;
TRI_associative_pointer_t* functions;
assert(context);
assert(context->_vocbase);
if (!name || !parameters) {
ABORT_OOM
}
// TODO: validate func name
functions = context->_vocbase->_functionsAql;
assert(functions);
// TODO: normalize function name
function = (TRI_aql_function_t*) TRI_LookupByKeyAssociativePointer(functions, (void*) name);
if (!function) {
// function name is unknown
TRI_SetErrorAql(context, TRI_ERROR_QUERY_FUNCTION_NAME_UNKNOWN, name);
return NULL;
}
node = (TRI_aql_node_fcall_t*) TRI_Allocate(sizeof(TRI_aql_node_fcall_t));
@ -1384,7 +1399,7 @@ TRI_aql_node_t* TRI_CreateNodeFcallAql (TRI_aql_parse_context_t* const context,
InitNode(context, (TRI_aql_node_t*) node, AQL_NODE_FCALL);
node->_name = (char*) name;
node->_name = function->_internalName;
node->_parameters = (TRI_aql_node_t*) parameters;
return (TRI_aql_node_t*) node;

View File

@ -98,13 +98,16 @@ static bool EqualVariable (TRI_associative_pointer_t* array,
/// @brief create and initialize a parse context
////////////////////////////////////////////////////////////////////////////////
TRI_aql_parse_context_t* TRI_CreateParseContextAql (const char* const query) {
TRI_aql_parse_context_t* TRI_CreateParseContextAql (TRI_vocbase_t* vocbase,
const char* const query) {
TRI_aql_parse_context_t* context;
context = (TRI_aql_parse_context_t*) TRI_Allocate(sizeof(TRI_aql_parse_context_t));
if (!context) {
return NULL;
}
context->_vocbase = vocbase;
TRI_InitVectorPointer(&context->_stack);
TRI_InitVectorPointer(&context->_nodes);

View File

@ -34,6 +34,7 @@
#include <BasicsC/vector.h>
#include <BasicsC/associative.h>
#include "VocBase/vocbase.h"
#include "Ahuacatl/error.h"
#ifdef __cplusplus
@ -92,6 +93,7 @@ typedef struct TRI_aql_parse_context_s {
TRI_vector_pointer_t _strings;
TRI_vector_pointer_t _stack;
TRI_aql_error_t _error;
TRI_vocbase_t* _vocbase;
void* _first;
char* _query;
}
@ -114,7 +116,8 @@ TRI_aql_parse_context_t;
/// @brief create and initialize a parse context
////////////////////////////////////////////////////////////////////////////////
TRI_aql_parse_context_t* TRI_CreateParseContextAql (const char* const);
TRI_aql_parse_context_t* TRI_CreateParseContextAql (TRI_vocbase_t*,
const char* const);
////////////////////////////////////////////////////////////////////////////////
/// @brief free a parse context

View File

@ -146,6 +146,7 @@ avocado_SOURCES = \
HttpsServer/HttpsServerImpl.cpp \
PriorityQueue/pqueueindex.c \
PriorityQueue/priorityqueue.c \
Ahuacatl/ahuacatl-functions.c \
Ahuacatl/ast-codegen-js.c \
Ahuacatl/ast-dump.c \
Ahuacatl/ast-node.c \

View File

@ -277,6 +277,7 @@ am_avocado_OBJECTS = Admin/ApplicationAdminServer.$(OBJEXT) \
HttpsServer/HttpsServerImpl.$(OBJEXT) \
PriorityQueue/pqueueindex.$(OBJEXT) \
PriorityQueue/priorityqueue.$(OBJEXT) \
Ahuacatl/ahuacatl-functions.$(OBJEXT) \
Ahuacatl/ast-codegen-js.$(OBJEXT) Ahuacatl/ast-dump.$(OBJEXT) \
Ahuacatl/ast-node.$(OBJEXT) Ahuacatl/error.$(OBJEXT) \
Ahuacatl/grammar.$(OBJEXT) Ahuacatl/parser.$(OBJEXT) \
@ -751,6 +752,7 @@ avocado_SOURCES = \
HttpsServer/HttpsServerImpl.cpp \
PriorityQueue/pqueueindex.c \
PriorityQueue/priorityqueue.c \
Ahuacatl/ahuacatl-functions.c \
Ahuacatl/ast-codegen-js.c \
Ahuacatl/ast-dump.c \
Ahuacatl/ast-node.c \
@ -1643,6 +1645,8 @@ Ahuacatl/$(am__dirstamp):
Ahuacatl/$(DEPDIR)/$(am__dirstamp):
@$(MKDIR_P) Ahuacatl/$(DEPDIR)
@: > Ahuacatl/$(DEPDIR)/$(am__dirstamp)
Ahuacatl/ahuacatl-functions.$(OBJEXT): Ahuacatl/$(am__dirstamp) \
Ahuacatl/$(DEPDIR)/$(am__dirstamp)
Ahuacatl/ast-codegen-js.$(OBJEXT): Ahuacatl/$(am__dirstamp) \
Ahuacatl/$(DEPDIR)/$(am__dirstamp)
Ahuacatl/ast-dump.$(OBJEXT): Ahuacatl/$(am__dirstamp) \
@ -1895,6 +1899,7 @@ mostlyclean-compile:
-rm -f Admin/RestAdminLogHandler.$(OBJEXT)
-rm -f Admin/RestBaseHandler.$(OBJEXT)
-rm -f Admin/RestVersionHandler.$(OBJEXT)
-rm -f Ahuacatl/ahuacatl-functions.$(OBJEXT)
-rm -f Ahuacatl/ast-codegen-js.$(OBJEXT)
-rm -f Ahuacatl/ast-dump.$(OBJEXT)
-rm -f Ahuacatl/ast-node.$(OBJEXT)
@ -2121,6 +2126,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@Admin/$(DEPDIR)/RestAdminLogHandler.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@Admin/$(DEPDIR)/RestBaseHandler.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@Admin/$(DEPDIR)/RestVersionHandler.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@Ahuacatl/$(DEPDIR)/ahuacatl-functions.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@Ahuacatl/$(DEPDIR)/ast-codegen-js.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@Ahuacatl/$(DEPDIR)/ast-dump.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@Ahuacatl/$(DEPDIR)/ast-node.Po@am__quote@

View File

@ -2299,7 +2299,7 @@ static v8::Handle<v8::Value> JS_RunAhuacatl (v8::Arguments const& argv) {
TRI_json_t* parameters = NULL;
TRI_aql_parse_context_t* context;
context = TRI_CreateParseContextAql(queryString.c_str());
context = TRI_CreateParseContextAql(vocbase, queryString.c_str());
if (!context) {
return scope.Close(v8::ThrowException(v8::String::New("out of memory")));
}

View File

@ -45,6 +45,7 @@
#include "VocBase/simple-collection.h"
#include "VocBase/synchroniser.h"
#include "VocBase/query-functions.h"
#include "Ahuacatl/ahuacatl-functions.h"
// -----------------------------------------------------------------------------
// --SECTION-- private variables
@ -1041,7 +1042,8 @@ TRI_vocbase_t* TRI_OpenVocBase (char const* path) {
vocbase = TRI_Allocate(sizeof(TRI_vocbase_t));
vocbase->_cursors = TRI_CreateShadowsQueryCursor();
vocbase->_functions = TRI_InitialiseQueryFunctions();
vocbase->_functionsAql = TRI_InitialiseFunctionsAql();
vocbase->_functions = TRI_InitialiseQueryFunctions(); // deprecated
vocbase->_lockFile = lockFile;
vocbase->_path = TRI_DuplicateString(path);
@ -1147,7 +1149,8 @@ void TRI_DestroyVocBase (TRI_vocbase_t* vocbase) {
TRI_DestroyVectorPointer(&vocbase->_deadCollections);
// free query functions
TRI_FreeQueryFunctions(vocbase->_functions);
TRI_FreeQueryFunctions(vocbase->_functions); // deprecated
TRI_FreeFunctionsAql(vocbase->_functionsAql);
// free the cursors
TRI_FreeShadowStore(vocbase->_cursors);

View File

@ -303,7 +303,8 @@ typedef struct TRI_vocbase_s {
TRI_thread_t _compactor;
struct TRI_shadow_store_s* _cursors;
TRI_associative_pointer_t* _functions;
TRI_associative_pointer_t* _functions; // deprecated
TRI_associative_pointer_t* _functionsAql;
}
TRI_vocbase_t;

View File

@ -893,6 +893,39 @@ function AHUACATL_STRING_CONCAT (lhs, rhs) {
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief cast to null
///
/// the operand can have any type, always returns null
////////////////////////////////////////////////////////////////////////////////
function AHUACATL_CAST_NULL (value) {
return null;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief cast to a bool
///
/// the operand can have any type, always returns a bool
////////////////////////////////////////////////////////////////////////////////
function AHUACATL_CAST_BOOL (value) {
switch (AHUACATL_TYPEWEIGHT(value)) {
case AHUACATL_TYPEWEIGHT_NULL:
return false;
case AHUACATL_TYPEWEIGHT_BOOL:
return value;
case AHUACATL_TYPEWEIGHT_NUMBER:
return (value != 0);
case AHUACATL_TYPEWEIGHT_STRING:
return (value != '');
case AHUACATL_TYPEWEIGHT_LIST:
return (value.length > 0);
case AHUACATL_TYPEWEIGHT_DOCUMENT:
return (AHUACATL_KEYS(value).length > 0);
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief cast to a number
///
@ -936,39 +969,6 @@ function AHUACATL_CAST_STRING (value) {
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief cast to a bool
///
/// the operand can have any type, always returns a bool
////////////////////////////////////////////////////////////////////////////////
function AHUACATL_CAST_BOOL (value) {
switch (AHUACATL_TYPEWEIGHT(value)) {
case AHUACATL_TYPEWEIGHT_NULL:
return false;
case AHUACATL_TYPEWEIGHT_BOOL:
return value;
case AHUACATL_TYPEWEIGHT_NUMBER:
return (value != 0);
case AHUACATL_TYPEWEIGHT_STRING:
return (value != '');
case AHUACATL_TYPEWEIGHT_LIST:
return (value.length > 0);
case AHUACATL_TYPEWEIGHT_DOCUMENT:
return (AHUACATL_KEYS(value).length > 0);
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief cast to null
///
/// the operand can have any type, always returns null
////////////////////////////////////////////////////////////////////////////////
function AHUACATL_CAST_NULL (value) {
return null;
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
@ -983,23 +983,13 @@ function AHUACATL_CAST_NULL (value) {
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief test if value is of type string
/// @brief test if value is of type null
///
/// returns a bool
////////////////////////////////////////////////////////////////////////////////
function AHUACATL_IS_STRING (value) {
return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_STRING);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief test if value is of type number
///
/// returns a bool
////////////////////////////////////////////////////////////////////////////////
function AHUACATL_IS_NUMBER (value) {
return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_NUMBER);
function AHUACATL_IS_NULL (value) {
return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_NULL);
}
////////////////////////////////////////////////////////////////////////////////
@ -1013,13 +1003,23 @@ function AHUACATL_IS_BOOL (value) {
}
////////////////////////////////////////////////////////////////////////////////
/// @brief test if value is of type null
/// @brief test if value is of type number
///
/// returns a bool
////////////////////////////////////////////////////////////////////////////////
function AHUACATL_IS_NULL (value) {
return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_NULL);
function AHUACATL_IS_NUMBER (value) {
return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_NUMBER);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief test if value is of type string
///
/// returns a bool
////////////////////////////////////////////////////////////////////////////////
function AHUACATL_IS_STRING (value) {
return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_STRING);
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -895,6 +895,39 @@ static string JS_server_ahuacatl =
"////////////////////////////////////////////////////////////////////////////////\n"
"\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"/// @brief cast to null\n"
"///\n"
"/// the operand can have any type, always returns null\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"\n"
"function AHUACATL_CAST_NULL (value) {\n"
" return null;\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).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"
@ -938,39 +971,6 @@ static string JS_server_ahuacatl =
"}\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).length > 0);\n"
" }\n"
"}\n"
"\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"/// @brief cast to null\n"
"///\n"
"/// the operand can have any type, always returns null\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"\n"
"function AHUACATL_CAST_NULL (value) {\n"
" return null;\n"
"}\n"
"\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"/// @}\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"\n"
@ -984,23 +984,13 @@ static string JS_server_ahuacatl =
"////////////////////////////////////////////////////////////////////////////////\n"
"\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"/// @brief test if value is of type string\n"
"/// @brief test if value is of type null\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 number\n"
"///\n"
"/// returns a bool\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"\n"
"function AHUACATL_IS_NUMBER (value) {\n"
" return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_NUMBER);\n"
"function AHUACATL_IS_NULL (value) {\n"
" return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_NULL);\n"
"}\n"
"\n"
"////////////////////////////////////////////////////////////////////////////////\n"
@ -1014,13 +1004,23 @@ static string JS_server_ahuacatl =
"}\n"
"\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"/// @brief test if value is of type null\n"
"/// @brief test if value is of type number\n"
"///\n"
"/// returns a bool\n"
"////////////////////////////////////////////////////////////////////////////////\n"
"\n"
"function AHUACATL_IS_NULL (value) {\n"
" return (AHUACATL_TYPEWEIGHT(value) === AHUACATL_TYPEWEIGHT_NULL);\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"