本文整理汇总了C++中any类的典型用法代码示例。如果您正苦于以下问题:C++ any类的具体用法?C++ any怎么用?C++ any使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了any类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: if
void JsonSerializer::recurseRead(Json::Value& jv, any& av)
{
if(av.type() == typeid(int))
{
jv = any_cast<int>(av);
}
else if(av.type() == typeid(unsigned int))
{
jv = any_cast<unsigned int>(av);
}
else if(av.type() == typeid(long long int))
{
jv = any_cast<long long int>(av);
}
else if(av.type() == typeid(unsigned long long int))
{
jv = any_cast<unsigned long long int>(av);
}
else if(av.type() == typeid(float))
{
jv = any_cast<float>(av);
}
else if(av.type() == typeid(double))
{
jv = any_cast<double>(av);
}
else if(av.type() == typeid(bool))
{
jv = any_cast<bool>(av);
}
else if(av.type() == typeid(string))
{
string str = any_cast<string>(av);
jv = str;
}
else if(av.type() == typeid(list<any>))
{
auto lst = any_cast<list<any>&>(av);
int i = 0;
for(auto it:lst)
{
recurseRead(jv[i], it);
++i;
}
}
else if(av.type() == typeid(list<pair<string, any> >))
{
list<pair<string, any> >& lst = any_cast<list<pair<string, any> >&>(av);
Json::Value tmp;
for(auto it:lst)
{
recurseRead(tmp[it.first], it.second);
}
jv.append(tmp);
}
else
{
cout<<"error wrong type!"<<endl;
}
}
开发者ID:lonsharn,项目名称:lsh_server,代码行数:60,代码来源:json_serializer.cpp
示例2: set
void field::set(any& o, const any& value) const
{
if (this->_setter != nullptr)
{
any v = this->desc().cast(value);
this->_setter (o,v);
return;
}
void* optr = o.ptr();
word8** ptr = memory::ptr(optr,this->_offset);
if (this->_descriptor->has(descriptor::Flags::FIELDS))
{
if (this->_flags.test(field::FLAGS_IS_POINTER))
{
word8** destination = (word8**) ptr;
word8* source = (word8*) value.ptr();
*destination = source;
}
}
else
{
if (value.type() == typeid(std::string))
{
std::string svalue = anycast<std::string>(value);
this->froms(o,svalue);
}
else
this->_descriptor->set(ptr,value);
}
}
开发者ID:jmichael218,项目名称:laurena,代码行数:31,代码来源:field.cpp
示例3: test_default_ctor
void test_default_ctor()
{
const any value;
check_true(value.empty(), "empty");
check_null(any_cast<int>(&value), "any_cast<int>");
check_equal(value.type(), typeid(void), "type");
}
开发者ID:untgames,项目名称:funner,代码行数:8,代码来源:any.cpp
示例4: test_null_copying
void test_null_copying()
{
const any null;
any copied = null, assigned;
assigned = null;
check_true(null.empty(), "empty on null");
check_true(copied.empty(), "empty on copied");
check_true(assigned.empty(), "empty on copied");
}
开发者ID:untgames,项目名称:funner,代码行数:10,代码来源:any.cpp
示例5: any
//CAST
any bitset_descriptor::cast (const any& value) const
{
if (value.desc() != this)
{
any destination;
std::string svalue;
return this->stoa(value.desc()->atos(value), destination);
}
return any(value);
}
开发者ID:jmichael218,项目名称:laurena,代码行数:12,代码来源:bitset_descriptor.cpp
示例6: same
//! \brief Return if two any objects are the same or not.
bool same( const any &other ) const
{
if( this->empty() && other.empty() )
return true;
else if( this->empty() && !other.empty() )
return false;
else if( !this->empty() && other.empty() )
return false;
// !this->empty() && !other.empty()
return content->same(*other.content);
}
开发者ID:haripandey,项目名称:trilinos,代码行数:12,代码来源:Teuchos_any.hpp
示例7: set
// RAW VALUE SERIALIZATION
void bitset_descriptor::set(void* ptr, const any& value) const
{
boost::dynamic_bitset<>* destination = (boost::dynamic_bitset<>*) ptr;
if (value.desc() != this)
{
any a = destination;
std::string svalue = std::move(value.desc()->atos(value));
this->stoa(svalue, a);
*destination = *anycast<boost::dynamic_bitset<>*>(a);
}
else
{
*destination = *anycast<boost::dynamic_bitset<>*>(value);
}
}
开发者ID:jmichael218,项目名称:laurena,代码行数:16,代码来源:bitset_descriptor.cpp
示例8: switch
/* set a named property */
bool GemState::set(const GemState::key_t key, any value) {
if(value.empty()) {
data->data.erase(key);
return false;
}
/* wrapper for DEPRECATED access to member variables */
if(1) {
try {
switch(key) {
case(_DIRTY): dirty=gem::any_cast<bool>(value); break;
case(_PIX): image=gem::any_cast<pixBlock*>(value); break;
case(_GL_TEX_NUMCOORDS): numTexCoords=gem::any_cast<int>(value); break;
case(_GL_TEX_COORDS): texCoords=gem::any_cast<TexCoord*>(value); break;
case(_GL_LIGHTING): lighting=gem::any_cast<bool>(value); break;
case(_GL_SMOOTH): smooth=gem::any_cast<bool>(value); break;
case(_GL_TEX_TYPE): texture=gem::any_cast<int>(value); break;
case(_GL_TEX_UNITS): multiTexUnits=gem::any_cast<int>(value); break;
case(_TIMING_TICK): tickTime=gem::any_cast<float>(value); break;
case(_GL_DRAWTYPE): drawType=gem::any_cast<GLenum>(value); break;
case(_GL_DISPLAYLIST): inDisplayList=gem::any_cast<bool>(value); break;
default: break;
}
} CATCH_ANY(key);
}
data->data[key]=value;
return true;
}
开发者ID:avilleret,项目名称:Gem,代码行数:29,代码来源:State.cpp
示例9: do_put
// in_value must either hold an object of value_type or a string that
// can be converted to value_type via iostreams.
void do_put(const any& in_key, const any& in_value, mpl::bool_<true>)
{
#if !(defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 95))
using boost::put;
#endif
key_type key = any_cast<key_type>(in_key);
if (in_value.type() == typeid(value_type)) {
#if defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 95)
boost::put(property_map, key, any_cast<value_type>(in_value));
#else
put(property_map, key, any_cast<value_type>(in_value));
#endif
} else {
// if in_value is an empty string, put a default constructed value_type.
std::string v = any_cast<std::string>(in_value);
if (v.empty()) {
#if defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 95)
boost::put(property_map, key, value_type());
#else
put(property_map, key, value_type());
#endif
} else {
#if defined(__GNUC__) && (__GNUC__ == 2) && (__GNUC_MINOR__ == 95)
boost::put(property_map, key, detail::read_value<value_type>(v));
#else
put(property_map, key, detail::read_value<value_type>(v));
#endif
}
}
}
开发者ID:JupiterSmalltalk,项目名称:openqwaq,代码行数:33,代码来源:dynamic_property_map.hpp
示例10: any
any descriptor::cast (const any& value) const
{
if (value.type() == this->type())
{
return any(value);
}
throw new LAURENA_UNIMPLEMENTED_EXCEPTION("recast not implemented for this class");
}
开发者ID:jmichael218,项目名称:laurena,代码行数:8,代码来源:descriptor.cpp
示例11: atos
// TO/FROM STRING SERIALIZATION
std::string any_descriptor::atos(const any& value) const
{
const descriptor* cd = value.desc();
if (!cd)
{
throw LAURENA_NULL_POINTER_EXCEPTION("unknow class descriptor");
}
return cd->atos(value);
}
开发者ID:jmichael218,项目名称:laurena,代码行数:11,代码来源:any_descriptor.cpp
示例12: froms
void field::froms(any& object, const std::string& svalue) const
{
any value;
void* ptrObject = object.ptr();
void* ptrAttribute = this->ptr(ptrObject);
value = svalue;
this->_descriptor->set(ptrAttribute,value);
}
开发者ID:jmichael218,项目名称:laurena,代码行数:10,代码来源:field.cpp
示例13: impl
static void impl(CONTAINER* c, const descriptor* element_descriptor, any& element)
{
if ( element.desc()->has(descriptor::Flags::ATOMIC))
{
element = element_descriptor->cast(element);
c->push_back(anycast<ELEMENT>(element));
}
else
{
ELEMENT* e = anycast<ELEMENT*>(element);
c->push_back(*e);
}
}
开发者ID:jmichael218,项目名称:laurena,代码行数:13,代码来源:list_descriptor.hpp
示例14: do_put
// in_value must either hold an object of value_type or a string that
// can be converted to value_type via iostreams.
void do_put(const any& in_key, const any& in_value, mpl::bool_<true>)
{
using boost::put;
key_type key = any_cast<key_type>(in_key);
if (in_value.type() == typeid(value_type)) {
put(property_map_, key, any_cast<value_type>(in_value));
} else {
// if in_value is an empty string, put a default constructed value_type.
std::string v = any_cast<std::string>(in_value);
if (v.empty()) {
put(property_map_, key, value_type());
} else {
put(property_map_, key, detail::read_value<value_type>(v));
}
}
}
开发者ID:0xDEC0DE8,项目名称:mcsema,代码行数:19,代码来源:dynamic_property_map.hpp
示例15: LAURENA_NULL_POINTER_EXCEPTION
void oarchive_json::serializeObject(const any& value)
{
const descriptor* cd = value.desc();
if ( !cd)
{
throw new LAURENA_NULL_POINTER_EXCEPTION("any& value do have nullptr descriptor.");
}
word32 backup = this->_nb_fields;
this->_nb_fields = 0;
std::string opening = "{";
std::string ending = "}" ;
if (cd->hasFeature(Feature::CONTAINER))
{
opening = "[" ;
ending = "]" ;
}
// opening
if (this->_compact)
this->_data << opening ;
else
{
this->_data << this->_tab << opening << std::endl;
this->_tab.increase();
}
if (cd->has(descriptor::Flags::FIELDS))
this->serializeFields(*cd,value);
if (cd->hasFeature(Feature::CONTAINER))
this->serializeElements(*cd,value);
if (this->_compact)
this->_data << ending ;
else
{
this->_data << std::endl << this->_tab.decrease() << ending ;
}
this->_nb_fields = backup;
}
开发者ID:jmichael218,项目名称:laurena,代码行数:46,代码来源:oarchive_json.cpp
示例16: if
bool
rpc::manager::validate( const any &message, any &error )
{
any err;
bool ok = true;
if ( !message.is_object() || !message.is_member( "jsonrpc" ) || ( message[ "jsonrpc" ].to_string() != "2.0" ) )
{
err[ "code" ] = errc::invalid_request;
err[ "message" ] = "Invalid JSON-RPC request.";
error[ "id" ] = any::null();
error[ "jsonrpc" ] = "2.0";
error[ "error" ] = err;
ok = false;
}
else if ( !message.is_member( "method" ) && !message.is_member( "id" ) )
{
err[ "code" ] = errc::invalid_request;
err[ "message" ] = "Invalid JSON-RPC request.";
error[ "id" ] = any::null();
error["jsonrpc" ] = "2.0";
error[ "error" ] = err;
ok = false;
}
else if ( message.is_member( "id" ) && !message[ "id" ].is_integer() )
{
err[ "code" ] = errc::invalid_request;
err[ "message" ] = "Invalid JSON-RPC request.";
error[ "id" ] = any::null();
error[ "jsonrpc" ] = "2.0";
error[ "error" ] = err;
ok = false;
}
else if ( message.is_member( "method" ) && !message["method"].is_string() )
{
err[ "code" ] = errc::invalid_request;
err[ "message" ] = "Invalid JSON-RPC request.";
error[ "id" ] = any::null();
error["jsonrpc" ] = "2.0";
error[ "error" ] = err;
ok = false;
}
return ok;
}
开发者ID:porchdog,项目名称:nodeoze,代码行数:53,代码来源:rpc.cpp
示例17: can_cast
bool can_cast(any &a)
{ return typeid(T) == a.type();}
开发者ID:BigR-Lab,项目名称:CodeRes_Cpp,代码行数:2,代码来源:any.cpp
示例18: is_empty
bool is_empty(any<has_empty<bool(), const _self>, const _self&> x) {
return x.empty();
}
开发者ID:LancelotGHX,项目名称:Simula,代码行数:3,代码来源:basic.cpp
示例19: append_many
void append_many(any<has_push_back<void(int)>, _self&> container) {
for(int i = 0; i < 10; ++i)
container.push_back(i);
}
开发者ID:LancelotGHX,项目名称:Simula,代码行数:4,代码来源:basic.cpp
示例20: is_int
bool is_int(const any & operand)
{
return operand.type() == typeid(int);
}
开发者ID:vcbin,项目名称:stupidalgorithm,代码行数:4,代码来源:scheduler.cpp
注:本文中的any类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论