170 std::size_t first_char = tree_val.
m_String.find_first_not_of(
" \t\r\n");
171 if (first_char == std::string::npos)
178 if (ch ==
'y' || ch ==
'n' || ch ==
't' || ch ==
'f') {
188 else if (
isdigit(ch) || ch ==
'-' || ch ==
'+' || ch ==
'.') {
191 if (errno != 0 && !tree_val.
m_Int) {
212 std::vector<CPromoteRule>::iterator iter =
223 return (*iter).m_PromotedType;
239 objects::CScope* scope)
269 if ((qnode.
GetOrig().length() >= 2) &&
270 ((qnode.
GetOrig()[0] ==
'\"' &&
278 else if ((qnode.
GetOrig().length() >= 2) &&
279 ((qnode.
GetOrig()[0] ==
'\'' &&
305 switch (field_type) {
395 switch (field_type) {
449 for (
size_t i=1;
i<args.size(); ++
i) {
490 string msg =
"Unable to compare: " +
491 args[0]->GetValue().GetOriginalText() +
493 args[
i]->GetValue().GetOriginalText() +
494 " using operator: " +
550 if (!data_available) {
568 string msg =
"Unable to compare: " +
569 arg1->
GetValue().GetOriginalText() +
571 arg2->
GetValue().GetOriginalText() +
572 " using operator: " +
573 qnode.
GetValue().GetNodeTypeAsString();
580 eval_res->
SetValue(qnode->IsNot() ?
true :
false);
611 return promoted_type;
623 _ASSERT(macro_query_exec && node_value);
625 if (macro_query_exec && node_value) {
638 vector<CRef<CQueryNodeValue>> arguments;
639 arguments.reserve(user_args.size());
640 for (
auto&& it : user_args) {
643 arguments.push_back(user_obj);
647 size_t arg_size = arguments.size();
649 for (
auto& iter : arguments) {
656 NCBI_THROW(macro::CMacroExecException, eWrongArguments,
657 "Wrong type of argument in function: " + qnode.
GetValue().GetOrig());
669 string fname = qnode->GetOriginalText();
678 for (
size_t i = 0;
i < args.size(); ++
i) {
729 string identifier = qnode.
GetValue().GetOriginalText();
734 bool found = mqe->
GetMacroRep()->GetNodeValue(identifier, *res);
753 if (args.size() == 0) {
756 "No arguments for logical function " +
757 qnode->GetNodeTypeAsString());
768 if (args.size() != 2) {
770 "Error: Binary operator: " +
771 qnode.
GetValue().GetNodeTypeAsString() +
786 "Error: Unable to convert field: " +
787 args[0]->GetValue().GetStrValue() +
788 " to boolean value.");
791 }
else if (args[0]->GetValue().IsValue()) {
800 "Error: Unable to convert field: " +
801 args[1]->GetValue().GetStrValue() +
802 " to boolean value.");
805 }
else if (args[1]->GetValue().IsValue()) {
829 if (args.size() != 1) {
831 "Error: Unary NOT operator has: " +
842 "Error: Unable to convert field: " +
843 args[0]->GetValue().GetStrValue() +
844 " to boolean value.");
847 }
else if (args[0]->GetValue().IsValue()) {
856 "Error: Unexpected logical operand: " +
857 qnode->GetOriginalText());
871 if (args.size() == 0) {
874 "No arguments for logical function " +
875 qnode->GetNodeTypeAsString());
888 if (args.size() < 2) {
890 "Error: n-ary operator: " +
891 qnode.
GetValue().GetNodeTypeAsString() +
906 for (
size_t i = 0;
i < args.size(); ++
i) {
917 if (!args[
i]->GetValue().IsValue()) {
924 if (
val->IsDataField()) {
928 "Error: Unable to convert field: " +
929 args[
i]->GetValue().GetStrValue() +
930 " to boolean value.");
932 val->SetValue(
val->m_Bool);
936 val->SetValue(
val->m_Bool);
942 if (!
val->GetValue()) {
948 if (
val->GetValue()) {
964 "Error: Unexpected logical operand: " +
965 qnode->GetOriginalText());
1141 if (args.size() != 2) {
1143 "Error: Binary operator " +
1144 qnode.
GetValue().GetNodeTypeAsString() +
1175 eval_res->
SetValue(qnode->IsNot() ?
false :
true);
1180 eval_res->
SetValue(qnode->IsNot() ?
false :
true);
1184 eval_res->
SetValue(qnode->IsNot() ?
true :
false);
1240 objects::CSeq_id seq_id1(val1->
m_String);
1241 objects::CSeq_id seq_id2(val2->
m_String);
1250 "Object Manager Error: " +
1262 "Error - Unhandled comparison operator: " +
1263 qnode.
GetValue().GetNodeTypeAsString());
1290 if (args.size() <= 1) {
1292 "Error: 'IN' operator has " +
1304 for (
size_t i=1;
i<args.size() && !found; ++
i) {
1354 objects::CSeq_id seq_id1(val1->
m_String);
1355 objects::CSeq_id seq_id2(val2->
m_String);
1362 "Object Manager Error: " +
1376 "Error - Unhandled comparison operator: " +
1377 qnode.
GetValue().GetNodeTypeAsString());
1536 if (args.size() != 2) {
1538 "Error: Binary operator " +
1539 qnode.
GetValue().GetNodeTypeAsString() +
1571 "Error - Unhandled comparison operator: " +
1572 qnode.
GetValue().GetNodeTypeAsString());
1740 if (args.size() != 2) {
1742 "Error: Binary operator " +
1743 qnode.
GetValue().GetNodeTypeAsString() +
1764 switch (node_type) {
1840 "Error - Unhandled operator: " +
1841 qnode.
GetValue().GetNodeTypeAsString());
1847 "Error - Unhandled comparison operator: " +
1848 qnode.
GetValue().GetNodeTypeAsString());
1874 if (args.size() != 3) {
1876 "Error: Ternary operator " +
1877 qnode.
GetValue().GetNodeTypeAsString() +
1955 bool is_between = (is_gt == is_lt) || is_eq;
1963 "Error - Unhandled comparison operator: " +
1964 qnode.
GetValue().GetNodeTypeAsString());
bool ResolveRTVar(const string &identifier, CQueryNodeValue &v)
Return the value of RT variable in node "v".
macro::CMacroRep * GetMacroRep()
CRef< CQueryNodeValue > GetOrCreateRTVar(const string &name)
Gets or creates run-time vars (used in assignment in Do clause)
Expression evaluation visitor functor.
class CQueryExecException
virtual void Evaluate(CQueryParseTree::TNode &node)
Function implements the assignment operator.
class CQueryFuncEqualityCompares
virtual void InitTypePromotionRules(CQueryParseNode::EType op_type)
Initialize promotion table for eqaulity comparisons (e.g. == or In)
virtual void Evaluate(CQueryParseTree::TNode &qnode)
Function implements functions calls in the do section of macro.
class CQueryFuncGtLtCompares
virtual void InitTypePromotionRules(CQueryParseNode::EType op_type)
Initialize promotion table for the comparisons.
CQueryFuncLike(NStr::ECase c=NStr::eCase)
Ctor.
virtual void Evaluate(CQueryParseTree::TNode &qnode)
Evaluate the node to see if 'Like' returns true.
virtual void InitTypePromotionRules(CQueryParseNode::EType op_type)
Initialize promotion rules for 'Like' comparison.
virtual void Evaluate(CQueryParseTree::TNode &qnode)
Function is a placeholder for run-time variable processing.
Int8 m_Int
Int data, if data was an integer or converted into one.
bool HasPromoteType(size_t arg_idx, QueryValueType::EBaseType t1, QueryValueType::EBaseType t2)
Return true if there is a promote entry defined for the specified argument pair at 'idx' only if the ...
bool AssignToRef(const CQueryNodeValue &source)
void SetFieldID(TFieldIDType fid)
CQueryParseTree::TNode * GetQueryNode()
Get corresponding query node.
void PromoteTo(QueryValueType::EBaseType pt)
Convert current value to the type 'pt'. Does not update m_DataType.
bool m_Bool
Bool data, if data base a constant boolean or converted into one.
virtual void Reset()
Reset user object (for reuse without reallocation)
string m_String
String data, if data came from a string or data field in the tree.
void SetIsDataField(bool b)
Set/Get to indicate if this is a field from the data source or simple string.
double m_Double
Floating point data, if data was a double or converted into one.
void SetDataType(QueryValueType::EBaseType dt)
Set/get underlying data type.
objects::CScope * GetScope()
void AddPromotedType(const CPromoteRule &pr)
Append a new promote rule.
bool GetValue() const
Set boolean result value (result of (sub)expression).
TFieldIDType GetFieldID() const
void SetScope(objects::CScope *s)
Set/Get CScope used for comparing seq-ids.
void SetRef(CRef< CQueryNodeValue > node)
QueryValueType::EBaseType GetPromoteType(size_t arg_idx)
Get the promotion type for a specific argument pair, or eUndefined if no rule is available.
QueryValueType::EBaseType GetDataType() const
EStringMatching
String matching algorithms.
@ ePlainSearch
Plain search.
bool MatchString(const CTempString &str)
Matches a string to a pattern, using the specified string matching algorithm.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
definition of a Culling tree
Base class for query node user defined object.
Include a standard set of the NCBI C++ Toolkit most basic headers.
static const char * str(char *buf, int n)
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
const string & GetMsg(void) const
Get message string.
static bool Match(const objects::CSeq_id &id1, const objects::CSeq_id &id2, objects::CScope *scope=NULL)
check to see if two seq-ids are identical.
CRef< C > Ref(C *object)
Helper functions to get CRef<> and CConstRef<> objects.
const string & GetOrig() const
const IQueryParseUserObject * GetUserObject() const
Get user object.
string GetNodeTypeAsString() const
Return query node type as a string (for debugging output)
vector< CQueryParseTree::TNode * > TArgVector
Vector for easy argument access.
virtual TFieldID GetIdentifier(const std::string &)
bool IsValue() const
Returns TRUE if node is value (INT, String, etc.)
virtual bool ResolveIdentifier(const std::string &, bool &)
If query has an identifier, this will resolve it in an application-specific way.
void SetUserObject(IQueryParseUserObject *obj)
virtual void CallFunction(const string &name, CQueryParseTree::TNode &node)
Extend this function to look up and invoke functions that appear in the query.
virtual CQueryParseNode::EType IdentifierType(const std::string &)
Some applications may know the type of an identifier.
void MakeArgVector(CQueryParseTree::TNode &qnode, TArgVector &args)
Created vector of arguments (translate sub-nodes to vector)
const string & GetStrValue() const
virtual bool HasIdentifier(const std::string &)
bool IsLogic() const
Returns TRUE if node describes logical operation (AND, OR, etc.)
@ eIdentifier
Identifier like db.field (Org, Fld12, etc.)
@ eFloatConst
Floating point const.
@ eIntConst
Integer const.
@ eBoolConst
Boolean (TRUE or FALSE)
@ eString
String ("free text")
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
static bool StringToBool(const CTempString str)
Convert string to bool.
static string SizetToString(size_t value, TNumToStringFlags flags=0, int base=10)
Convert size_t to string.
static int CompareNocase(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2)
Case-insensitive compare of a substring with another string.
static int StringToInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to int.
static bool MatchesMask(CTempString str, CTempString mask, ECase use_case=eCase)
Match "str" against the "mask".
static double StringToDouble(const CTempStringEx str, TStringToNumFlags flags=0)
Convert string to double.
PNocase_Generic< string > PNocase
bool AStrEquiv(const Arg1 &x, const Arg2 &y, Pred pr)
Check equivalence of arguments using predicate.
static int Compare(const CTempString s1, SIZE_TYPE pos, SIZE_TYPE n, const char *s2, ECase use_case=eCase)
Compare of a substring with another string.
ECase
Which type of string comparison.
@ fConvErr_NoThrow
Do not throw an exception on error.
@ eNocase
Case insensitive compare.
Fun TreeDepthFirstTraverse(TTreeNode &tree_node, Fun func)
Depth-first tree traversal algorithm.
const TValue & GetValue(void) const
Return node's value.
EBaseType
Set of all possible types for nodes.
constexpr auto sort(_Init &&init)
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
static int match(register const pcre_uchar *eptr, register const pcre_uchar *ecode, const pcre_uchar *mstart, int offset_top, match_data *md, eptrblock *eptrb, unsigned int rdepth)