当前位置: 首页>>代码示例>>C++>>正文


C++ variant::has_key方法代码示例

本文整理汇总了C++中variant::has_key方法的典型用法代码示例。如果您正苦于以下问题:C++ variant::has_key方法的具体用法?C++ variant::has_key怎么用?C++ variant::has_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在variant的用法示例。


在下文中一共展示了variant::has_key方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: button

checkbox::checkbox(const variant& v, game_logic::formula_callable* e) 
	: checked_(false), button(v,e)
{
	hpadding_ = v["hpad"].as_int(12);
	if(v.has_key("padding")) {
		ASSERT_LOG(v["padding"].num_elements() == 2, "Incorrect number of padding elements specifed." << v["padding"].num_elements());
		hpadding_ = v["padding"][0].as_int();
	}
	checked_ = v["checked"].as_bool(false);
	variant label_var = v["label"];
	label_ = (label_var.is_map() || label_var.is_callable()) ? "" : label_var.as_string_default("Checkbox");
	label_widget_ = (label_var.is_map() || label_var.is_callable())
		? widget_factory::create(label_var, e) 
		: widget_ptr(new graphical_font_label(label_, "door_label", 2));
	ASSERT_LOG(get_environment() != 0, "You must specify a callable environment");
	click_handler_ = get_environment()->create_formula(v["on_click"]);
	onclick_ = boost::bind(&checkbox::click, this, _1);
	set_click_handler(boost::bind(&checkbox::on_click, this));

	set_label(create_checkbox_widget(label_widget_, 
		checked_, 
		button_resolution(),
		hpadding_));

	if(v.has_key("width") || v.has_key("height")) {
		set_dim(v["width"].as_int(width()), v["height"].as_int(height()));
	}
}
开发者ID:apr-apr-apr,项目名称:anura,代码行数:28,代码来源:checkbox.cpp

示例2:

	world::world(const variant& node)
		: view_distance_(node["view_distance"].as_int(default_view_distance)), 
		seed_(node["seed"].as_int(0))
	{
		ASSERT_LOG(node.has_key("shader"), "Must have 'shader' attribute");
		ASSERT_LOG(node["shader"].is_string(), "'shader' attribute must be a string");
		shader_ = gles2::shader_program::get_global(node["shader"].as_string())->shader();

		if(node.has_key("lighting")) {
			lighting_.reset(new graphics::lighting(shader_, node["lighting"]));
		}

		if(node.has_key("objects")) {
			for(int n = 0; n != node["objects"].num_elements(); ++n) {
				add_object(new user_voxel_object(node["objects"][n]));
			}
		}

		if(node.has_key("skybox")) {
			skybox_.reset(new graphics::skybox(node["skybox"]));
		}

		if(node.has_key("chunks")) {
			logic_.reset(new logical_world(node));
			build_fixed(node["chunks"]);
		} else {
			build_infinite();
		}
	}
开发者ID:AsKorysti,项目名称:anura,代码行数:29,代码来源:isoworld.cpp

示例3: if

	BlendEquation::BlendEquation(const variant& node)
		: rgb_(BlendEquationConstants::BE_ADD),
		  alpha_(BlendEquationConstants::BE_ADD)
	{
		if(node.is_map()) {
			if(node.has_key("rgba")) {
				rgb_ = alpha_ = convert_string_to_equation(node["rgba"].as_string());
			} 
			if(node.has_key("rgb")) {
				rgb_ = convert_string_to_equation(node["rgb"].as_string());
			}
			if(node.has_key("alpha")) {
				alpha_ = convert_string_to_equation(node["alpha"].as_string());
			}
			if(node.has_key("a")) {
				alpha_ = convert_string_to_equation(node["a"].as_string());
			}
		} else if(node.is_list()) {
			ASSERT_LOG(node.num_elements() > 0, "When using a list for blend equation must give at least one element");
			if(node.num_elements() == 1) {
				rgb_ = alpha_ = convert_string_to_equation(node[0].as_string());
			} else {
				rgb_   = convert_string_to_equation(node[0].as_string());
				alpha_ = convert_string_to_equation(node[1].as_string());
			}
		} else if(node.is_string()) {
			// simply setting the rgb/alpha values that same, from string
			rgb_ = alpha_ = convert_string_to_equation(node.as_string());
		} else {
			ASSERT_LOG(false, "Unrecognised type for blend equation: " << node.to_debug_string());
		}
	}
开发者ID:sweetkristas,项目名称:Castles,代码行数:32,代码来源:Blend.cpp

示例4: rect

frame::frame(variant node)
   : id_(node["id"].as_string()),
     image_(node["image"].as_string()),
     variant_id_(id_),
     enter_event_id_(get_object_event_id("enter_" + id_ + "_anim")),
	 end_event_id_(get_object_event_id("end_" + id_ + "_anim")),
	 leave_event_id_(get_object_event_id("leave_" + id_ + "_anim")),
	 process_event_id_(get_object_event_id("process_" + id_)),
     texture_(node.has_key("fbo") ? node["fbo"].convert_to<texture_object>()->texture() : graphics::texture::get(image_, node["image_formula"].as_string_default())),
	 solid_(solid_info::create(node)),
     collide_rect_(node.has_key("collide") ? rect(node["collide"]) :
	               rect(node["collide_x"].as_int(),
                        node["collide_y"].as_int(),
                        node["collide_w"].as_int(),
                        node["collide_h"].as_int())),
	 hit_rect_(node.has_key("hit") ? rect(node["hit"]) :
	               rect(node["hit_x"].as_int(),
				        node["hit_y"].as_int(),
				        node["hit_w"].as_int(),
				        node["hit_h"].as_int())),
	 platform_rect_(node.has_key("platform") ? rect(node["platform"]) :
	                rect(node["platform_x"].as_int(),
	                     node["platform_y"].as_int(),
	                     node["platform_w"].as_int(), 1)),
	 img_rect_(node.has_key("rect") ? rect(node["rect"]) :
	           rect(node["x"].as_int(),
	                node["y"].as_int(),
	                node["w"].as_int(),
	                node["h"].as_int())),
	 feet_x_(node["feet_x"].as_int()),
	 feet_y_(node["feet_y"].as_int()),
	 accel_x_(node["accel_x"].as_int(INT_MIN)),
	 accel_y_(node["accel_y"].as_int(INT_MIN)),
	 velocity_x_(node["velocity_x"].as_int(INT_MIN)),
	 velocity_y_(node["velocity_y"].as_int(INT_MIN)),
	 nframes_(node["frames"].as_int(1)),
	 nframes_per_row_(node["frames_per_row"].as_int(-1)),
	 frame_time_(node["duration"].as_int(-1)),
	 reverse_frame_(node["reverse"].as_bool()),
	 play_backwards_(node["play_backwards"].as_bool()),
	 scale_(node["scale"].as_int(2)),
	 pad_(node["pad"].as_int()),
	 rotate_(node["rotate"].as_int()),
	 blur_(node["blur"].as_int()),
	 rotate_on_slope_(node["rotate_on_slope"].as_bool()),
	 damage_(node["damage"].as_int()),
	 sounds_(util::split(node["sound"].as_string_default())),
	 no_remove_alpha_borders_(node["no_remove_alpha_borders"].as_bool(false)),
	 collision_areas_inside_frame_(true),
	 current_palette_(-1)
{
	std::vector<std::string> hit_frames = util::split(node["hit_frames"].as_string_default());
	foreach(const std::string& f, hit_frames) {
		hit_frames_.push_back(boost::lexical_cast<int>(f));
	}
开发者ID:kimsama,项目名称:frogatto,代码行数:55,代码来源:frame.cpp

示例5: write_instruction

 void xml_writer_impl::write_instruction(const variant& instruction)
 {
     if (instruction.is<variant::Mapping>() && instruction.has_key(xml_target) && instruction.has_key(xml_data))
     {
         m_os << "<?" << instruction[xml_target].as<std::string>() << " " << instruction[xml_data].as<std::string>() << "?>";
     }
     else
     {
         boost::throw_exception(variant_error((boost::format("Expecting dictionary containing '%s' and '%s' for processing instruction") % xml_target % xml_data).str()));
     }        
 }
开发者ID:proteanic,项目名称:protean,代码行数:11,代码来源:xml_writer_impl.cpp

示例6: SDLWindow

		explicit SDLWindow(int width, int height, const variant& hints) 
			: Window(width, height, hints),
			  renderer_hint_(),
			  renderer_(nullptr),
			  context_(nullptr),
			  nonfs_width_(width),
			  nonfs_height_(height),
			  request_major_version_(2),
			  request_minor_version_(1),
			  profile_(ProfileValue::COMPAT)
		{
			if(hints.has_key("renderer")) {
				if(hints["renderer"].is_string()) {
					renderer_hint_.emplace_back(hints["renderer"].as_string());
				} else {
					renderer_hint_ = hints["renderer"].as_list_string();
				}
			} else {
				renderer_hint_.emplace_back("opengl");
			}

			// XXX figure out a better way to pass this hint.
			SDL_SetHint(SDL_HINT_RENDER_DRIVER, renderer_hint_.front().c_str());

			auto dpi_aware = hints["dpi_aware"].as_bool(false);
			if(dpi_aware) {
				SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "0");
			} else {
				SDL_SetHint(SDL_HINT_VIDEO_HIGHDPI_DISABLED, "1");
			}

			if(hints.has_key("version")) {
				const int version = hints["version"].as_int32();
				request_major_version_ = version / 100;
				request_minor_version_ = version % 100;
			}
			if(hints.has_key("profile")) {
				const std::string profile = hints["profile"].as_string();
				if(profile == "compatibility" || profile == "compat") {
					profile_ = ProfileValue::COMPAT;
				} else if(profile == "core") {
					profile_ = ProfileValue::CORE;
				} else if(profile == "es" || profile == "ES") {
					profile_ = ProfileValue::ES;
				} else {
					LOG_ERROR("Unrecognized profile setting '" << profile << "' defaulting to compatibility.");
				}
			}
		}
开发者ID:sweetkristas,项目名称:render_engine,代码行数:49,代码来源:WindowManager.cpp

示例7: widget

	selector_widget::selector_widget(const variant& v, game_logic::formula_callable* e)
		: widget(v, e), current_selection_(v["selection"].as_int(0))
	{
		if(v.has_key("list") || v.has_key("children")) {
			const variant& l = v.has_key("list") ? v["list"] : v["children"];
			ASSERT_LOG(l.is_list(), "'list'/'children' attribute must be a list");
			foreach(const variant& child, l.as_list()) {
				if(child.is_list()) {
					ASSERT_LOG(child.num_elements() == 2, "items in the sub-list must have two elements.");
					widget_ptr w;
					if(child[1].is_map()) {
						w = widget_factory::create(child[1], e);
					} else {
						w = child[1].try_convert<widget>();
						ASSERT_LOG(w != NULL, "Couldn't convert second element to widget.");
					}
					list_.push_back(selector_pair(child[0].as_string(), w));
				} else if(child.is_string()) {
					const std::string& s = child.as_string();
					list_.push_back(selector_pair(s, widget_ptr(new label(s))));
				} else {
					widget_ptr w;
					std::string s;
					if(child.is_map()) {
						w = widget_factory::create(child, e);
						ASSERT_LOG(child.has_key("id") || child.has_key("select_string"), "list items must supply 'id' or 'select_string' attribute.");
						s = child.has_key("id") ? child["id"].as_string() : child["select_string"].as_string();
					} else {
						w = child.try_convert<widget>();
						ASSERT_LOG(w != NULL, "Couldn't convert item to widget.");
						ASSERT_LOG(!w->id().empty(), "list items must have 'id' attribute");
						s = w->id();
					}
					list_.push_back(selector_pair(s, w));
				}
			}
		}

		if(v.has_key("on_change")) {
			change_handler_ = get_environment()->create_formula(v["on_change"]);
			on_change_ = boost::bind(&selector_widget::change_delegate, this, _1);
		}
		if(v.has_key("on_select")) {
			select_handler_ = get_environment()->create_formula(v["on_select"]);
			on_select_ = boost::bind(&selector_widget::select_delegate, this, _1);
		}
		init();
	}
开发者ID:kimsama,项目名称:frogatto,代码行数:48,代码来源:selector_widget.cpp

示例8: rect

	std::vector<CastlePart> parse_dir(const variant& node)
	{
		std::vector<CastlePart> res;
		const std::vector<std::string> keys = { "bl", "br", "l", "r", "tl", "tr" };
		ASSERT_LOG(node.is_map(), "must be a map type.");
		for(auto key : keys) {
			ASSERT_LOG(node.has_key(key), "Must have attribute '" << key << "' in definition.");
			const variant& dir = node[key];
			ASSERT_LOG(dir.has_key("rect"), "Attribute '" << key << "' must have 'rect' definition.");
			CastlePart cp;
			cp.r_ = rect(dir["rect"]);
			if(dir.has_key("border")) {
				ASSERT_LOG(dir["border"].num_elements() == 4, "'border' attribute must be list of 4 integers.");
				for(int n = 0; n != 4; ++n) {
					cp.border_[n] = dir["border"][n].as_int32();
				}
			} else {
				for(int n = 0; n != 4; ++n) {
					cp.border_[n] = 0;
				}
			}
			if(dir.has_key("offset")) {
				cp.offs_ = point(dir["offset"]);
			} else {
				cp.offs_.x = cp.offs_.y = 0;
			}
			res.emplace_back(cp);
		}
		return res;
	}
开发者ID:sweetkristas,项目名称:Castles,代码行数:30,代码来源:main.cpp

示例9: CastleDef

	explicit CastleDef(const std::string& name, const variant& node) 
		: name_(name)
	{
		using namespace KRE;

		ASSERT_LOG(node.has_key("image"), "No 'image' attribute in castle definition.");
		const std::string tex_name = node["image"].as_string();		
		texture_ = Texture::createTexture(tex_name, TextureType::TEXTURE_2D, 4);
		//texture_->setFiltering(Texture::Filtering::LINEAR, Texture::Filtering::LINEAR, Texture::Filtering::POINT);
		texture_->setAddressModes(-1, Texture::AddressMode::BORDER, Texture::AddressMode::BORDER);

		ASSERT_LOG(node.has_key("concave") && node.has_key("convex"),
			"Castle definition must have 'concave' and 'convex' attributes.");

		concave_ = parse_dir(node["concave"]);
		convex_ = parse_dir(node["convex"]);
	}
开发者ID:sweetkristas,项目名称:Castles,代码行数:17,代码来源:main.cpp

示例10: widget

	bar_widget::bar_widget(const variant& v, game_logic::formula_callable* e)
		: widget(v, e), segments_(v["segments"].as_int(1)), 
		segment_length_(v["segment_length"].as_int(5)), 
		rotate_(GLfloat(v["rotation"].as_decimal().as_float())),
		tick_width_(v["tick_width"].as_int(1)), scale_(2.0f),
		drained_segments_(v["drained"].as_int(0)), animating_(false),
		drain_rate_(v["drain_rate"].as_decimal(decimal(10.0)).as_float()),
		total_bar_length_(0), drained_bar_length_(0), active_bar_length_(0),
		left_cap_width_(0), right_cap_width_(0), 
		animation_end_point_unscaled_(0.0f),
		animation_current_position_(0.0f), drained_segments_after_anim_(0),
		bar_max_width_(v["max_width"].as_int())
	{
		if(v.has_key("bar_color")) {
			bar_color_ = graphics::color(v["bar_color"]).as_sdl_color();
		} else {
			bar_color_ = graphics::color("red").as_sdl_color();
		}
		if(v.has_key("tick_color")) {
			tick_mark_color_ = graphics::color(v["tick_color"]).as_sdl_color();
		} else {
			tick_mark_color_ = graphics::color("black").as_sdl_color();
		}
		if(v.has_key("drained_bar_color")) {
			drained_bar_color_ = graphics::color(v["drained_bar_color"]).as_sdl_color();
		} else {
			drained_bar_color_ = graphics::color("black").as_sdl_color();
		}
		if(v.has_key("drained_tick_color")) {
			drained_tick_mark_color_ = graphics::color(v["drained_tick_color"]).as_sdl_color();
		} else {
			drained_tick_mark_color_ = graphics::color("white").as_sdl_color();
		}

		if(v.has_key("scale")) {
			scale_ = GLfloat(v["scale"].as_decimal().as_float());
		}

		ASSERT_LOG(v.has_key("bar"), "Missing 'bar' attribute");
		init_bar_section(v["bar"], &bar_);
		ASSERT_LOG(v.has_key("left_cap"), "Missing 'left_cap' attribute");
		init_bar_section(v["left_cap"], &left_cap_);
		ASSERT_LOG(v.has_key("right_cap"), "Missing 'right_cap' attribute");
		init_bar_section(v["right_cap"], &right_cap_);

		ASSERT_GT(segments_, 0);
		ASSERT_GT(segment_length_, 0);
		if(drained_segments_ > segments_) {
			drained_segments_ = segments_;
		}
		if(drained_segments_ < 0) {
			drained_segments_ = 0;
		}
		bar_height_ = height();
		init();
	}
开发者ID:emmasteimann,项目名称:frogatto,代码行数:56,代码来源:bar_widget.cpp

示例11:

	RenderTarget::RenderTarget(const variant& node)
		: width_(0),
		  height_(0),
		  color_attachments_(1),
		  depth_attachment_(false),
		  stencil_attachment_(false),
		  multi_sampling_(false),
		  multi_samples_(0),
		  clear_color_(0.0f, 0.0f, 0.0f, 1.0f)
	{
		ASSERT_LOG(node.is_map(), "RenderTarget definitions must be maps: " << node.to_debug_string());
		ASSERT_LOG(node.has_key("width"), "Render target must have a 'width' attribute.");
		ASSERT_LOG(node.has_key("height"), "Render target must have a 'height' attribute.");
		width_ = node["width"].as_int32();
		height_ = node["height"].as_int32();
		if(node.has_key("color_planes")) {
			color_attachments_ = node["color_planes"].as_int32();
			ASSERT_LOG(color_attachments_ >= 0, "Number of 'color_planes' must be zero or greater: " << color_attachments_);
		}
		if(node.has_key("depth_buffer")) {
			depth_attachment_ = node["depth_buffer"].as_bool();
		}
		if(node.has_key("stencil_buffer")) {
			stencil_attachment_ = node["stencil_buffer"].as_bool();
		}
		if(node.has_key("use_multisampling")) {
			multi_sampling_ = node["use_multisampling"].as_bool();
			if(node.has_key("samples")) {
				multi_samples_ = node["samples"].as_int32();
			}
		}
		// XXX Maybe we need to add some extra filtering from min to max values based on order ?
	}
开发者ID:sweetkristas,项目名称:Castles,代码行数:33,代码来源:RenderTarget.cpp

示例12: widget

graphical_font_label::graphical_font_label(const variant& v, game_logic::formula_callable* e)
	: widget(v,e)
{
	text_ = v["text"].as_string_default("TEXT");
	font_ = graphical_font::get(v.has_key("font") ? v["font"].as_string() : "door_label");
	ASSERT_LOG(font_.get(), "UNKNOWN FONT: " << v["font"].as_string());
	size_ = v["size"].as_int(12);
	reset_text_dimensions();
}
开发者ID:AsKorysti,项目名称:anura,代码行数:9,代码来源:graphical_font_label.cpp

示例13: init_bar_section

	void bar_widget::init_bar_section(const variant&v, bar_section* b)
	{
		b->texture = graphics::texture::get(v["image"].as_string());
		if(v.has_key("area")) {
			ASSERT_LOG(v["area"].is_list() && v["area"].num_elements() == 4, "'area' attribute must be four element list.");
			b->area = rect(v["area"][0].as_int(), v["area"][1].as_int(), v["area"][2].as_int(), v["area"][3].as_int());
		} else {
			b->area = rect(0, 0, b->texture.width(), b->texture.height());
		}
	}
开发者ID:emmasteimann,项目名称:frogatto,代码行数:10,代码来源:bar_widget.cpp

示例14: createEffect

	EffectPtr DisplayDeviceOpenGL::createEffect(const variant& node)
	{
		ASSERT_LOG(node.has_key("type") && node["type"].is_string(), "Effects must have 'type' attribute as string: " << node.to_debug_string());
		const std::string& type = node["type"].as_string();
		if(type == "stipple") {
			return std::make_shared<OpenGL::StippleEffect>(node);
		}
		// XXX Add more effects here as and if needed.
		return EffectPtr();
	}
开发者ID:sweetkristas,项目名称:mercy,代码行数:10,代码来源:DisplayDeviceOGL.cpp

示例15: emit_object

			explicit emit_object(particle_system_container* parent, const variant& node) 
				: parent_container_(parent) {
				ASSERT_LOG(parent != NULL, "FATAL: PSYSTEM2: parent is null");
				if(node.has_key("name")) {
					name_ = node["name"].as_string();
				} else {
					std::stringstream ss;
					ss << "emit_object_" << int(get_random_float());
					name_ = ss.str();
				}
			}
开发者ID:LungTakumi,项目名称:anura,代码行数:11,代码来源:psystem2.hpp


注:本文中的variant::has_key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。