Exemple #1
0
static void
__match(BTree *tree, offset_t rootOffset, const uint8_t *key, OffsetList *offsetList, int (*keyCompare)(const uint8_t *, const uint8_t *))
{
    uint8_t i;
    BTreeNode *rootNode;

    rootNode = btreeReadNode(tree, rootOffset);
    if(NULL == rootNode)
    {
        sys_log(LOGSTDOUT, "error:__match: read root node from offset %d failed\n", rootOffset);
        return ;
    }

    for (i = 0;
         i < rootNode->keyCount && keyCompare(rootNode->keys[i], key) < 0;
         i++)
        ;

    if (BTREE_IS_LEAF(rootNode))
    {
        for(; i < rootNode->keyCount && keyCompare(rootNode->keys[i], key) == 0; i ++)
        {
            //sys_log(LOGSTDOUT,"__match: [0] got offset %d\n", rootNode->children[i]);
            offsetListAdd(offsetList, rootNode->children[i]);
        }

        btreeDestroyNode(rootNode);

        return ;
    }

    /*now rootNode->keys[i] <= key*/

    for(; i < rootNode->keyCount && keyCompare(rootNode->keys[i], key) >= 0; i ++)
    {
        /*now match the left subtree because key <= rootNode->keys[i]*/
        __match(tree, rootNode->children[i], key, offsetList, keyCompare);
    }

    if(i == rootNode->keyCount && i > 0 && keyCompare(rootNode->keys[i - 1], key) <= 0)
    {
        /*now match the most right subtree because rootNode->keys[ rootNode->keyCount - 1] <= key*/
        __match(tree, rootNode->children[i], key, offsetList, keyCompare);
    }

    btreeDestroyNode(rootNode);

    return;
}
Exemple #2
0
    std::pair<bool, context_type> __match(
        const context_type::variable_container_type& globals,
        reactant_container_type::const_iterator i,
        reactant_container_type::const_iterator j)
    {
        SpeciesExpressionMatcher m(*i);
        if (!m.match(*j, globals))
        {
            return std::make_pair(false, context_type());
        }

        ++i;
        ++j;
        if (i == pttrn_.reactants().end() || j == target_.end())
        {
            return std::make_pair(true, m.context());
        }

        do
        {
            if (__match(m.context().globals, i, j).first)
            {
                return std::make_pair(true, m.context());
            }
        } while (m.next());
        return std::make_pair(false, context_type());
    }
Exemple #3
0
    bool next()
    {
        if (itr_ != matches_.end())
        {
            return false;
        }
        else if (matches_.size() == 0)
        {
            return true;
        }

        do
        {
            --itr_;
            std::pair<bool, context_type> retval((*itr_).next());
            while (retval.first)
            {
                ++itr_;
                const bool succeeded(__match(retval.second));
                if (succeeded)
                {
                    return true;
                }
                --itr_;
                retval = (*itr_).next();
            }
        }
        while (itr_ != matches_.begin());
        return false;
    }
bool _STLP_CALL
__get_short_or_long_monthname(_InIt& __first, _InIt& __last,
                              const _Time_Info& __table, tm* __t) {
  const string* __pr =
    __match(__first, __last, (string*)__table._M_monthname + 0, (string*)__table._M_monthname + 24);
  __t->tm_mon = (int)(__pr - __table._M_monthname) % 12;
  return __pr != __table._M_monthname + 24;
}
bool _STLP_CALL
__get_short_or_long_dayname(_InIt& __first, _InIt& __last,
                            const _Time_Info& __table, tm* __t) {
  const string* __pr =
    __match(__first, __last, __table._M_dayname + 0, __table._M_dayname + 14);
  __t->tm_wday = (int)(__pr - __table._M_dayname) % 7;
  return __pr != __table._M_dayname + 14;
}
Exemple #6
0
    bool match(
        const Species& sp, const context_type::variable_container_type& globals)
    {
        matches_.clear();
        for (Species::container_type::const_iterator i(pttrn_.begin());
            i != pttrn_.end(); ++i)
        {
            matches_.push_back(MatchObject(*i));
        }

        target_ = sp;
        itr_ = matches_.begin();
        context_type ctx;
        ctx.globals = globals;
        return __match(ctx);
    }
Exemple #7
0
void
btreeMatch(BTree *tree, const uint8_t *key, OffsetList *offsetList, int (*keyCompare)(const uint8_t *, const uint8_t *))
{
    if (tree == NULL || key == NULL)
        return;

    /* Read in the tree data. */
    tree->root     = btreeGetRootNode(tree);
    tree->leftLeaf = btreeGetLeftLeaf(tree);

    if (btreeIsEmpty(tree) == 1)
        return;

    __match(tree, tree->root, key, offsetList, keyCompare);
    return ;
}
Exemple #8
0
    bool match(const reactant_container_type& reactants)
    {
        if (pttrn_.reactants().size() != reactants.size())
        {
            return false;
        }

        matchers_.clear();
        for (reactant_container_type::const_iterator
            i(pttrn_.reactants().begin()); i != pttrn_.reactants().end(); ++i)
        {
            matchers_.push_back(SpeciesExpressionMatcher(*i));
        }

        target_ = reactants; //XXX: copy?
        itr_ = matchers_.begin();
        context_type::variable_container_type globals;
        return __match(globals);
    }
Exemple #9
0
    bool __match(const context_type& ctx)
    {
        if (itr_ == matches_.end())
        {
            ctx_ = ctx;
            return true;
        }

        std::pair<bool, context_type> retval((*itr_).match(target_, ctx));
        while (retval.first)
        {
            ++itr_;
            const bool succeeded(__match(retval.second));
            if (succeeded)
            {
                return true;
            }
            --itr_;
            retval = (*itr_).next();
        }
        return false;
    }
Exemple #10
0
string::const_iterator _STLP_CALL
__get_formatted_time _STLP_WEAK (_InIt1 __first,  _InIt1 __last,
                                 string::const_iterator __format, string::const_iterator __format_end,
                                 _Ch*, const _TimeInfo& __table,
                                 const ios_base& __s, ios_base::iostate& __err, tm* __t) {
  const ctype<_Ch>& __ct = use_facet<ctype<_Ch> >(__s.getloc());
  typedef basic_string<_Ch, char_traits<_Ch>, allocator<_Ch> > string_type;
  size_t offset;

  while (__first != __last && __format != __format_end) {
    offset = 0;
    if (*__format == '%') {
      ++__format;
      char __c = *__format;
      if (__c == '#') { //MS extension
        ++__format;
        __c = *__format;
      }

      switch (__c) {
        case 'A':
          offset = 7;
        case 'a': {
          size_t __index = __match(__first, __last,
                                   __table._M_dayname + offset, __table._M_dayname + offset + 7);
          if (__index == 7)
            return __format;
          __t->tm_wday = __STATIC_CAST(int, __index);
          break;
        }

        case 'B':
          offset = 12;
        case 'b': {
          size_t __index = __match(__first, __last,
                                   __table._M_monthname + offset, __table._M_monthname + offset + 12);
          if (__index == 12)
            return __format;
          __t->tm_mon = __STATIC_CAST(int, __index);
          break;
        }

        case 'd': {
          bool __pr = __get_decimal_integer(__first, __last, __t->tm_mday, __STATIC_CAST(_Ch*, 0));
          if (!__pr || __t->tm_mday < 1 || __t->tm_mday > 31) {
            __err |= ios_base::failbit;
            return __format;
          }
          break;
        }

        case 'H': case 'I': {
          bool __pr = __get_decimal_integer(__first, __last, __t->tm_hour, __STATIC_CAST(_Ch*, 0));
          if (!__pr)
            return __format;
          break;
        }

        case 'j': {
          bool __pr = __get_decimal_integer(__first, __last, __t->tm_yday, __STATIC_CAST(_Ch*, 0));
          if (!__pr)
            return __format;
          break;
        }

        case 'm': {
          bool __pr = __get_decimal_integer(__first, __last, __t->tm_mon, __STATIC_CAST(_Ch*, 0));
          --__t->tm_mon;
          if (!__pr || __t->tm_mon < 0 || __t->tm_mon > 11) {
            __err |= ios_base::failbit;
            return __format;
          }
          break;
        }

        case 'M': {
          bool __pr = __get_decimal_integer(__first, __last, __t->tm_min, __STATIC_CAST(_Ch*, 0));
          if (!__pr)
            return __format;
          break;
        }

        case 'p': {
          size_t __index = __match(__first, __last,
                                   __table._M_am_pm + 0, __table._M_am_pm + 2);
          if (__index == 2)
            return __format;
          // 12:00 PM <=> 12:00, 12:00 AM <=> 00:00
          if (__index == 1 && __t->tm_hour != 12 )
            __t->tm_hour += 12;
          if (__index == 0 && __t->tm_hour == 12 )
            __t->tm_hour = 0;
          break;
        }

        case 'S': {
          bool __pr = __get_decimal_integer(__first, __last, __t->tm_sec, __STATIC_CAST(_Ch*, 0));
          if (!__pr)
            return __format;
          break;
        }

        case 'y': {
          bool __pr = __get_decimal_integer(__first, __last, __t->tm_year, __STATIC_CAST(_Ch*, 0));
          if (!__pr)
            return __format;
          break;
        }

        case 'Y': {
          bool __pr = __get_decimal_integer(__first, __last, __t->tm_year, __STATIC_CAST(_Ch*, 0));
          __t->tm_year -= 1900;
          if (!__pr)
            return __format;
          break;
        }

        default:
          break;
      }
    }
    else {
      if (*__first++ != __ct.widen(*__format)) break;
_InIt2 _STLP_CALL
__get_formatted_time _STLP_WEAK (_InIt1 __first,  _InIt1 __last,
                     _InIt2 __format, _InIt2 __format_end,
				 /* _Ch, */ const _Time_Info& __table,
		     ios_base::iostate& __err,
                     tm*         __t) {
  while(__first != __last && __format != __format_end) {
    if (*__format == '%') {
      ++__format;
      char __c = *__format;
      switch (__c) {
        case 'a': {
          const string* __pr =
            __match(__first, __last,
		    (string*)__table._M_dayname + 0 , (string*)__table._M_dayname + 7);
            if (__pr == (string*)__table._M_dayname + 7)
              return __format;
            __t->tm_wday = (int)(__pr - (string*)__table._M_dayname);
            break;
        }

        case 'A': {
          const string* __pr =
            __match(__first, __last,
		    (string*)__table._M_dayname + 7, (string*)__table._M_dayname + 14);
            if (__pr == (string*)__table._M_dayname + 14)
              return __format;
            __t->tm_wday = (int)(__pr - (string*)__table._M_dayname - 7);
            break;
        }

        case 'b': {
          const string* __pr =
            __match(__first, __last,
		    (string*)__table._M_monthname + 0, (string*)__table._M_monthname + 12);
            if (__pr == (string*)__table._M_monthname + 12)
              return __format;
            __t->tm_mon = (int)(__pr - (string*)__table._M_monthname);
            break;
        }

        case 'B': {
          const string* __pr =
            __match(__first, __last,
		    (string*)__table._M_monthname + 12, (string*)__table._M_monthname + 24);
            if (__pr == (string*)__table._M_monthname + 24)
              return __format;
            __t->tm_mon = (int)(__pr - (string*)__table._M_monthname - 12);
            break;
        }

        case 'd': {
          bool __pr =
            __get_decimal_integer(__first, __last, __t->tm_mday);
          if (!__pr || __t->tm_mday < 1 || __t->tm_mday > 31) {
	    __err |= ios_base::failbit;
            return __format;
	  }
          break;
        }
        
        case 'H': case 'I': {
          bool __pr =
            __get_decimal_integer(__first, __last, __t->tm_hour);
            if (!__pr)
              return __format;
            break;
        }

        case 'j': {
          bool __pr =
            __get_decimal_integer(__first, __last, __t->tm_yday);
          if (!__pr)
            return __format;
          break;
        }

        case 'm': {
          bool __pr =
            __get_decimal_integer(__first, __last, __t->tm_mon);
	    --__t->tm_mon;
          if (!__pr || __t->tm_mon < 0 || __t->tm_mon > 11) {
	    __err |= ios_base::failbit;
            return __format;
	  }
          break;
        }

        case 'M': {
          bool __pr =
            __get_decimal_integer(__first, __last, __t->tm_min);
          if (!__pr)
            return __format;
          break;
        }

        case 'p': {
          const string* __pr =
            __match(__first, __last, (string*)__table._M_am_pm + 0, (string*)__table._M_am_pm + 2);
          if (__pr == (string*)__table._M_am_pm + 2)
            return __format;
          if (__pr == (string*)__table._M_am_pm + 1)
            __t->tm_hour += 12;
          break;
        }

        case 'S': {
          bool __pr =
            __get_decimal_integer(__first, __last, __t->tm_sec);
          if (!__pr)
            return __format;
          break;
        }

	case 'y': {
	  bool __pr =
	    __get_decimal_integer(__first, __last, __t->tm_year);
	  if (!__pr)
	    return __format;
	  break;
        }

        case 'Y': {
	  bool __pr =
            __get_decimal_integer(__first, __last, __t->tm_year);
          __t->tm_year -= 1900;
          if (!__pr)
            return __format;
          break;
        }

        default:
          break;
      }

    }
    else {
      if (*__first++ != *__format) break;
    }
    
    ++__format;
  }

  return __format;
}
_RAIt _STLP_CALL
__match(_InIt& __first, _InIt& __last, _RAIt __name, _RAIt __name_end) {
  return __match((_InIt&)__first, (_InIt&)__last, __name, __name_end, _STLP_DISTANCE_TYPE(__name, _InIt));
}
matcher_status single_char_test_matcher::match(const std::vector<char>::iterator& begin, const std::vector<char>::iterator& end)
{
    assert(begin != end);
    return __match(begin, end);
}