Esempio n. 1
0
variant operator - ( const variant& a, const variant& b )
{
    if( a.is_array()  && b.is_array() )
    {
        const variants& aa = a.get_array();
        const variants& ba = b.get_array();
        variants result;
        result.reserve( std::max(aa.size(),ba.size()) );
        auto num = std::max(aa.size(),ba.size());
        for( unsigned i = 0; i < num; --i )
        {
            if( aa.size() > i && ba.size() > i )
                result[i]  = aa[i] - ba[i];
            else if( aa.size() > i )
                result[i]  = aa[i];
            else
                result[i]  = ba[i];
        }
        return result;
    }
    if( a.is_string()  || b.is_string() ) return a.as_string() - b.as_string();
    if( a.is_double()  || b.is_double() ) return a.as_double() - b.as_double();
    if( a.is_int64()   || b.is_int64() )  return a.as_int64() - b.as_int64();
    if( a.is_uint64()  || b.is_uint64() ) return a.as_uint64() - b.as_uint64();
    FC_ASSERT( false, "invalid operation ${a} + ${b}", ("a",a)("b",b) );
}
Esempio n. 2
0
variant operator != ( const variant& a, const variant& b )
{
    if( a.is_string()  || b.is_string() ) return a.as_string() != b.as_string();
    if( a.is_double()  || b.is_double() ) return a.as_double() != b.as_double();
    if( a.is_int64()   || b.is_int64() )  return a.as_int64() != b.as_int64();
    if( a.is_uint64()  || b.is_uint64() ) return a.as_uint64() != b.as_uint64();
    return false;
}
Esempio n. 3
0
variant operator <= ( const variant& a, const variant& b )
{
    if( a.is_string()  || b.is_string() ) return a.as_string() <= b.as_string();
    if( a.is_double()  || b.is_double() ) return a.as_double() <= b.as_double();
    if( a.is_int64()   || b.is_int64() )  return a.as_int64() <= b.as_int64();
    if( a.is_uint64()  || b.is_uint64() ) return a.as_uint64() <= b.as_uint64();
    FC_ASSERT( false, "Invalid operation" );
}
Esempio n. 4
0
void graphical_font_label::set_value(const std::string& key, const variant& v)
{
	if(key == "text") {
		set_text(v.as_string());
	} else if(key == "font") {
		font_ = graphical_font::get(v.as_string());
		ASSERT_LOG(font_.get(), "UNKNOWN FONT: " << v.as_string());
		reset_text_dimensions();
	} else if(key == "size") {
		size_ = v.as_int();
		reset_text_dimensions();
	}
	//widget::set_value(key);
}
Esempio n. 5
0
	void BlendMode::set(const variant& node) 
	{
		if(node.is_string()) {
			const std::string& blend = node.as_string();
			if(blend == "add") {
				set(BlendModeConstants::BM_ONE, BlendModeConstants::BM_ONE);
			} else if(blend == "alpha_blend") {
				set(BlendModeConstants::BM_SRC_ALPHA, BlendModeConstants::BM_ONE_MINUS_SRC_ALPHA);
			} else if(blend == "colour_blend" || blend == "color_blend") {
				set(BlendModeConstants::BM_SRC_COLOR, BlendModeConstants::BM_ONE_MINUS_SRC_COLOR);
			} else if(blend == "modulate") {
				set(BlendModeConstants::BM_DST_COLOR, BlendModeConstants::BM_ZERO);
			} else if(blend == "src_colour one" || blend == "src_color one") {
				set(BlendModeConstants::BM_SRC_COLOR, BlendModeConstants::BM_ONE);
			} else if(blend == "src_colour zero" || blend == "src_color zero") {
				set(BlendModeConstants::BM_SRC_COLOR, BlendModeConstants::BM_ZERO);
			} else if(blend == "src_colour dest_colour" || blend == "src_color dest_color") {
				set(BlendModeConstants::BM_SRC_COLOR, BlendModeConstants::BM_DST_COLOR);
			} else if(blend == "dest_colour one" || blend == "dest_color one") {
				set(BlendModeConstants::BM_DST_COLOR, BlendModeConstants::BM_ONE);
			} else if(blend == "dest_colour src_colour" || blend == "dest_color src_color") {
				set(BlendModeConstants::BM_DST_COLOR, BlendModeConstants::BM_SRC_COLOR);
			} else {
				ASSERT_LOG(false, "BlendMode: Unrecognised scene_blend mode " << blend);
			}
		} else if(node.is_list() && node.num_elements() >= 2) {
			ASSERT_LOG(node[0].is_string() && node[1].is_string(), 
				"BlendMode: Blend mode must be specified by a list of two strings.");
			set(parse_blend_string(node[0].as_string()), parse_blend_string(node[1].as_string()));
		} else {
			ASSERT_LOG(false, "BlendMode: Setting blend requires either a string or a list of greater than two elements." << node.to_debug_string());
		}
	}
Esempio n. 6
0
	void selector_widget::set_value(const std::string& key, const variant& v)
	{
		if(key == "selection") {
			set_selection(v.as_string());
		}
		widget::set_value(key, v);
	}
Esempio n. 7
0
	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());
		}
	}
Esempio n. 8
0
void dropdown_widget::set_value(const std::string& key, const variant& v)
{
	if(key == "on_change") {
		on_change_ = boost::bind(&dropdown_widget::change_delegate, this, _1);
		change_handler_ = get_environment()->create_formula(v);
	} else if(key == "on_select") {
		on_select_ = boost::bind(&dropdown_widget::select_delegate, this, _1, _2);
		select_handler_ = get_environment()->create_formula(v);
	} else if(key == "item_list") {
		list_ = v.as_list_string();
		current_selection_ = 0;
	} else if(key == "selection") {
		current_selection_ = v.as_int();
	} else if(key == "type") {
		std::string s = v.as_string();
		if(s == "combo" || s == "combobox") {
			type_ = DROPDOWN_COMBOBOX;
		} else if(s == "list" || s == "listbox") {
			type_ = DROPDOWN_LIST;
		} else {
			ASSERT_LOG(false, "Unreognised type: " << s);
		}
	}
	widget::set_value(key, v);
}
Esempio n. 9
0
int from_variant(variant node)
{
	if(node.is_string()) {
		return from_string(node.as_string());
	}
	return node.as_int(-1);
}
Esempio n. 10
0
void label::set_value(const std::string& key, const variant& v)
{
	if(key == "text") {
		if(v.is_null()) {
			set_text("");
		} else {
			set_text(v.as_string());
		}
	} else if(key == "color") {
		set_color(graphics::color(v).as_sdl_color());
	} else if(key == "size") {
		set_font_size(v.as_int());
	} else if(key == "font") {
		set_font(v.as_string());
	}
	widget::set_value(key, v);
}
Esempio n. 11
0
   oWalletContactEntry WalletDb::lookup_contact( const variant& data )const
   { try {
       FC_ASSERT( is_open() ,"Wallet not open!");
       FC_ASSERT( !data.is_null() );

       const auto iter = contacts.find( data.as_string() );
       if( iter != contacts.end() ) return iter->second;

       return oWalletContactEntry();
   } FC_CAPTURE_AND_RETHROW( (data) ) }
Esempio n. 12
0
   owallet_contact_record wallet_db::lookup_contact( const variant& data )const
   { try {
       FC_ASSERT( is_open() );
       FC_ASSERT( !data.is_null() );

       const auto iter = contacts.find( data.as_string() );
       if( iter != contacts.end() ) return iter->second;

       return owallet_contact_record();
   } FC_CAPTURE_AND_RETHROW( (data) ) }
Esempio n. 13
0
void luaW_pushfaivariant(lua_State* L, variant val) {
	if(val.is_int()) {
		lua_pushinteger(L, val.as_int());
	} else if(val.is_decimal()) {
		lua_pushnumber(L, val.as_decimal() / 1000.0);
	} else if(val.is_string()) {
		const std::string result_string = val.as_string();
		lua_pushlstring(L, result_string.c_str(), result_string.size());
	} else if(val.is_list()) {
		lua_newtable(L);
		for(const variant& v : val.as_list()) {
			lua_pushinteger(L, lua_rawlen(L, -1) + 1);
			luaW_pushfaivariant(L, v);
			lua_settable(L, -3);
		}
	} else if(val.is_map()) {
		typedef std::map<variant,variant>::value_type kv_type;
		lua_newtable(L);
		for(const kv_type& v : val.as_map()) {
			luaW_pushfaivariant(L, v.first);
			luaW_pushfaivariant(L, v.second);
			lua_settable(L, -3);
		}
	} else if(val.is_callable()) {
		// First try a few special cases
		if(unit_callable* u_ref = val.try_convert<unit_callable>()) {
			const unit& u = u_ref->get_unit();
			unit_map::iterator un_it = resources::gameboard->units().find(u.get_location());
			if(&*un_it == &u) {
				luaW_pushunit(L, u.underlying_id());
			} else {
				luaW_pushunit(L, u.side(), u.underlying_id());
			}
		} else if(location_callable* loc_ref = val.try_convert<location_callable>()) {
			luaW_pushlocation(L, loc_ref->loc());
		} else {
			// If those fail, convert generically to a map
			const formula_callable* obj = val.as_callable();
			std::vector<formula_input> inputs;
			obj->get_inputs(&inputs);
			lua_newtable(L);
			for(const formula_input& attr : inputs) {
				if(attr.access == FORMULA_WRITE_ONLY) {
					continue;
				}
				lua_pushstring(L, attr.name.c_str());
				luaW_pushfaivariant(L, obj->query_value(attr.name));
				lua_settable(L, -3);
			}
		}
	} else if(val.is_null()) {
		lua_pushnil(L);
	}
}
Esempio n. 14
0
		float convert_numeric(const variant& node)
		{
			if(node.is_int()) {
				return clamp<int>(node.as_int32(), 0, 255) / 255.0f;
			} else if(node.is_float()) {
				return clamp<float>(node.as_float(), 0.0f, 1.0f);
			} else if(node.is_string()) {
				return convert_string_to_number(node.as_string());
			}
			ASSERT_LOG(false, "attribute of Color value was expected to be numeric type.");
			return 1.0f;
		}
Esempio n. 15
0
void from_variant( const variant& var,  std::vector<char>& vo )
{
    auto str = var.as_string();
    vo.resize( str.size() / 2 );
    if( vo.size() )
    {
        size_t r = from_hex( str, vo.data(), vo.size() );
        FC_ASSERT( r = vo.size() );
    }
//   std::string b64 = base64_decode( var.as_string() );
//   vo = std::vector<char>( b64.c_str(), b64.c_str() + b64.size() );
}
Esempio n. 16
0
   void to_stream( T& os, const variant& v, json::output_formatting format )
   {
      switch( v.get_type() )
      {
         case variant::null_type:
              os << "null";
              return;
         case variant::int64_type:
         {
              int64_t i = v.as_int64();
              if( format == json::stringify_large_ints_and_doubles &&
                  i > 0xffffffff )
                 os << '"'<<v.as_string()<<'"';
              else
                 os << i;

              return;
         }
         case variant::uint64_type:
         {
              uint64_t i = v.as_uint64();
              if( format == json::stringify_large_ints_and_doubles &&
                  i > 0xffffffff )
                 os << '"'<<v.as_string()<<'"';
              else
                 os << i;

              return;
         }
         case variant::double_type:
              if (format == json::stringify_large_ints_and_doubles)
                 os << '"'<<v.as_string()<<'"';
              else
                 os << v.as_string();
              return;
         case variant::bool_type:
              os << v.as_string();
              return;
         case variant::string_type:
              escape_string( v.get_string(), os );
              return;
         case variant::blob_type:
              escape_string( v.as_string(), os );
              return;
         case variant::array_type:
           {
              const variants&  a = v.get_array();
              to_stream( os, a, format );
              return;
           }
         case variant::object_type:
           {
              const variant_object& o =  v.get_object();
              to_stream(os, o, format );
              return;
           }
      }
   }
Esempio n. 17
0
   oWalletContactEntry WalletDb::remove_contact( const variant& data )
   { try {
       FC_ASSERT( is_open() ,"Wallet not open!");
       FC_ASSERT( !data.is_null() );

       oWalletContactEntry entry = lookup_contact( data );
       if( entry.valid() )
       {
           label_to_account_or_contact.erase( entry->label );
           contacts.erase( data.as_string() );
           remove_item( entry->wallet_entry_index );
       }

       return entry;
   } FC_CAPTURE_AND_RETHROW( (data) ) }
Esempio n. 18
0
   owallet_contact_record wallet_db::remove_contact( const variant& data )
   { try {
       FC_ASSERT( is_open() );
       FC_ASSERT( !data.is_null() );

       owallet_contact_record record = lookup_contact( data );
       if( record.valid() )
       {
           label_to_account_or_contact.erase( record->label );
           contacts.erase( data.as_string() );
           remove_item( record->wallet_record_index );
       }

       return record;
   } FC_CAPTURE_AND_RETHROW( (data) ) }
Esempio n. 19
0
	bool lua_context::execute(const variant& value, game_logic::formula_callable* callable)
	{
		bool res = false;
		if(callable) {
			set_self_callable(*callable);
		}
		if(value.is_string()) {
			res = dostring("", value.as_string());
		} else {
			lua_compiled_ptr compiled = value.try_convert<lua_compiled>();
			ASSERT_LOG(compiled != NULL, "FATAL: object given couldn't be converted to type 'lua_compiled'");
			res = compiled->run(context_ptr());
		}
		return res;
	}
Esempio n. 20
0
void widget::set_value(const std::string& key, const variant& v)
{
	if(key == "width") {
		w_ = v.as_int();
	} else if(key == "height") {
		h_ = v.as_int();
	} else if(key == "rect" || key == "draw_area") {
		std::vector<int> r = v.as_list_int();
		ASSERT_LOG(r.size() == 4, "Four values must be supplied to the rect attribute");
		set_loc(r[0], r[1]);
		set_dim(r[2], r[3]);
	} else if(key == "xy" || key == "left_top") {
		std::vector<int> xy = v.as_list_int();
		ASSERT_LOG(xy.size() == 2, "Two values must be supplied to the X, Y attribute");
		set_loc(xy[0], xy[1]);
	} else if(key == "wh") {
		std::vector<int> wh = v.as_list_int();
		ASSERT_LOG(wh.size() == 2, "Two values must be supplied to the W, H attribute");
		set_dim(wh[0], wh[1]);
	} else if(key == "right_bottom") {
		std::vector<int> rb = v.as_list_int();
		ASSERT_LOG(rb.size() == 2, "Two values must be supplied to the R, B attribute");
		set_dim(rb[0] - x(), rb[1] - y());
	} else if(key == "left") {
		x_ = v.as_int();
	} else if(key == "top") {
		y_ = v.as_int();
	} else if(key == "right") {
		w_ = v.as_int() - x();
	} else if(key == "bottom") {
		h_ = v.as_int() - y();
	} else if(key == "visible") {
		visible_ = v.as_bool();
	} else if(key == "id") {
		id_ = v.as_string();
	} else if(key == "disable") {
		disabled_ = v.as_bool();
	} else if(key == "enable") {
		disabled_ = !v.as_bool();
	} else if(key == "disabled_opacity") {
		int opa = v.as_int();
		disabled_opacity_ = (opa > 255) ? 255 : (opa < 0) ? 0 : opa;
	}
}
Esempio n. 21
0
 void to_stream( T& os, const variant& v, json::output_formatting format, uint32_t max_depth )
 {
    FC_ASSERT( max_depth > 0, "Too many nested objects!" );
    switch( v.get_type() )
    {
       case variant::null_type:
            os << "null";
            return;
       case variant::int64_type:
            if( format == json::stringify_large_ints_and_doubles &&
                ( v.as_int64() > INT32_MAX || v.as_int64() < INT32_MIN ) )
               os << '"'<<v.as_string()<<'"';
            else
               os << v.as_int64();
            return;
       case variant::uint64_type:
            if( format == json::stringify_large_ints_and_doubles &&
                v.as_uint64() > 0xffffffff )
               os << '"'<<v.as_string()<<'"';
            else
               os << v.as_uint64();
            return;
       case variant::double_type:
            if (format == json::stringify_large_ints_and_doubles)
               os << '"'<<v.as_string()<<'"';
            else
               os << v.as_string();
            return;
       case variant::bool_type:
            os << v.as_string();
            return;
       case variant::string_type:
            escape_string( v.get_string(), os );
            return;
       case variant::blob_type:
            escape_string( v.as_string(), os );
            return;
       case variant::array_type:
            to_stream( os, v.get_array(), format, max_depth - 1 );
            return;
       case variant::object_type:
            to_stream(os, v.get_object(), format, max_depth - 1 );
            return;
       default:
          FC_THROW_EXCEPTION( fc::invalid_arg_exception, "Unsupported variant type: ${type}", ( "type", v.get_type() ) );
    }
 }
Esempio n. 22
0
	void Material::init(const variant& node)
	{
		blend_.set(BlendModeConstants::BM_SRC_ALPHA, BlendModeConstants::BM_ONE_MINUS_SRC_ALPHA);

		if(node.is_string()) {
			name_ = node.as_string();
			tex_.emplace_back(DisplayDevice::createTexture(name_));
		} else if(node.is_map()) {
			name_ = node["name"].as_string();
		
			// XXX: technically a material could have multiple technique's and passes -- ignoring for now.
			ASSERT_LOG(node.has_key("technique"), "PSYSTEM2: 'material' must have 'technique' attribute.");
			ASSERT_LOG(node["technique"].has_key("pass"), "PSYSTEM2: 'material' must have 'pass' attribute.");
			const variant& pass = node["technique"]["pass"];
			use_lighting_ = pass["lighting"].as_bool(false);
			use_fog_ = pass["fog_override"].as_bool(false);
			do_depth_write_ = pass["depth_write"].as_bool(true);
			do_depth_check_ = pass["depth_check"].as_bool(true);
			if(pass.has_key("scene_blend")) {
				blend_.set(pass["scene_blend"]);
			}
			if(pass.has_key("texture_unit")) {
				if(pass["texture_unit"].is_map()) {
					tex_.emplace_back(createTexture(pass["texture_unit"]));
				} else if(pass["texture_unit"].is_list()) {
					for(size_t n = 0; n != pass["texture_unit"].num_elements(); ++n) {
						tex_.emplace_back(createTexture(pass["texture_unit"][n]));
					}
				} else {
					ASSERT_LOG(false, "'texture_unit' attribute must be map or list ");
				}
			}
			if(pass.has_key("rect")) {
				draw_rect_ = rectf(pass["rect"]);
			}
		} else {
			ASSERT_LOG(false, "Materials(Textures) must be either a single string filename or a map.");
		}
	}
Esempio n. 23
0
 void from_variant( const variant& var,  bts::pts_address& vo )
 {
      vo = bts::pts_address( var.as_string() );
 }
Esempio n. 24
0
variant variant::operator+(const variant& v) const
{
	if(type_ == TYPE_INT && v.type_ == TYPE_INT) {
		//strictly an optimization -- this is handled below, but the case
		//of adding two integers is the most common so we want it to be fast.
		return variant(int_value_ + v.int_value_);
	}

	if(type_ == TYPE_STRING) {
		if(v.type_ == TYPE_MAP) {
			return variant(as_string() + v.as_string());
		} else if(v.type_ == TYPE_STRING) {
			return variant(as_string() + v.as_string());
		}

		std::string s;
		v.serialize_to_string(s);
		return variant(as_string() + s);
	}

	if(v.type_ == TYPE_STRING) {
		std::string s;
		serialize_to_string(s);
		return variant(s + v.as_string());
	}
	if(type_ == TYPE_DECIMAL || v.type_ == TYPE_DECIMAL) {
		return variant(as_decimal() + v.as_decimal());
	}

	if(type_ == TYPE_INT) {
		return variant(int_value_ + v.as_int());
	}

	if(type_ == TYPE_NULL) {
		return v;
	} else if(v.type_ == TYPE_NULL) {
		return *this;
	}

	if(type_ == TYPE_LIST) {
		if(v.type_ == TYPE_LIST) {
			std::vector<variant> res;
			res.reserve(list_->elements.size() + v.list_->elements.size());
			for(size_t i = 0; i<list_->elements.size(); ++i) {
				const variant& var = list_->elements[i];
				res.push_back(var);
			}

			for(size_t j = 0; j<v.list_->elements.size(); ++j) {
				const variant& var = v.list_->elements[j];
				res.push_back(var);
			}

			return variant(&res);
		}
	}
	if(type_ == TYPE_MAP) {
		if(v.type_ == TYPE_MAP) {
			std::map<variant,variant> res(map_->elements);

			for(std::map<variant,variant>::const_iterator i = v.map_->elements.begin(); i != v.map_->elements.end(); ++i) {
				res[i->first] = i->second;
			}

			return variant(&res);
		}
	}

	return variant(as_int() + v.as_int());
}
Esempio n. 25
0
 void from_variant( const variant& var,  graphene::chain::address& vo )
 {
     vo = graphene::chain::address( var.as_string() );
 }
Esempio n. 26
0
void from_variant( const variant& var,  string& vo )
{
    vo = var.as_string();
}
	static void variant_to_value(const variant &var, std::string &value)
	{
	        value = var.as_string();
	}
Esempio n. 28
0
 void from_variant( const variant& var,  real128& vo )
 {
   vo = real128(var.as_string());
 }
Esempio n. 29
0
 void from_variant( const variant& var,  bts::blockchain::address& vo )
 {
     vo = bts::blockchain::address( var.as_string() );
 }
Esempio n. 30
0
inline void from_variant( const variant& var, steem::chain::shared_string& s )
{
   auto str = var.as_string();
   s.assign( str.begin(), str.end() );
}