本文整理汇总了C++中variant::as_string方法的典型用法代码示例。如果您正苦于以下问题:C++ variant::as_string方法的具体用法?C++ variant::as_string怎么用?C++ variant::as_string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类variant
的用法示例。
在下文中一共展示了variant::as_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
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) );
}
示例2:
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;
}
示例3: set_value
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);
}
示例4: set
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());
}
}
示例5: set_value
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);
}
示例6: 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());
}
}
示例7: set_value
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);
}
示例8: from_variant
int from_variant(variant node)
{
if(node.is_string()) {
return from_string(node.as_string());
}
return node.as_int(-1);
}
示例9: set_value
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);
}
示例10: lookup_contact
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) ) }
示例11: lookup_contact
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) ) }
示例12: luaW_pushfaivariant
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);
}
}
示例13: convert_numeric
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;
}
示例14: from_variant
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() );
}
示例15: to_stream
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;
}
}
}