Exemplo n.º 1
0
IOperand		*Operand<T>::operator-(const IOperand &rhs) const
{
    Operand               first;
    Operand               second;
    eOperandType          new_type;

    first = *this;
    second = rhs;
    new_type = select_type(first.getType(), second.getType());
    if (new_type == Int8)
        return (createOperand(new_type, convint8_t(first.toString()) -
                              convint8_t(second.toString())));
    if (new_type == Int16)
        return (createOperand(new_type, convint16_t(first.toString()) -
                              convint16_t(second.toString())));
    if (new_type == Int32)
        return (createOperand(new_type, convint32_t(first.toString()) -
                              convint32_t(second.toString())));
    if (new_type == Float)
        return (createOperand(new_type, convinfloat(first.toString()) -
                              convinfloat(second.toString())));
    if (new_type == Double)
        return (createOperand(new_type, convindouble(first.toString()) -
                              convindouble(second.toString())));
    return (NULL);
}
Exemplo n.º 2
0
void Write::run1(ValueArr& varr,std::string &str)//数组到json
{
	COUTDEBUG
	std::vector<TypeValue>::iterator b = varr.vec.begin();
	std::vector<TypeValue>::iterator e = varr.vec.end();
	str.append("[");
	for (; b != e; ++b)
	{
		select_type(b->type,b->vpoint,str);
		str.append(",");
	}
	str[str.length()-1]=']';//覆盖最后一个多出来的","
}
Exemplo n.º 3
0
void Write::run1(ValueObj &vobj,std::string &str)//对象到json
{
	COUTDEBUG
	std::map<std::string ,TypeValue>::iterator b=vobj.mypair.begin();
	std::map<std::string ,TypeValue>::iterator e=vobj.mypair.end();
	str.append("{");
	for (; b != e; ++b)
	{
		str+="\""+b->first+"\":";
		select_type(b->second.type,b->second.vpoint,str);
		str.append(",");
	}

	str[str.length()-1]='}';//覆盖最后一个多出来的","
}
Exemplo n.º 4
0
static int init_config(struct config *cfg, int argc, char *argv[])
{
	int err = 0;

	memset(cfg, 0, sizeof(struct config));

	cfg->wf.wf_kind = WAVEFORM_SINE;
	cfg->wf.wf_frequency = 500.0;
	cfg->wf.wf_amplitude = 1.0;
	cfg->wf.wf_offset = 0.0;
	cfg->wf.spl_frequency = 1000.0;
	cfg->wf.spl_count = 0;

	while ((err = getopt_long(argc,
				  argv, "vt:f:a:o:s:O:h", opts, NULL)) >= 0) {

		switch (err) {

		case 'v':
			cfg->verbose = 1;
			break;
		case 't':
			err = select_type(&cfg->wf, optarg);
			if (err < 0)
				goto out;
			break;
		case 'f':
			errno = 0;
			cfg->wf.wf_frequency = strtod(optarg, NULL);
			if (errno) {
				err = -errno;
				goto bad_conversion;
			}
			break;
		case 'a':
			errno = 0;
			cfg->wf.wf_amplitude = strtod(optarg, NULL);
			if (errno) {
				err = -errno;
				goto bad_conversion;
			}
			break;
		case 'o':
			errno = 0;
			cfg->wf.wf_offset = strtod(optarg, NULL);
			if (errno) {
				err = -errno;
				goto bad_conversion;
			}
			break;
		case 's':
			errno = 0;
			cfg->wf.spl_frequency = strtod(optarg, NULL);
			if (errno) {
				err = -errno;
				goto bad_conversion;
			}
			break;
		case 'O':
			cfg->filename = optarg;
			break;
		case 'h':
		default:
			err = -EINVAL;
			do_print_usage();
			goto out;
		}
	}

	err = 0;

	if (cfg->filename != NULL) {
		cfg->output = fopen(cfg->filename, "w");
		if (cfg->output == NULL) {
			err = -errno;
			fprintf(stderr, "%s: %s\n", cfg->filename, strerror(errno));
			goto out;
		}
	} else {
		cfg->output = stdout;
		cfg->filename = "stdout";
	}

	if (isatty(fileno(cfg->output))) {
		err = -EINVAL;
		fprintf(stderr,
			"Error: output terminals are not allowed (%s)\n",
			cfg->filename);
		goto out;
	}

out:
	if (err < 0)
		cleanup_config(cfg);

	return err;

bad_conversion:
	fprintf(stderr, "Error:  bad option(s) value(s)\n");
	do_print_usage();
	return err;
}
Exemplo n.º 5
0
void CreateDialog::popup_create(bool p_dont_clear, bool p_replace_mode, const String &p_select_type) {

	type_list.clear();
	ClassDB::get_class_list(&type_list);
	ScriptServer::get_global_class_list(&type_list);
	type_list.sort_custom<StringName::AlphCompare>();

	recent->clear();

	FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("create_recent." + base_type), FileAccess::READ);

	if (f) {

		TreeItem *root = recent->create_item();

		while (!f->eof_reached()) {
			String l = f->get_line().strip_edges();
			String name = l.split(" ")[0];

			if (ClassDB::class_exists(name) || ScriptServer::is_global_class(name)) {
				TreeItem *ti = recent->create_item(root);
				ti->set_text(0, l);
				ti->set_icon(0, EditorNode::get_singleton()->get_class_icon(l, base_type));
			}
		}

		memdelete(f);
	}

	favorites->clear();

	f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("favorites." + base_type), FileAccess::READ);

	favorite_list.clear();

	if (f) {

		while (!f->eof_reached()) {
			String l = f->get_line().strip_edges();

			if (l != String()) {
				favorite_list.push_back(l);
			}
		}

		memdelete(f);
	}

	_save_and_update_favorite_list();

	// Restore valid window bounds or pop up at default size.
	Rect2 saved_size = EditorSettings::get_singleton()->get_project_metadata("dialog_bounds", "create_new_node", Rect2());
	if (saved_size != Rect2()) {
		popup(saved_size);
	} else {
		popup_centered_clamped(Size2(900, 700) * EDSCALE, 0.8);
	}

	if (p_dont_clear) {
		search_box->select_all();
	} else {
		search_box->clear();
	}

	search_box->grab_focus();

	_update_search();

	is_replace_mode = p_replace_mode;

	if (p_replace_mode) {
		select_type(p_select_type);
		set_title(vformat(TTR("Change %s Type"), base_type));
		get_ok()->set_text(TTR("Change"));
	} else {
		set_title(vformat(TTR("Create New %s"), base_type));
		get_ok()->set_text(TTR("Create"));
	}
}