Esempio n. 1
0
File: vec.c Progetto: 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();
}
Esempio n. 2
0
  //// R-value reference overloads
  //// Message incoming
  void operator()(message& existing, message&& incoming)
  {
    //    std::cerr << ossia::to_pretty_string(existing.destination) << " : "
    //              << ossia::value_to_pretty_string(existing) << " <= "
    //              << ossia::to_pretty_string(incoming.destination) << " : "
    //              << ossia::value_to_pretty_string(incoming) << std::endl;

    auto to_append_index_empty = incoming.dest.index.empty();
    auto source_index_empty = existing.dest.index.empty();
    if (incoming.message_value.valid()
        && (same_vec_type(existing.message_value, incoming.message_value)
            || is_vec(existing.dest.address().get_value_type())))
    {
      // We handle the Vec types a bit differently :
      // since it's very cheap, the value will contain the whole array data
      // and the index will be the relevant index in the array.
      // Hence we merge both indexes.
      auto res = ossia::apply(
          vec_merger{existing.dest, incoming.dest}, existing.message_value.v,
          incoming.message_value.v);

      if (res)
      {
        state.remove(existing_it);
        state.add(std::move(res));
      }
    }
    else if (to_append_index_empty && source_index_empty)
    {
      // Add the new message to the state
      if (MergeSingleValues)
      {
        value_merger<true>::merge_value(
            existing.message_value, std::move(incoming.message_value));
      }
      else
      {
        state.add(std::move(incoming));
      }
    }
    else
    {
      piecewise_message pw{incoming.dest.value, {}, incoming.dest.unit};
      if (!to_append_index_empty && !source_index_empty)
      {
        // Most complex case : we create a list big enough to host both values
        value_merger<true>::insert_in_list(
            pw.message_value, existing.message_value, existing.dest.index);
        value_merger<true>::insert_in_list(
            pw.message_value, std::move(incoming.message_value),
            incoming.dest.index);
      }
      // For these cases, we mix in the one that has the index;
      // the one without index information becomes index [0] :
      else if (!to_append_index_empty)
      {
        pw.message_value.push_back(existing.message_value);
        value_merger<true>::insert_in_list(
            pw.message_value, std::move(incoming.message_value),
            incoming.dest.index);
      }
      else if (!source_index_empty)
      {
        value_merger<true>::insert_in_list(
            pw.message_value, existing.message_value, existing.dest.index);
        value_merger<true>::set_first_value(
            pw.message_value, std::move(incoming.message_value));
      }

      state.remove(existing_it);
      state.add(std::move(pw));
    }
  }
Esempio n. 3
0
bool HHVM_FUNCTION(HH_is_vec, const Variant& v) {
  return is_vec(v);
}
Esempio n. 4
0
File: vec.c Progetto: seanpringle/lt
static void
ensure_vec (vec_t *vec, const char *func)
{
  ensure(is_vec(vec)) errorf("%s not a vec_t", func);
}