本文整理汇总了C++中Any::Type方法的典型用法代码示例。如果您正苦于以下问题:C++ Any::Type方法的具体用法?C++ Any::Type怎么用?C++ Any::Type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Any
的用法示例。
在下文中一共展示了Any::Type方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetProperties
void ServiceRegistration::SetProperties(const ServiceProperties& props)
{
if (!d) throw std::logic_error("ServiceRegistration object invalid");
MutexLocker lock(d->eventLock);
ServiceListeners::ServiceListenerEntries before;
// TBD, optimize the locking of services
{
//MutexLocker lock2(d->module->coreCtx->globalFwLock);
if (d->available)
{
// NYI! Optimize the MODIFIED_ENDMATCH code
int old_rank = 0;
int new_rank = 0;
std::list<std::string> classes;
{
MutexLocker lock3(d->propsLock);
Any any = d->properties[ServiceConstants::SERVICE_RANKING()];
if (any.Type() == typeid(int)) old_rank = any_cast<int>(any);
d->module->coreCtx->listeners.GetMatchingServiceListeners(d->reference, before, false);
classes = ref_any_cast<std::list<std::string> >(d->properties[ServiceConstants::OBJECTCLASS()]);
long int sid = any_cast<long int>(d->properties[ServiceConstants::SERVICE_ID()]);
d->properties = ServiceRegistry::CreateServiceProperties(props, classes, sid);
any = d->properties[ServiceConstants::SERVICE_RANKING()];
if (any.Type() == typeid(int)) new_rank = any_cast<int>(any);
}
if (old_rank != new_rank)
{
d->module->coreCtx->services.UpdateServiceRegistrationOrder(*this, classes);
}
}
else
{
throw std::logic_error("Service is unregistered");
}
}
ServiceListeners::ServiceListenerEntries matchingListeners;
d->module->coreCtx->listeners.GetMatchingServiceListeners(d->reference, matchingListeners);
d->module->coreCtx->listeners.ServiceChanged(matchingListeners,
ServiceEvent(ServiceEvent::MODIFIED, d->reference),
before);
d->module->coreCtx->listeners.ServiceChanged(before,
ServiceEvent(ServiceEvent::MODIFIED_ENDMATCH, d->reference));
}
示例2: Compare
bool LDAPExpr::Compare( const Any& obj, int op, const std::string& s ) const
{
if (obj.Empty())
return false;
if (op == EQ && s == WILDCARD_STRING)
return true;
try
{
const std::type_info& objType = obj.Type();
if (objType == typeid(std::string))
{
return CompareString(ref_any_cast<std::string>(obj), op, s);
}
else if (objType == typeid(std::vector<std::string>))
{
const std::vector<std::string>& list = ref_any_cast<std::vector<std::string> >(obj);
for (std::size_t it = 0; it != list.size(); it++)
{
if (CompareString(list[it], op, s))
return true;
}
}
else if (objType == typeid(std::list<std::string>))
{
const std::list<std::string>& list = ref_any_cast<std::list<std::string> >(obj);
for (std::list<std::string>::const_iterator it = list.begin();
it != list.end(); ++it)
{
if (CompareString(*it, op, s))
return true;
}
}
else if (objType == typeid(char))
{
return CompareString(std::string(1, ref_any_cast<char>(obj)), op, s);
}
else if (objType == typeid(bool))
{
if (op==LE || op==GE)
return false;
std::string boolVal = any_cast<bool>(obj) ? "true" : "false";
return std::equal(s.begin(), s.end(), boolVal.begin(), stricomp);
}
else if (objType == typeid(Byte) || objType == typeid(int))
{
int sInt;
std::stringstream ss(s);
ss >> sInt;
int intVal = any_cast<int>(obj);
switch(op)
{
case LE:
return intVal <= sInt;
case GE:
return intVal >= sInt;
default: /*APPROX and EQ*/
return intVal == sInt;
}
}
else if (objType == typeid(float))
{
float sFloat;
std::stringstream ss(s);
ss >> sFloat;
float floatVal = any_cast<float>(obj);
switch(op)
{
case LE:
return floatVal <= sFloat;
case GE:
return floatVal >= sFloat;
default: /*APPROX and EQ*/
float diff = floatVal - sFloat;
return (diff < std::numeric_limits<float>::epsilon()) && (diff > -std::numeric_limits<float>::epsilon());
}
}
示例3: Compare
bool LDAPExpr::Compare( const Any& obj, int op, const std::string& s ) const
{
if (obj.Empty())
return false;
if (op == EQ && s == WILDCARD_STRING)
return true;
try
{
const std::type_info& objType = obj.Type();
if (objType == typeid(std::string))
{
return CompareString(ref_any_cast<std::string>(obj), op, s);
}
else if (objType == typeid(std::vector<std::string>))
{
const std::vector<std::string>& list = ref_any_cast<std::vector<std::string> >(obj);
for (std::size_t it = 0; it != list.size(); it++)
{
if (CompareString(list[it], op, s))
return true;
}
}
else if (objType == typeid(std::list<std::string>))
{
const std::list<std::string>& list = ref_any_cast<std::list<std::string> >(obj);
for (std::list<std::string>::const_iterator it = list.begin();
it != list.end(); ++it)
{
if (CompareString(*it, op, s))
return true;
}
}
else if (objType == typeid(char))
{
return CompareString(std::string(1, ref_any_cast<char>(obj)), op, s);
}
else if (objType == typeid(bool))
{
if (op==LE || op==GE)
return false;
std::string boolVal = any_cast<bool>(obj) ? "true" : "false";
return std::equal(s.begin(), s.end(), boolVal.begin(), stricomp);
}
else if (objType == typeid(short))
{
return CompareIntegralType<short>(obj, op, s);
}
else if (objType == typeid(int))
{
return CompareIntegralType<int>(obj, op, s);
}
else if (objType == typeid(long int))
{
return CompareIntegralType<long int>(obj, op, s);
}
else if (objType == typeid(long long int))
{
return CompareIntegralType<long long int>(obj, op, s);
}
else if (objType == typeid(unsigned char))
{
return CompareIntegralType<unsigned char>(obj, op, s);
}
else if (objType == typeid(unsigned short))
{
return CompareIntegralType<unsigned short>(obj, op, s);
}
else if (objType == typeid(unsigned int))
{
return CompareIntegralType<unsigned int>(obj, op, s);
}
else if (objType == typeid(unsigned long int))
{
return CompareIntegralType<unsigned long int>(obj, op, s);
}
else if (objType == typeid(unsigned long long int))
{
return CompareIntegralType<unsigned long long int>(obj, op, s);
}
else if (objType == typeid(float))
{
errno = 0;
char* endptr = 0;
double sFloat = strtod(s.c_str(), &endptr);
if ((errno == ERANGE && (sFloat == 0 || sFloat == HUGE_VAL || sFloat == -HUGE_VAL)) ||
(errno != 0 && sFloat == 0) || endptr == s.c_str())
{
return false;
}
double floatVal = static_cast<double>(any_cast<float>(obj));
switch(op)
{
case LE:
return floatVal <= sFloat;
case GE:
return floatVal >= sFloat;
//.........这里部分代码省略.........
示例4: manifestRes
ModulePrivate::ModulePrivate(Module* qq, CoreModuleContext* coreCtx,
ModuleInfo* info)
: coreCtx(coreCtx)
, info(*info)
, resourceContainer(info)
, moduleContext(0)
, moduleActivator(0)
, q(qq)
{
// Check if the module provides a manifest.json file and if yes, parse it.
if (resourceContainer.IsValid())
{
ModuleResource manifestRes("/manifest.json", resourceContainer);
if (manifestRes)
{
ModuleResourceStream manifestStream(manifestRes);
try
{
moduleManifest.Parse(manifestStream);
}
catch (const std::exception& e)
{
US_ERROR << "Parsing of manifest.json for module " << info->location << " failed: " << e.what();
}
}
}
// Check if we got version information and validate the version identifier
if (moduleManifest.Contains(Module::PROP_VERSION()))
{
Any versionAny = moduleManifest.GetValue(Module::PROP_VERSION());
std::string errMsg;
if (versionAny.Type() != typeid(std::string))
{
errMsg = std::string("The version identifier must be a string");
}
try
{
version = ModuleVersion(versionAny.ToString());
}
catch (const std::exception& e)
{
errMsg = std::string("The version identifier is invalid: ") + e.what();
}
if (!errMsg.empty())
{
throw std::invalid_argument(std::string("The Json value for ") + Module::PROP_VERSION() + " for module " +
info->location + " is not valid: " + errMsg);
}
}
std::stringstream propId;
propId << this->info.id;
moduleManifest.SetValue(Module::PROP_ID(), propId.str());
moduleManifest.SetValue(Module::PROP_LOCATION(), this->info.location);
moduleManifest.SetValue(Module::PROP_NAME(), this->info.name);
if (moduleManifest.Contains(Module::PROP_AUTOLOAD_DIR()))
{
this->info.autoLoadDir = moduleManifest.GetValue(Module::PROP_AUTOLOAD_DIR()).ToString();
}
else
{
this->info.autoLoadDir = this->info.name;
moduleManifest.SetValue(Module::PROP_AUTOLOAD_DIR(), Any(this->info.autoLoadDir));
}
}