Ejemplo n.º 1
0
scope_ptr
zookeeper_t::increment(writable_ptr::increment result, const path_t& path, const value_t& value) {
    if (!value.is_double() && !value.is_int() && !value.is_uint()) {
        result->abort(cocaine::error::unicorn_errors::invalid_type);
        return nullptr;
    }
    auto scope = std::make_shared<zk_scope_t>();
    auto& handler = scope->handler_scope.get_handler<increment_action_t>(
        context_t({*log, zk}),
        std::move(result),
        path,
        value
    );
    zk.get(handler.path, handler);
    return scope;
}
Ejemplo n.º 2
0
template<Type::Enum type> value_t raise_cast(value_t obj)
{
    if(obj->type() != type)
        type_error(obj, "an object of type " + Type::names[type]);

    return obj;
}
Ejemplo n.º 3
0
	value_t Numeric::coerce(value_t obj, value_t other)
	{
		if(obj->type() == other->type())
			return Array::allocate_pair(other, obj);

		auto convert = [&](value_t input) -> value_t {
			if(input->type() == Type::Float)
				return input;

			return raise_cast<Float>(call(input, "to_f"));
		};

		OnStack<1> os(obj);
		
		value_t left = convert(other);
		value_t right = convert(obj);
		
		return Array::allocate_pair(left, right);
	}
Ejemplo n.º 4
0
Archivo: hash.cpp Proyecto: Zoxc/mirb
	value_t Hash::rb_delete(Hash *self, value_t key, value_t block)
	{
		OnStack<2> os(self, key);

		value_t value = HashAccess::remove(self, key);

		if(value != value_undef)
			return value;
		else if(block->test())
			return yield(block, key);
		else
			return self->get_default(key);
	}
 inline void set_radio_index( dom::element& el, const value_t& t  )
 {
   selected_cb selected;
   dom::element r = el.parent(); // ATTN: I assume here that all radios in the group belong to the same parent!
   r.find_all(&selected, "[type='radio'][name='%S']", el.get_attribute("name"));
   unsigned int idx = (unsigned int)t.get(0);
   for( unsigned int n = 0; n < selected.elements.size(); ++n )
   {
     dom::element& e = selected.elements[n];
     if ( n == idx)
         e.set_state(STATE_CHECKED, 0);
     else
         e.set_state(0, STATE_CHECKED);
   }
 }
Ejemplo n.º 6
0
Archivo: bignum.cpp Proyecto: Zoxc/mirb
	value_t Bignum::coerce(Bignum *obj, value_t other)
	{
		switch(other->type())
		{
			case Type::Fixnum:
			{
				if(obj->number.can_be_fix())
					return Array::allocate_pair(other, Fixnum::from_int(obj->number.to_intptr()));
				else
					return Array::allocate_pair(Number(Fixnum::to_int(other)).to_bignum(), obj);
			}
			
			case Type::Bignum:
				return Array::allocate_pair(other, obj);

			default:
				coerce_error(other, obj);
		};
	}
/** Set value of the DOM element. Sets value for elements recognized by get_ctl_type() function. 
 * \param[in] el \b const dom::element&, The element.
 * \param[in] v \b const value_t&, The value.
 **/
  inline void set_value(dom::element& el, const value_t& v )
  {
    switch(get_ctl_type(el))
    {
      case CTL_UNKNOWN:         break;
      case CTL_EDIT:
      case CTL_DECIMAL:
      case CTL_CURRENCY:
      case CTL_PASSWORD:
      case CTL_NUMERIC: 
      case CTL_PROGRESS:        
      case CTL_SLIDER:          
      case CTL_SELECT_SINGLE:   
      case CTL_SELECT_MULTIPLE: 
      case CTL_DD_SELECT:       
      case CTL_TEXTAREA:
      case CTL_DATE:
      case CTL_CALENDAR:
      case CTL_HIDDEN:
      default:
        el.set_value(v);
        break;
      // special cases:
      case CTL_BUTTON:          break;
      case CTL_CHECKBOX:        set_checkbox_bits(el,v); break;
      case CTL_RADIO:           set_radio_index(el,v);  break;
      case CTL_HTMLAREA:        
       {
          utf8::ostream os; os << v.get( L"" );
          el.set_html( os.data(), os.length() );
          el.update();
        } break;
      case CTL_NO:
        assert(false);
        break;
    }
  }
Ejemplo n.º 8
0
	value_t FalseClass::rb_xor(value_t value)
	{
		return value->test() ? value_true : value_false;
	}
Ejemplo n.º 9
0
 void resize(size_t size) {
     value.resize(size);
 }
Ejemplo n.º 10
0
 size_t size() const { return value.size(); }
Ejemplo n.º 11
0
 void* data() {
     return reinterpret_cast<void*>(value.data());
 }
Ejemplo n.º 12
0
 const void* data() const {
     return reinterpret_cast<const void*>(value.data());
 }
void CheatEngine::keepAddressesWithValue(const value_t& value, value_size_t size) {
  assert(!m_blocks.empty());

  for (auto blockIt = begin(m_blocks); blockIt != end(m_blocks);) {
    MEMORY_BASIC_INFORMATION info;
    const auto len = VirtualQueryEx(m_process, blockIt->baseAddress, &info, sizeof(info));
    assert(len == sizeof(info));

    if (can_modify_page(info)) {
      chunk_t chunk(blockIt->size);
      DWORD bytesRead;
      ReadProcessMemory(m_process, blockIt->baseAddress, chunk.data(), blockIt->size, &bytesRead);
      chunk.resize(bytesRead);
      blockIt->size = bytesRead;

      // from the offsets that matched before within that page, only keep the ones that still match
      offsets_t stillMatches;
      for (auto offsetIt = blockIt->matches.cbegin(); offsetIt != blockIt->matches.cend(); ++offsetIt) {
        assert(*offsetIt + size <= chunk.size());
        if (std::equal(chunk.cbegin() + *offsetIt, chunk.cbegin() + *offsetIt + size, value.cbegin())) {
          stillMatches.push_back(*offsetIt);
        }
      }
      blockIt->matches = stillMatches;

      // memory page no longer has matching addresses: drop it
      if (blockIt->matches.empty()) {
        blockIt = m_blocks.erase(blockIt);
      }
      else {
        ++blockIt;
      }
    }
    else {
      ++blockIt;
    }
  }
}
Ejemplo n.º 14
0
 UncertainVector<1> UncertainVector<D>::dot(const value_t & rhs) const
 {
     return UncertainVector<1>( _v.dot(rhs),  rhs.dot( _E * rhs ) );
 }