コード例 #1
0
ファイル: draw.c プロジェクト: Xethan/fdf
void	point_and_line(t_env e, size_t x, size_t y)
{
	ft_pixel_put(e, e.map[y][x].z, e.map[y][x].x, e.map[y][x].y);
	if (x != e.x - 1)
		if (is_map(e, x, y) || is_map(e, x + 1, y))
			draw_segment(e, e.map[y][x], e.map[y][x + 1]);
	if (y != e.y - 1)
		if (is_map(e, x, y) || is_map(e, x, y + 1))
			draw_segment(e, e.map[y][x], e.map[y + 1][x]);
}
コード例 #2
0
ファイル: hist.c プロジェクト: AndyA/timewarp
void test_main(void) {
  is(countof(hist_in), countof(fwd_map), "countof(hist_in) == countof(fwd_map)");
  is(countof(hist_in), countof(rev_map), "countof(hist_in) == countof(rev_map)");

  double map[countof(hist_in)];

  hist_map(hist_in, countof(hist_in), map);
  is_map(map, fwd_map, countof(fwd_map),  "fwd_map");

  double imap[countof(hist_in)];

  hist_inverse(map, imap, countof(hist_in));
  is_map(imap, rev_map, countof(rev_map),  "rev_map");
}
コード例 #3
0
ファイル: pymp.cpp プロジェクト: sharpeye/pymp
    PyObject * next()
    {
        auto obj = read_next();

        if( is_array( obj ) )
        {
            if( obj.as.array_size )
            {
                push_list( obj.as.array_size );

                return nullptr;
            }

            return PyList_New( 0 );
        }
        
        if( is_map( obj ) )
        {
            if( obj.as.map_size )
            {
                push_dict( obj.as.map_size );

                return nullptr;
            }

            return PyDict_New();
        }
            
        return read_simple( obj );
    }
コード例 #4
0
ファイル: erl_bif_persistent.c プロジェクト: bmk/otp
static BIF_RETTYPE
persistent_term_info_trap(BIF_ALIST_1)
{
    TrapData* trap_data = (TrapData *) BIF_ARG_1;
    Eterm res;
    Uint bump_reds;
    Binary* mbp;

    mbp = erts_magic_ref2bin(BIF_ARG_1);
    trap_data = ERTS_MAGIC_BIN_DATA(mbp);
    bump_reds = trap_data->remaining;
    res = do_info(BIF_P, trap_data);
    if (trap_data->remaining > 0) {
        ASSERT(res == am_ok);
        BUMP_ALL_REDS(BIF_P);
        BIF_TRAP1(&persistent_term_info_export, BIF_P, BIF_ARG_1);
    } else {
        /*
         * Decrement ref count (and possibly delete the hash table
         * and associated literal area).
         */
        dec_table_refc(BIF_P, trap_data->table);
        trap_data->table = NULL; /* Prevent refc decrement */
        BUMP_REDS(BIF_P, bump_reds);
        ASSERT(is_map(res));
        BIF_RET(res);
    }
}
コード例 #5
0
ファイル: TimerAPI.cpp プロジェクト: xor-mind/solarus
/**
 * @brief Registers a timer into a context (table or a userdata).
 * @param timer A timer.
 * @param context_index Index of the table or userdata in the stack.
 * @param callback_index Index of the function to call when the timer finishes.
 */
void LuaContext::add_timer(Timer* timer, int context_index, int callback_index) {

  const void* context;
  if (lua_type(l, context_index) == LUA_TUSERDATA) {
    ExportableToLua** userdata = static_cast<ExportableToLua**>(
        lua_touserdata(l, context_index));
    context = *userdata;
  }
  else {
    context = lua_topointer(l, context_index);
  }

  lua_pushvalue(l, callback_index);
  int callback_ref = create_ref();

  timers[timer].callback_ref = callback_ref;
  timers[timer].context = context;

  Game* game = main_loop.get_game();
  if (game != NULL) {
    // We are during a game: depending on the timer's context,
    // when the map is suspended, also suspend the timer or not.
    if (is_map(l, context_index)
        || is_entity(l, context_index)
        || is_item(l, context_index)) {
      timer->set_suspended_with_map(true);
    }
  }
  timer->increment_refcount();
}
コード例 #6
0
ファイル: erl_bif_op.c プロジェクト: HansN/otp
BIF_RETTYPE is_map_1(BIF_ALIST_1)
{
    if (is_map(BIF_ARG_1)) {
	BIF_RET(am_true);
    }
    BIF_RET(am_false);
}
コード例 #7
0
ファイル: vec.c プロジェクト: seanpringle/lt
char*
vec_char (vec_t *vec)
{
  ensure_vec(vec, __func__);

  int count = vec->count;

  push(strf("["));

  for (int i = 0; i < count; i++)
  {
    if (is_vec(vec_get(vec, i)[0]))
      push(strf("vec[]"));
    else
    if (is_map(vec_get(vec, i)[0]))
      push(strf("map[]"));
    else
      push(to_char(vec_get(vec, i)[0]));

    op_concat();
    if (i < count-1)
    {
      push(strf(", "));
      op_concat();
    }
  }

  push(strf("]"));
  op_concat();

  return pop();
}
コード例 #8
0
ファイル: openvswitch.c プロジェクト: knobunc/plotnetcfg
static struct ovs_if *parse_iface(json_t *jresult, json_t *uuid)
{
	struct ovs_if *iface;
	json_t *jif, *jarr;
	unsigned int i;

	if (!is_uuid(uuid))
		return NULL;
	jif = json_object_get(jresult, "Interface");
	jif = json_object_get(jif, json_string_value(json_array_get(uuid, 1)));
	jif = json_object_get(jif, "new");

	iface = calloc(sizeof(*iface), 1);
	if (!iface)
		return NULL;
	iface->name = strdup(json_string_value(json_object_get(jif, "name")));
	iface->type = strdup(json_string_value(json_object_get(jif, "type")));
	jarr = json_object_get(jif, "options");
	if (!strcmp(iface->type, "vxlan") && is_map(jarr)) {
		jarr = json_array_get(jarr, 1);
		for (i = 0; i < json_array_size(jarr); i++) {
			json_t *jkv;
			const char *key, *val;

			jkv = json_array_get(jarr, i);
			key = json_string_value(json_array_get(jkv, 0));
			val = json_string_value(json_array_get(jkv, 1));
			if (!strcmp(key, "local_ip"))
				iface->local_ip = strdup(val);
			else if (!strcmp(key, "remote_ip"))
				iface->remote_ip = strdup(val);
		}
	} else if (!strcmp(iface->type, "patch") && is_map(jarr)) {
		jarr = json_array_get(jarr, 1);
		for (i = 0; i < json_array_size(jarr); i++) {
			json_t *jkv;
			const char *key, *val;

			jkv = json_array_get(jarr, i);
			key = json_string_value(json_array_get(jkv, 0));
			val = json_string_value(json_array_get(jkv, 1));
			if (!strcmp(key, "peer"))
				iface->peer = strdup(val);
		}
	}
	return iface;
}
コード例 #9
0
ファイル: TimerAPI.cpp プロジェクト: lambdaloop/solarus
/**
 * @brief Registers a timer into a context (table or a userdata).
 * @param timer A timer.
 * @param context_index Index of the table or userdata in the stack.
 * @param callback_index Index of the function to call when the timer finishes.
 */
void LuaContext::add_timer(Timer* timer, int context_index, int callback_index) {

  const void* context;
  if (lua_type(l, context_index) == LUA_TUSERDATA) {
    ExportableToLua** userdata = static_cast<ExportableToLua**>(
        lua_touserdata(l, context_index));
    context = *userdata;
  }
  else {
    context = lua_topointer(l, context_index);
  }

  lua_pushvalue(l, callback_index);
  int callback_ref = create_ref();

#ifndef NDEBUG
  // Sanity check: check the uniqueness of the ref.
  std::map<Timer*, LuaTimerData>::iterator it;
  for (it = timers.begin(); it != timers.end(); ++it) {
    if (it->second.callback_ref == callback_ref) {
      Debug::die(StringConcat() << "Callback ref " << callback_ref
            << " is already used by a timer (duplicate luaL_unref?)");
    }
  }
#endif

  Debug::check_assertion(timers.find(timer) == timers.end(),
      "Duplicate timer in the system");

  timers[timer].callback_ref = callback_ref;
  timers[timer].context = context;

  Game* game = main_loop.get_game();
  if (game != NULL) {
    // We are during a game: depending on the timer's context,
    // suspend the timer or not.
    if (is_map(l, context_index)
        || is_entity(l, context_index)
        || is_item(l, context_index)) {

      // By default, we want the timer to be automatically suspended when a
      // camera movement, a dialog or the pause menu starts.
      timer->set_suspended_with_map(true);

      // But in the initial state, we override that rule.
      // We initially suspend the timer only during a dialog.
      // In particular, we don't want to suspend timers created during a
      // camera movement.
      // This would be very painful for users.
      bool initially_suspended = game->is_dialog_enabled();
      timer->set_suspended(initially_suspended);
    }
  }
  timer->increment_refcount();
}
コード例 #10
0
 void theory_array_full::add_parent_map(theory_var v, enode* s) {
     if (m_params.m_array_cg && !s->is_cgr()) {
         return;
     }
     SASSERT(v != null_theory_var);
     SASSERT(is_map(s));
     v                = find(v);
     var_data * d     = m_var_data[v];
     var_data_full * d_full     = m_var_data_full[v];
     d_full->m_parent_maps.push_back(s);
     m_trail_stack.push(push_back_trail<theory_array, enode *, false>(d_full->m_parent_maps));
     if (!m_params.m_array_weak && !m_params.m_array_delay_exp_axiom && d->m_prop_upward) {
         ptr_vector<enode>::iterator it  = d->m_parent_selects.begin();
         ptr_vector<enode>::iterator end = d->m_parent_selects.end();
         for (; it != end; ++it) {
             if (!m_params.m_array_cg || (*it)->is_cgr()) {
                 instantiate_select_map_axiom(*it, s);
             }                
         }
     }
 }
コード例 #11
0
ファイル: Type.cpp プロジェクト: leek-wars/leekscript
bool Type::compatible(const Type& type) const {
	if (_types.size() == 0 or type._types.size() == 0) {
		return true;
	}
	if (is_any()) {
		return true;
	}
	if (this->is_primitive() && type.is_polymorphic()) {
		return false;
	}
	if (this->temporary and not type.temporary) {
		return false; // type not compatible with type&&
	}
	if (not this->constant and type.constant) {
		return false; // 'const type' not compatible with 'type'
	}
	if ((is_array() && type.is_array()) || (is_set() && type.is_set()) || (is_map() && type.is_map()) || (is_function() && type.is_function())) {
		return _types[0]->compatible(type._types[0].get());
	}
	if (_types[0] != type._types[0]) {
		// 'Integer' is compatible with 'Float'
		if (this->is_real() and type.is_integer()) {
			return true;
		}
		// 'Boolean' is compatible with 'Integer'
		if (this->is_integer() and type.is_bool()) {
			return true;
		}
		// 'Integer' is compatible with 'Long'
		if (this->is_long() and type.is_integer()) {
			return true;
		}
		// All numbers types are compatible with the base 'Number' type
		if (dynamic_cast<const Number_type*>(_types[0].get()) and (type.is_integer() or type.is_long() or type.is_real())) {
			return true;
		}
		return false;
	}
	return true;
}
コード例 #12
0
 void theory_array_full::add_map(theory_var v, enode* s) {
     if (m_params.m_array_cg && !s->is_cgr()) {
         return;
     }
     SASSERT(is_map(s));
     v                = find(v);
     var_data_full * d_full = m_var_data_full[v];
     var_data *     d     = m_var_data[v];
     //
     // TODO: defaulting to exhaustive up-propagation.
     //       instead apply stratified filter.
     set_prop_upward(v,d);
     d_full->m_maps.push_back(s);
     m_trail_stack.push(push_back_trail<theory_array, enode *, false>(d_full->m_maps));
     ptr_vector<enode>::iterator it  = d->m_parent_selects.begin();
     ptr_vector<enode>::iterator end = d->m_parent_selects.end();
     for (; it != end; ++it) {
         SASSERT(is_select(*it));
         instantiate_select_map_axiom(*it, s);
     }
     set_prop_upward(s);
 }
コード例 #13
0
ファイル: TimerApi.cpp プロジェクト: benoitschneider/solarus
/**
 * \brief Registers a timer into a context (table or a userdata).
 * \param timer A timer.
 * \param context_index Index of the table or userdata in the stack.
 * \param callback_ref Lua ref to the function to call when the timer finishes.
 */
void LuaContext::add_timer(
    const TimerPtr& timer,
    int context_index,
    const ScopedLuaRef& callback_ref
) {
  const void* context;
  if (lua_type(l, context_index) == LUA_TUSERDATA) {
    ExportableToLuaPtr* userdata = static_cast<ExportableToLuaPtr*>(
        lua_touserdata(l, context_index)
    );
    context = userdata->get();
  }
  else {
    context = lua_topointer(l, context_index);
  }

  callback_ref.push();

#ifndef NDEBUG
  // Sanity check: check the uniqueness of the ref.
  for (const auto& kvp: timers) {
    if (kvp.second.callback_ref.get() == callback_ref.get()) {
      std::ostringstream oss;
      oss << "Callback ref " << callback_ref.get()
          << " is already used by a timer (duplicate luaL_unref?)";
      Debug::die(oss.str());
    }
  }
#endif

  Debug::check_assertion(timers.find(timer) == timers.end(),
      "Duplicate timer in the system");

  timers[timer].callback_ref = callback_ref;
  timers[timer].context = context;

  Game* game = main_loop.get_game();
  if (game != nullptr) {
    // We are during a game: depending on the timer's context,
    // suspend the timer or not.
    if (is_map(l, context_index)
        || is_entity(l, context_index)
        || is_item(l, context_index)) {

      bool initially_suspended = false;

      // By default, we want the timer to be automatically suspended when a
      // camera movement, a dialog or the pause menu starts.
      if (!is_entity(l, context_index)) {
        // The timer normally gets suspended/resumed with the map.
        timer->set_suspended_with_map(true);

        // But in the initial state, we override that rule.
        // We initially suspend the timer only during a dialog.
        // In particular, we don't want to suspend timers created during a
        // camera movement.
        // This would be very painful for users.
        initially_suspended = game->is_dialog_enabled();
      }
      else {
        // Entities are more complex: they also get suspended when disabled
        // and when far from the camera. Therefore, they don't simply follow
        // the map suspended state.
        EntityPtr entity = check_entity(l, context_index);
        initially_suspended = entity->is_suspended() || !entity->is_enabled();
      }

      timer->set_suspended(initially_suspended);
    }
  }
}
コード例 #14
0
ファイル: TimerApi.cpp プロジェクト: kenygia/solarus
/**
 * \brief Registers a timer into a context (table or a userdata).
 * \param timer A timer.
 * \param context_index Index of the table or userdata in the stack.
 * \param callback_index Index of the function to call when the timer finishes.
 */
void LuaContext::add_timer(Timer* timer, int context_index, int callback_index) {

  const void* context;
  if (lua_type(l, context_index) == LUA_TUSERDATA) {
    ExportableToLua** userdata = static_cast<ExportableToLua**>(
        lua_touserdata(l, context_index));
    context = *userdata;
  }
  else {
    context = lua_topointer(l, context_index);
  }

  lua_pushvalue(l, callback_index);
  int callback_ref = create_ref();

#ifndef NDEBUG
  // Sanity check: check the uniqueness of the ref.
  std::map<Timer*, LuaTimerData>::iterator it;
  for (it = timers.begin(); it != timers.end(); ++it) {
    if (it->second.callback_ref == callback_ref) {
      std::ostringstream oss;
      oss << "Callback ref " << callback_ref
          << " is already used by a timer (duplicate luaL_unref?)";
      Debug::die(oss.str());
    }
  }
#endif

  Debug::check_assertion(timers.find(timer) == timers.end(),
      "Duplicate timer in the system");

  timers[timer].callback_ref = callback_ref;
  timers[timer].context = context;

  Game* game = main_loop.get_game();
  if (game != NULL) {
    // We are during a game: depending on the timer's context,
    // suspend the timer or not.
    if (is_map(l, context_index)
        || is_entity(l, context_index)
        || is_item(l, context_index)) {

      bool initially_suspended = false;

      // By default, we want the timer to be automatically suspended when a
      // camera movement, a dialog or the pause menu starts.
      if (!is_entity(l, context_index)) {
        // The timer normally get suspended/unsuspend with the map.
        timer->set_suspended_with_map(true);

        // But in the initial state, we override that rule.
        // We initially suspend the timer only during a dialog.
        // In particular, we don't want to suspend timers created during a
        // camera movement.
        // This would be very painful for users.
        initially_suspended = game->is_dialog_enabled();
      }
      else {
        // Entities are more complex: they also get suspended when disabled
        // and when far from the camera. Therefore, they don't simply follow
        // the map suspended state.
        const MapEntity& entity = check_entity(l, context_index);
        initially_suspended = entity.is_suspended() || !entity.is_enabled();
      }

      timer->set_suspended(initially_suspended);
    }
  }
  RefCountable::ref(timer);
}
コード例 #15
0
ファイル: var.hpp プロジェクト: MauroFab/dynamic-cpp
 /// is var a collection type?
 bool is_collection() const { return is_vector() || is_map(); }