00001 #include <spl/xml/xpath/private/XPathOpPredicate.h> 00002 #include <spl/xml/xpath/XPath.h> 00003 00004 XPathOpPredicate::XPathOpPredicate() 00005 : m_ops(), m_binop(OP_ERROR), m_arg(new Variant()) 00006 { 00007 } 00008 00009 XPathOpPredicate::XPathOpPredicate(const XPathOpPredicate& op) 00010 : m_ops(op.m_ops), m_binop(OP_ERROR), m_arg(new Variant()) 00011 { 00012 } 00013 00014 XPathOpPredicate::~XPathOpPredicate() 00015 { 00016 } 00017 00018 XPathOpPredicate& XPathOpPredicate::operator =(const XPathOpPredicate& oproot) 00019 { 00020 m_ops = oproot.m_ops; 00021 m_binop = oproot.m_binop; 00022 m_arg = oproot.m_arg; 00023 return *this; 00024 } 00025 00026 bool XPathOpPredicate::IsMatch(XmlNode& context) 00027 { 00028 return true; 00029 } 00030 00031 XmlNodeListPtr XPathOpPredicate::NextContext(XmlNodePtr context) 00032 { 00033 RefCountPtr<Array<XPathOperatorPtr> > ops(m_ops.ToArray()); 00034 XmlNodeListPtr innerCtx = XPath::SelectNodes(ops, context); 00035 00036 XmlNodeListPtr matchNodes = XmlNodeListPtr(new XmlNodeList()); 00037 00038 for ( int x = 0; x < innerCtx->Count(); x++ ) 00039 { 00040 XmlNodePtr node = innerCtx->Item(x); 00041 00042 switch( m_binop ) 00043 { 00044 case OP_EQ: 00045 if (Variant(*node->Value()) == *m_arg) 00046 { 00047 matchNodes->Add(context); 00048 return matchNodes; 00049 } 00050 break; 00051 case OP_NEQ: 00052 if (Variant(*node->Value()) != *m_arg) 00053 { 00054 matchNodes->Add(context); 00055 return matchNodes; 00056 } 00057 break; 00058 case OP_LT: 00059 if (Variant(*node->Value()) < *m_arg) 00060 { 00061 matchNodes->Add(context); 00062 return matchNodes; 00063 } 00064 break; 00065 case OP_LTEQ: 00066 if (Variant(*node->Value()) <= *m_arg) 00067 { 00068 matchNodes->Add(context); 00069 return matchNodes; 00070 } 00071 break; 00072 case OP_GT: 00073 if (Variant(*node->Value()) > *m_arg) 00074 { 00075 matchNodes->Add(context); 00076 return matchNodes; 00077 } 00078 break; 00079 case OP_GTEQ: 00080 if (Variant(*node->Value()) >= *m_arg) 00081 { 00082 matchNodes->Add(context); 00083 return matchNodes; 00084 } 00085 break; 00086 default: 00087 throw new SyntaxException("Internal predicate operator error"); 00088 } 00089 } 00090 00091 return matchNodes; 00092 } 00093 00094 #if defined(DEBUG) || defined(_DEBUG) 00095 void XPathOpPredicate::CheckMem() const 00096 { 00097 XPathOperator::CheckMem(); 00098 m_ops.CheckMem(); 00099 } 00100 00101 void XPathOpPredicate::ValidateMem() const 00102 { 00103 XPathOperator::ValidateMem(); 00104 m_ops.ValidateMem(); 00105 } 00106 #endif