Пример #1
0
static void format_line(void *ptr, int level, const char *fmt, va_list vl,
                        AVBPrint part[3], int *print_prefix, int type[2])
{
    AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
    av_bprint_init(part+0, 0, 1);
    av_bprint_init(part+1, 0, 1);
    av_bprint_init(part+2, 0, 65536);

    if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16;
    if (*print_prefix && avc) {
        if (avc->parent_log_context_offset) {
            AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) +
                                   avc->parent_log_context_offset);
            if (parent && *parent) {
                av_bprintf(part+0, "[%s @ %p] ",
                         (*parent)->item_name(parent), parent);
                if(type) type[0] = get_category(parent);
            }
        }
        av_bprintf(part+1, "[%s @ %p] ",
                 avc->item_name(ptr), ptr);
        if(type) type[1] = get_category(ptr);
    }

    av_vbprintf(part+2, fmt, vl);

    if(*part[0].str || *part[1].str || *part[2].str) {
        char lastc = part[2].len ? part[2].str[part[2].len - 1] : 0;
        *print_prefix = lastc == '\n' || lastc == '\r';
    }
}
Пример #2
0
static void format_line(void *ptr, int level, const char *fmt, va_list vl,
                        char part[3][LINE_SZ], int part_size, int *print_prefix, int type[2])
{
    AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
    part[0][0] = part[1][0] = part[2][0] = 0;
    if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16;
    if (*print_prefix && avc) {
        if (avc->parent_log_context_offset) {
            AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) +
                                   avc->parent_log_context_offset);
            if (parent && *parent) {
                snprintf(part[0], part_size, "[%s @ %p] ",
                         (*parent)->item_name(parent), parent);
                if(type) type[0] = get_category(parent);
            }
        }
        snprintf(part[1], part_size, "[%s @ %p] ",
                 avc->item_name(ptr), ptr);
        if(type) type[1] = get_category(ptr);
    }

    vsnprintf(part[2], part_size, fmt, vl);

    if(*part[0] || *part[1] || *part[2]) {
        char lastc = strlen(part[2]) ? part[2][strlen(part[2]) - 1] : 0;
        *print_prefix = lastc == '\n' || lastc == '\r';
    }
}
Пример #3
0
int main(int argc, char* argv [])
{
    boost::log::add_file_log("cli.log");

    boost::log::core::get()->set_filter(
        xiv::utils::log::severity_level >= xiv::utils::log::Severity::trace
    );

    auto game_data = xiv::dat::GameData("G:/SquareEnix/FINAL FANTASY XIV - A Realm Reborn/game/sqpack/ffxiv/");

    if (false)
    {
        for (auto cat_nb : game_data.get_cat_nbs())
        {
            auto& cat = game_data.get_category(cat_nb);
            for (auto& hash_table_entry : cat.get_index().get_hash_table())
            {
                for (auto& dir_hash_table_entry : hash_table_entry.second)
                {
                    auto file = cat.get_file(hash_table_entry.first, dir_hash_table_entry.first);

                    if (file->get_type() == xiv::dat::FileType::model)
                    {
                        //xiv::mdl::Model aModel(game_data, *file);
                    }
                }
            }
        }
    }
    else if (true)
    {
        search_models(game_data);
    }
    else if (true)
    {
        std::string model_strings [] = { "chara/equipment/e0044/model/c0101e0044_top.mdl" };

        for (auto& model_string : model_strings)
        {
            xiv::mdl::Model aModel(game_data, model_string);
            aModel.export_as_json("G:/projects/output_mv");
        }
    }
    else
    {

        std::string file_strings [] = {
            "chara/monster/m0096/obj/body/b0001/material/v0001/mt_m0096b0001_b.mtrl"
        };

        for (auto& file_string : file_strings)
        {
            auto file = game_data.get_file(file_string);
            file->export_as_bin("G:/test.bin");
        }

    }

    return 0;
}
Пример #4
0
const char *
category_name(void)
{
	switch (get_category()) {
	case T_CHARMAP:
		return ("CHARMAP");
	case T_WIDTH:
		return ("WIDTH");
	case T_COLLATE:
		return ("LC_COLLATE");
	case T_CTYPE:
		return ("LC_CTYPE");
	case T_MESSAGES:
		return ("LC_MESSAGES");
	case T_MONETARY:
		return ("LC_MONETARY");
	case T_NUMERIC:
		return ("LC_NUMERIC");
	case T_TIME:
		return ("LC_TIME");
	default:
		INTERR;
		return (NULL);
	}
}
bool auth_attr_addr::deserialize_body(NetMsg &msg, coding_t coding, uint16 body_length, IEErrorList &err, uint32 &bytes_read, bool skip) {

	uint32 start_pos = msg.get_pos();
	
	// Error: Message is shorter than the length field makes us believe.
	if ( msg.get_bytes_left() < body_length ) {
		catch_bad_alloc( err.put(new IEMsgTooShort(coding, category, start_pos)) );
 		msg.set_pos(start_pos);
		return false;
	}

	if(sub_type==IPV4_ADDRESS){
		struct in_addr tmp_ip;
		msg.decode(tmp_ip);
        ip.set_ip(tmp_ip);
		bytes_read = 4;
	}else{
		struct in6_addr tmp_ip;
		msg.decode(tmp_ip);
		ip.set_ip(tmp_ip);
		bytes_read = 16;
	}
	
	// Error: We expected the length field to be different.
	if ( (body_length + HEADER_LENGTH) !=(uint32) get_serialized_size_nopadding(coding) || body_length!= bytes_read) {

		catch_bad_alloc( err.put( new IEWrongLength(coding, get_category(), get_xtype(), get_subtype(), msg.get_pos())) );
		msg.set_pos(start_pos);
		return false;
	}
	
	return true;
}
//categorize images using nearest centroid and generate confusion table
void LocalDescriptorAndBagOfFeature::test_category(std::vector<Histogram> &feature_vectors, std::vector<double> &confusion_table, std::vector<std::string> &category_labels, std::vector<std::vector<double>> &category_centroids){
    for(Histogram &feature_vector : feature_vectors){
        int cat = get_category(feature_vector, category_centroids);
        //std::cout << "image " << i << " of " << bikes.size() << ": " << cat << "-" << category_labels[cat] << std::endl;
        confusion_table[cat]++;
    }
}
Пример #7
0
static PyObject *
warnings_warn_impl(PyObject *module, PyObject *message, PyObject *category,
                   Py_ssize_t stacklevel, PyObject *source)
/*[clinic end generated code: output=31ed5ab7d8d760b2 input=bfdf5cf99f6c4edd]*/
{
    category = get_category(message, category);
    if (category == NULL)
        return NULL;
    return do_warn(message, category, stacklevel, source);
}
Пример #8
0
static PyObject *
warnings_warn(PyObject *self, PyObject *args, PyObject *kwds)
{
    static char *kw_list[] = { "message", "category", "stacklevel", 0 };
    PyObject *message, *category = NULL;
    Py_ssize_t stack_level = 1;

    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|On:warn", kw_list,
                                     &message, &category, &stack_level))
        return NULL;

    category = get_category(message, category);
    if (category == NULL)
        return NULL;
    return do_warn(message, category, stack_level);
}
Пример #9
0
Файл: bank.c Проект: hnkien/bank
void send_to_downstream(Node *store, int sock_fd, BankConfig config) {
	pthread_mutex_lock(&sending_lock);
	PointerContainer *head = NULL, *temp = NULL;
	head = withdraw(store, config.bank_max_msg_length);
	int i = 0;
	int l = 0;
	int hash = 0;
	while (head != NULL ) {
		temp = head;
		head = head->next;
		l = strlen((char*) (temp->contained));
		log_debug("Send %d char! %s", l, (char*) (temp->contained));
		if (config._downstream_consistent_hashing == 0) {
			for (i = 0; i < config.destiny_host_count; i++) {
				if (config.downstream_sockaddr[i] != NULL
						&& (config._destiny_health_check == 0
								|| config.downstream_error_count[i]
										<= DOWN_STREAM_ERROR_THRESHOLD)) {
					sendto(sock_fd, (char*) (temp->contained), l, 0,
							(struct sockaddr *) (config.downstream_sockaddr[i]),
							config.sockaddr_len);
				}
			}
		} else {
			hash = (int) get_hash(temp->label, strlen(temp->label),
					config.downstream_hash_ring_length);
			i = get_category(hash, config.downstream_hash_ring,
					config.downstream_error_count, DOWN_STREAM_ERROR_THRESHOLD,
					config.destiny_host_count,
					config.downstream_consistent_hash_replica);
			log_debug("Consistent hashing shows we send it to %d.", i);
			if (i < 0) {
				log_warning("No downstream end-point is available.");
				continue;
			}
			if (config.downstream_sockaddr[i] != NULL ) {
				sendto(sock_fd, (char*) (temp->contained), l, 0,
						(struct sockaddr *) (config.downstream_sockaddr[i]),
						config.sockaddr_len);
			}
		}
		free((char*) (temp->contained));
		delete_container(&temp);
	}
	pthread_mutex_unlock(&sending_lock);
}
Пример #10
0
static int intl_ctl(ErlDrvData drv_data, unsigned int command, char *buf,
                    int len, char **rbuf, int rlen)
{
    void* d = (void*)drv_data;
    char* aptr = buf;
    int   alen = len;
    char* str1;
    char* str2;
    char* str3;
    int   int1;
    int   int2;
    unsigned int uint1;

    switch(command) {
    case INTL_GETTEXT:
	/* arguments: string msgid */
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(gettext(str1), rbuf, rlen);

    case INTL_NGETTEXT:
	/* arguments: string msgid, string msgid_plural, int n */
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str2) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_uinteger(&aptr, &alen, &uint1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(ngettext(str1,str2,uint1), rbuf, rlen);

    case INTL_DGETTEXT:
	/* arguments: string domain, string msgid */
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str2) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(dgettext(str1,str2), rbuf, rlen);

    case INTL_DNGETTEXT:
	/* arguments: string domain, string msgid, 
	   string msgid_plural, integer n */
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str2) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str3) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_uinteger(&aptr, &alen, &uint1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(dngettext(str1,str2,str3,uint1), rbuf, rlen);
	
    case INTL_DCGETTEXT:
	/* arguments: string domain, string msgid, int category */
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str2) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_integer(&aptr,&alen, &int1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if ((int1 = get_category(int1)) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(dcgettext(str1,str2,int1),rbuf,rlen);

    case INTL_DCNGETTEXT:
	/* arguments: string domain, string msgid, 
	   strinf msgid_plural, unsigned n, int category */
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str2) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str3) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_uinteger(&aptr,&alen, &uint1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_integer(&aptr,&alen, &int1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if ((int1 = get_category(int1)) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(dcngettext(str1,str2,str3,uint1,int1),rbuf,rlen);

    case INTL_TEXTDOMAIN:
	/* arguments: string domainname */
	if (len == 0)
	    return ret_string(textdomain(NULL), rbuf, rlen);
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(textdomain(str1), rbuf, rlen);

    case INTL_BINDTEXTDOMAIN:
	/* arguments: string domainname, string dirname */
	if (len == 0)
	    return ret_string(textdomain(NULL), rbuf, rlen);
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str2) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(bindtextdomain(str1,str2), rbuf, rlen);

    case INTL_BIND_TEXTDOMAIN_CODESET:
	/* arguments: string domainname, string dirname */
	if (len == 0)
	    return ret_string(textdomain(NULL), rbuf, rlen);
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str2) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(bind_textdomain_codeset(str1,str2), rbuf, rlen);

    case INTL_SETLOCALE:
	if (get_integer(&aptr,&alen, &int1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if ((int1 = get_category(int1)) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	if (get_string(&aptr, &alen, &str1) < 0)
	    return ret_code(EINVAL, rbuf, rlen);
	return ret_string(setlocale(int1,str1), rbuf, rlen);
    }
    return -1;
}
Пример #11
0
long
pdf_defineresource (const char *category,
		    const char *resname, pdf_obj *object, int flags)
{
  int      res_id;
  struct res_cache *rc;
  int      cat_id;
  pdf_res *res = NULL;

  ASSERT(category && object);

  cat_id = get_category(category);
  if (cat_id < 0) {
    ERROR("Unknown resource category: %s", category);
    return -1;
  }

  rc = &resources[cat_id];
  if (resname) {
    for (res_id = 0; res_id < rc->count; res_id++) {
      res = &rc->resources[res_id];
      if (!strcmp(resname, res->ident)) {
	WARN("Resource %s (category: %s) already defined...",
	     resname, category);
	pdf_flush_resource(res);
	res->flags    = flags;
	if (flags & PDF_RES_FLUSH_IMMEDIATE) {
	  res->reference = pdf_ref_obj(object);
	  pdf_release_obj(object);
	} else {
	  res->object = object;
	}
	return (long) ((cat_id << 16)|(res_id));
      }
    }
  } else {
    res_id = rc->count;
  }

  if (res_id == rc->count) {
    if (rc->count >= rc->capacity) {
      rc->capacity += CACHE_ALLOC_SIZE;
      rc->resources = RENEW(rc->resources, rc->capacity, pdf_res);
    }
    res = &rc->resources[res_id];

    pdf_init_resource(res);
    if (resname && resname[0] != '\0') {
      res->ident = NEW(strlen(resname) + 1, char);
      strcpy(res->ident, resname);
    }
    res->category = cat_id;
    res->flags    = flags;
    if (flags & PDF_RES_FLUSH_IMMEDIATE) {
      res->reference = pdf_ref_obj(object);
      pdf_release_obj(object);
    } else {
      res->object = object;
    }
    rc->count++;
  }
Пример #12
0
/// create an error code with the given value and the asio transport category
inline lib::error_code make_error_code(error::value e) {
    return lib::error_code(static_cast<int>(e), get_category());
}
Пример #13
0
void SingleAvroFile::initialize_categories() {
  for (std::map<std::string, std::vector<RMF_avro_backend::Data > >::const_iterator
       it = all_.category.begin(); it != all_.category.end(); ++it) {
    get_category(it->first);
  }
}
Пример #14
0
// make json formated description
void Property::make_description() {
  if (nullptr == property_) {
    g_warning("%s: cannot make description from a nullptr property",
              __PRETTY_FUNCTION__);
    return;
  }
  GValue value = G_VALUE_INIT;
  g_value_init(&value, property_->value_type);

  g_object_get_property(object_, property_->name, &value);
  json_description_->reset();
  json_description_->begin_object();
  // long name
  json_description_->add_string_member("name", long_name_.c_str());
  // name
  json_description_->add_string_member("id", name_.c_str());
  // nickname
  // json_description_->add_string_member ("nickname", g_param_spec_get_nick (property_));

  // short description
  json_description_->add_string_member("description",
                                       g_param_spec_get_blurb(property_));
  json_description_->add_string_member("parent",
                                       get_category().c_str());
  json_description_->add_int_member("order",
                                    get_position_weight());
  // name
  // json_description_->add_string_member ("internal name", g_param_spec_get_name (property_));
  if (property_->flags &G_PARAM_WRITABLE)
    json_description_->add_string_member("writable", "true");
  else
    json_description_->add_string_member("writable", "false");
  switch (G_VALUE_TYPE(&value)) {
    case G_TYPE_STRING:
      {
        const char *string_val = g_value_get_string(&value);
        json_description_->add_string_member("type", "string");
        if (string_val == nullptr)
          json_description_->add_string_member("default value", "");
        else
          json_description_->add_string_member("default value", string_val);
        break;
      }
    case G_TYPE_BOOLEAN:
      {
        gboolean bool_val = g_value_get_boolean(&value);
        json_description_->add_string_member("type", "boolean");
        if (bool_val)
          json_description_->add_string_member("default value", "true");
        else
          json_description_->add_string_member("default value", "false");
        break;
      }
    case G_TYPE_ULONG:
      {
        GParamSpecULong *pulong = G_PARAM_SPEC_ULONG(property_);

        json_description_->add_string_member("type", "ulong");
        gchar *min = g_strdup_printf("%lu", pulong->minimum);
        gchar *max = g_strdup_printf("%lu", pulong->maximum);
        gchar *default_value =
            g_strdup_printf("%lu", g_value_get_ulong(&value));
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_LONG:
      {
        GParamSpecLong *plong = G_PARAM_SPEC_LONG(property_);
        gchar *min = g_strdup_printf("%ld", plong->minimum);
        gchar *max = g_strdup_printf("%ld", plong->maximum);
        gchar *default_value =
            g_strdup_printf("%ld", g_value_get_ulong(&value));
        json_description_->add_string_member("type", "long");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_UINT:
      {
        GParamSpecUInt *puint = G_PARAM_SPEC_UINT(property_);
        gchar *min = g_strdup_printf("%u", puint->minimum);
        gchar *max = g_strdup_printf("%u", puint->maximum);
        gchar *default_value =
            g_strdup_printf("%u", g_value_get_uint(&value));
        json_description_->add_string_member("type", "uint");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_INT:
      {
        GParamSpecInt *pint = G_PARAM_SPEC_INT(property_);
        gchar *min = g_strdup_printf("%d", pint->minimum);
        gchar *max = g_strdup_printf("%d", pint->maximum);
        gchar *default_value = g_strdup_printf("%d", g_value_get_int(&value));
        json_description_->add_string_member("type", "int");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_UINT64:
      {
        GParamSpecUInt64 *puint64 = G_PARAM_SPEC_UINT64(property_);
        gchar *min = g_strdup_printf("%" G_GUINT64_FORMAT, puint64->minimum);
        gchar *max = g_strdup_printf("%" G_GUINT64_FORMAT, puint64->maximum);
        gchar *default_value = g_strdup_printf("%" G_GUINT64_FORMAT,
                                               g_value_get_uint64(&value));
        json_description_->add_string_member("type", "uint64");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_INT64:
      {
        GParamSpecInt64 *pint64 = G_PARAM_SPEC_INT64(property_);
        gchar *min = g_strdup_printf("%" G_GINT64_FORMAT, pint64->minimum);
        gchar *max = g_strdup_printf("%" G_GINT64_FORMAT, pint64->maximum);
        gchar *default_value =
            g_strdup_printf("%" G_GINT64_FORMAT, g_value_get_int64(&value));
        json_description_->add_string_member("type", "int64");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_FLOAT:
      {
        GParamSpecFloat *pfloat = G_PARAM_SPEC_FLOAT(property_);
        gchar *min = g_strdup_printf("%.7g", pfloat->minimum);
        gchar *max = g_strdup_printf("%.7g", pfloat->maximum);
        gchar *default_value =
            g_strdup_printf("%.7g", g_value_get_float(&value));
        json_description_->add_string_member("type", "float");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    case G_TYPE_DOUBLE:
      {
        GParamSpecDouble *pdouble = G_PARAM_SPEC_DOUBLE(property_);
        gchar *min = g_strdup_printf("%.7g", pdouble->minimum);
        gchar *max = g_strdup_printf("%.7g", pdouble->maximum);
        gchar *default_value =
            g_strdup_printf("%.7g", g_value_get_double(&value));
        json_description_->add_string_member("type", "double");
        json_description_->add_string_member("minimum", min);
        json_description_->add_string_member("maximum", max);
        json_description_->add_string_member("default value", default_value);
        g_free(min);
        g_free(max);
        g_free(default_value);
        break;
      }
    default:
      if (property_->value_type == GST_TYPE_CAPS) {
        const GstCaps *caps = gst_value_get_caps(&value);
        json_description_->add_string_member("type", "caps");
        if (!caps)
          json_description_->add_string_member("default value", "");
        else
          json_description_->add_string_member("default value",
                                               gst_caps_to_string(caps));
      } else if (G_IS_PARAM_SPEC_ENUM(property_)) {
        GEnumValue *values;
        guint j = 0;
        gint enum_value;
        const gchar *value_nick = "";
        const gchar *value_name = "";
        json_description_->add_string_member("type", "enum");
        values =
            G_ENUM_CLASS(g_type_class_ref(property_->value_type))->values;
        enum_value = g_value_get_enum(&value);
        while (values[j].value_name) {
          if (values[j].value == enum_value) {
            value_nick = values[j].value_nick;
            value_name = values[j].value_name;
          }
          j++;
        }

        json_description_->set_member_name("default value");
        json_description_->begin_object();
        gchar *value = g_strdup_printf("%d", enum_value);
        json_description_->add_string_member("value", value);
        g_free(value);
        json_description_->add_string_member("nick", value_nick);
        json_description_->add_string_member("name", value_name);
        json_description_->end_object();

        // g_debug ("Enum \"%s\" Default: %d, \"%s\" \"%s\"",
        //  g_type_name (G_VALUE_TYPE (&value)),
        //  enum_value,
        //  value_nick,
        //  value_name);

        j = 0;

        json_description_->set_member_name("values");
        json_description_->begin_array();
        while (values[j].value_name) {
          json_description_->begin_object();
          json_description_->add_string_member("name", values[j].value_name);
          json_description_->add_string_member("nick", values[j].value_nick);
          gchar *values_value = g_strdup_printf("%d", values[j].value);
          json_description_->add_string_member("value", values_value);
          g_free(values_value);
          json_description_->end_object();
          j++;
        }
        json_description_->end_array();

        /* g_type_class_unref (ec); */
      } else if (G_IS_PARAM_SPEC_FLAGS(property_)) {
        g_debug("warning: param spec flags not handled");
        // GParamSpecFlags *pflags = G_PARAM_SPEC_FLAGS (property_);
        // GFlagsValue *vals;
        // gchar *cur;

        // vals = pflags->flags_class->values;

        // cur = flags_to_string (vals, g_value_get_flags (&value));

        // g_debug ("%-23.23s Flags \"%s\" Default: 0x%08x, \"%s\"", "",
        //    g_type_name (G_VALUE_TYPE (&value)),
        //    g_value_get_flags (&value), cur);

        // while (vals[0].value_name) {
        //   g_debug ("");
        //   if (_name)
        //     g_debug ("%s", _name);
        //   g_debug ("%-23.23s    (0x%08x): %-16s - %s", "",
        //      vals[0].value, vals[0].value_nick, vals[0].value_name);
        //   ++vals;
        // }

        // g_free (cur);
      } else if (G_IS_PARAM_SPEC_OBJECT(property_)) {
        g_debug("warning: param spec object not handled");
        // g_debug ("%-23.23s Object of type \"%s\"", "",
        //  g_type_name (property_->value_type));
      } else if (G_IS_PARAM_SPEC_BOXED(property_)) {
        g_debug("warning: param spec boxed not handled");
        // g_debug ("%-23.23s Boxed pointer of type \"%s\"", "",
        //  g_type_name (property_->value_type));
      } else if (G_IS_PARAM_SPEC_POINTER(property_)) {
        g_debug("warning: param spec pointer not handled");
        // if (property_->value_type != G_TYPE_POINTER) {
        //   g_debug ("%-23.23s Pointer of type \"%s\".", "",
        //    g_type_name (property_->value_type));
        // } else if (property_->value_type == G_TYPE_VALUE_ARRAY) {
        // GParamSpecValueArray *pvarray = G_PARAM_SPEC_VALUE_ARRAY (property_);
        // g_debug ("warning: array not handled");
        // if (pvarray->element_spec) {
        //   g_debug ("%-23.23s Array of GValues of type \"%s\"", "",
        //    g_type_name (pvarray->element_spec->value_type));
        // } else {
        //   g_debug ("%-23.23s Array of GValues", "");
        // }
      } else if (GST_IS_PARAM_SPEC_FRACTION(property_)) {
        GstParamSpecFraction *pfraction = GST_PARAM_SPEC_FRACTION(property_);
        json_description_->add_string_member("type", "fraction");
        gchar *minnum = g_strdup_printf("%d", pfraction->min_num);
        gchar *minden = g_strdup_printf("%d", pfraction->min_den);
        gchar *maxnum = g_strdup_printf("%d", pfraction->max_num);
        gchar *maxden = g_strdup_printf("%d", pfraction->max_den);
        gchar *defaultnum = g_strdup_printf("%d",
                                            gst_value_get_fraction_numerator
                                            (&value));
        gchar *defaultden = g_strdup_printf("%d",
                                            gst_value_get_fraction_denominator
                                            (&value));
        json_description_->add_string_member("minimum numerator", minnum);
        json_description_->add_string_member("maximum numerator", minden);
        json_description_->add_string_member("minimum denominator", maxnum);
        json_description_->add_string_member("maximum denominator", maxden);
        json_description_->add_string_member("default numerator", defaultnum);
        json_description_->add_string_member("default denominator",
                                             defaultden);
        g_free(minnum);
        g_free(minden);
        g_free(maxnum);
        g_free(maxden);
        g_free(defaultnum);
        g_free(defaultden);
        // g_debug ("Range: %d/%d - %d/%d Default: %d/%d ",
        //  pfraction->min_num, pfraction->min_den,
        //  pfraction->max_num, pfraction->max_den,
        //  gst_value_get_fraction_numerator (&value),
        //  gst_value_get_fraction_denominator (&value));
      } else {
        g_warning("warning: unknown type");
        // g_debug ("%-23.23s Unknown type %ld \"%s\"", "", property_->value_type,
        //  g_type_name (property_->value_type));
      }
      break;
  }
  g_value_reset(&value);
  json_description_->end_object();
}
Пример #15
0
void Item_factory::load_basic_info(JsonObject& jo, itype* new_item_template)
{
    std::string new_id = jo.get_string("id");
    new_item_template->id = new_id;
    if(m_templates.count(new_id) > 0) {
        // New item already exists. Because mods are loaded after
        // core data, we override it. This allows mods to change
        // item from core data.
        delete m_templates[new_id];
    }
    m_templates[new_id] = new_item_template;
    itypes[new_id] = new_item_template;
    standard_itype_ids.push_back(new_id);

    // And then proceed to assign the correct field
    new_item_template->price = jo.get_int("price");
    new_item_template->name = _(jo.get_string("name").c_str());
    new_item_template->sym = jo.get_string("symbol")[0];
    new_item_template->color = color_from_string(jo.get_string("color"));
    new_item_template->description = _(jo.get_string("description").c_str());
    if(jo.has_member("material")){
      set_material_from_json(jo, "material", new_item_template);
    } else {
      new_item_template->m1 = "null";
      new_item_template->m2 = "null";
    }
    Item_tag new_phase = "solid";
    if(jo.has_member("phase")){
        new_phase = jo.get_string("phase");
    }
    new_item_template->phase = phase_from_tag(new_phase);
    new_item_template->volume = jo.get_int("volume");
    new_item_template->weight = jo.get_int("weight");
    new_item_template->melee_dam = jo.get_int("bashing");
    new_item_template->melee_cut = jo.get_int("cutting");
    new_item_template->m_to_hit = jo.get_int("to_hit");

    new_item_template->light_emission = 0;

    /*
    List of current flags
    FIT - Reduces encumbrance by one
    SKINTIGHT - Reduces layer penalty
    VARSIZE - Can be made to fit via tailoring
    OVERSIZE - Can always be worn no matter encumbrance/mutations/bionics/etc
    POCKETS - Will increase warmth for hands if hands are cold and the player is wielding nothing
    HOOD - Will increase warmth for head if head is cold and player's head isn't encumbered
    RAINPROOF - Works like a raincoat to protect from rain effects
    WATCH - Shows the current time, instead of sun/moon position
    ALARMCLOCK - Has an alarmclock feature
    FANCY - Less than practical clothing meant primarily to convey a certain image.
    SUPER_FANCY - Clothing suitable for the most posh of events.
    LIGHT_* - light emission, sets cached int light_emission
    USE_EAT_VERB - Use the eat verb, even if it's a liquid(soup, jam etc.)
    STURDY - Clothing is made to be armor. Prevents damage to armor unless it is penetrated.
    SWIM_GOGGLES - Allows you to see much further under water.
    REBREATHER - Works with an active UPS to supply you with oxygen while underwater.

    Container-only flags:
    SEALS
    RIGID
    WATERTIGHT
    */
    new_item_template->item_tags = jo.get_tags("flags");
    if ( new_item_template->item_tags.size() > 0 ) {
        for( std::set<std::string>::const_iterator it = new_item_template->item_tags.begin();
        it != new_item_template->item_tags.end(); ++it ) {
            set_intvar(std::string(*it), new_item_template->light_emission, 1, 10000);
        }
    }

    if( jo.has_member("qualities") ){
        set_qualities_from_json(jo, "qualities", new_item_template);
    }

    new_item_template->techniques = jo.get_tags("techniques");

    new_item_template->use = (!jo.has_member("use_action") ? &iuse::none :
                              use_from_string(jo.get_string("use_action")));

    if(jo.has_member("category")) {
        new_item_template->category = get_category(jo.get_string("category"));
    } else {
        new_item_template->category = get_category(calc_category(new_item_template));
    }
}