本文整理汇总了C++中CVariant::asBoolean方法的典型用法代码示例。如果您正苦于以下问题:C++ CVariant::asBoolean方法的具体用法?C++ CVariant::asBoolean怎么用?C++ CVariant::asBoolean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CVariant
的用法示例。
在下文中一共展示了CVariant::asBoolean方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Open
JSONRPC_STATUS CPlayerOperations::Open(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
{
CVariant options = parameterObject["options"];
CVariant optionShuffled = options["shuffled"];
CVariant optionRepeat = options["repeat"];
CVariant optionResume = options["resume"];
CVariant optionPlayer = options["playercoreid"];
if (parameterObject["item"].isObject() && parameterObject["item"].isMember("playlistid"))
{
int playlistid = (int)parameterObject["item"]["playlistid"].asInteger();
if (playlistid < PLAYLIST_PICTURE)
{
// Apply the "shuffled" option if available
if (optionShuffled.isBoolean())
g_playlistPlayer.SetShuffle(playlistid, optionShuffled.asBoolean(), false);
// Apply the "repeat" option if available
if (!optionRepeat.isNull())
g_playlistPlayer.SetRepeat(playlistid, (REPEAT_STATE)ParseRepeatState(optionRepeat), false);
}
int playlistStartPosition = (int)parameterObject["item"]["position"].asInteger();
switch (playlistid)
{
case PLAYLIST_MUSIC:
case PLAYLIST_VIDEO:
CApplicationMessenger::Get().MediaPlay(playlistid, playlistStartPosition);
OnPlaylistChanged();
break;
case PLAYLIST_PICTURE:
{
std::string firstPicturePath;
if (playlistStartPosition > 0)
{
CGUIWindowSlideShow *slideshow = (CGUIWindowSlideShow*)g_windowManager.GetWindow(WINDOW_SLIDESHOW);
if (slideshow != NULL)
{
CFileItemList list;
slideshow->GetSlideShowContents(list);
if (playlistStartPosition < list.Size())
firstPicturePath = list.Get(playlistStartPosition)->GetPath();
}
}
return StartSlideshow("", false, optionShuffled.isBoolean() && optionShuffled.asBoolean(), firstPicturePath);
break;
}
}
return ACK;
}
else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("path"))
{
bool random = (optionShuffled.isBoolean() && optionShuffled.asBoolean()) ||
(!optionShuffled.isBoolean() && parameterObject["item"]["random"].asBoolean());
return StartSlideshow(parameterObject["item"]["path"].asString(), parameterObject["item"]["recursive"].asBoolean(), random);
}
else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("partymode"))
{
if (g_partyModeManager.IsEnabled())
g_partyModeManager.Disable();
CApplicationMessenger::Get().ExecBuiltIn("playercontrol(partymode(" + parameterObject["item"]["partymode"].asString() + "))");
return ACK;
}
else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("channelid"))
{
if (!g_PVRManager.IsStarted())
return FailedToExecute;
CPVRChannelGroupsContainer *channelGroupContainer = g_PVRChannelGroups;
if (channelGroupContainer == NULL)
return FailedToExecute;
CPVRChannelPtr channel = channelGroupContainer->GetChannelById((int)parameterObject["item"]["channelid"].asInteger());
if (channel == NULL)
return InvalidParams;
if ((g_PVRManager.IsPlayingRadio() && channel->IsRadio()) ||
(g_PVRManager.IsPlayingTV() && !channel->IsRadio()))
g_application.m_pPlayer->SwitchChannel(channel);
else
CApplicationMessenger::Get().MediaPlay(CFileItem(channel));
return ACK;
}
else if (parameterObject["item"].isObject() && parameterObject["item"].isMember("recordingid"))
{
if (!g_PVRManager.IsStarted())
return FailedToExecute;
CPVRRecordings *recordingsContainer = g_PVRRecordings;
if (recordingsContainer == NULL)
return FailedToExecute;
CFileItemPtr fileItem = recordingsContainer->GetById((int)parameterObject["item"]["recordingid"].asInteger());
if (fileItem == NULL)
return InvalidParams;
//.........这里部分代码省略.........
示例2: GetAddons
JSONRPC_STATUS CAddonsOperations::GetAddons(const std::string &method, ITransportLayer *transport, IClient *client, const CVariant ¶meterObject, CVariant &result)
{
vector<TYPE> addonTypes;
TYPE addonType = TranslateType(parameterObject["type"].asString());
CPluginSource::Content content = CPluginSource::Translate(parameterObject["content"].asString());
CVariant enabled = parameterObject["enabled"];
// ignore the "content" parameter if the type is specified but not a plugin or script
if (addonType != ADDON_UNKNOWN && addonType != ADDON_PLUGIN && addonType != ADDON_SCRIPT)
content = CPluginSource::UNKNOWN;
if (addonType >= ADDON_VIDEO && addonType <= ADDON_EXECUTABLE)
{
addonTypes.push_back(ADDON_PLUGIN);
addonTypes.push_back(ADDON_SCRIPT);
switch (addonType)
{
case ADDON_VIDEO:
content = CPluginSource::VIDEO;
break;
case ADDON_AUDIO:
content = CPluginSource::AUDIO;
break;
case ADDON_IMAGE:
content = CPluginSource::IMAGE;
break;
case ADDON_EXECUTABLE:
content = CPluginSource::EXECUTABLE;
break;
default:
break;
}
}
else
addonTypes.push_back(addonType);
VECADDONS addons;
for (vector<TYPE>::const_iterator typeIt = addonTypes.begin(); typeIt != addonTypes.end(); ++typeIt)
{
VECADDONS typeAddons;
if (*typeIt == ADDON_UNKNOWN)
{
if (!enabled.isBoolean())
{
CAddonMgr::Get().GetAllAddons(typeAddons, false);
CAddonMgr::Get().GetAllAddons(typeAddons, true);
}
else
CAddonMgr::Get().GetAllAddons(typeAddons, enabled.asBoolean());
}
else
{
if (!enabled.isBoolean())
{
CAddonMgr::Get().GetAddons(*typeIt, typeAddons, false);
VECADDONS enabledAddons;
CAddonMgr::Get().GetAddons(*typeIt, enabledAddons, true);
typeAddons.insert(typeAddons.end(), enabledAddons.begin(), enabledAddons.end());
}
else
CAddonMgr::Get().GetAddons(*typeIt, typeAddons, enabled.asBoolean());
}
addons.insert(addons.end(), typeAddons.begin(), typeAddons.end());
}
// remove library addons
for (int index = 0; index < (int)addons.size(); index++)
{
PluginPtr plugin;
if (content != CPluginSource::UNKNOWN)
plugin = boost::dynamic_pointer_cast<CPluginSource>(addons.at(index));
if ((addons.at(index)->Type() <= ADDON_UNKNOWN || addons.at(index)->Type() >= ADDON_MAX) ||
((content != CPluginSource::UNKNOWN && plugin == NULL) || (plugin != NULL && !plugin->Provides(content))))
{
addons.erase(addons.begin() + index);
index--;
}
}
int start, end;
HandleLimits(parameterObject, result, addons.size(), start, end);
CAddonDatabase addondb;
for (int index = start; index < end; index++)
FillDetails(addons.at(index), parameterObject["properties"], result["addons"], addondb, true);
return OK;
}
示例3:
TEST(TestUrlOptions, AddOption)
{
const char *keyChar = "char";
const char *keyString = "string";
const char *keyEmpty = "empty";
const char *keyInt = "int";
const char *keyFloat = "float";
const char *keyDouble = "double";
const char *keyBool = "bool";
const char *valueChar = "valueChar";
const std::string valueString = "valueString";
const char *valueEmpty = "";
int valueInt = 1;
float valueFloat = 1.0f;
double valueDouble = 1.0;
bool valueBool = true;
CVariant variantValue;
CUrlOptions urlOptions;
urlOptions.AddOption(keyChar, valueChar);
{
CVariant variantValue;
EXPECT_TRUE(urlOptions.GetOption(keyChar, variantValue));
EXPECT_TRUE(variantValue.isString());
EXPECT_STREQ(valueChar, variantValue.asString().c_str());
}
urlOptions.AddOption(keyString, valueString);
{
CVariant variantValue;
EXPECT_TRUE(urlOptions.GetOption(keyString, variantValue));
EXPECT_TRUE(variantValue.isString());
EXPECT_STREQ(valueString.c_str(), variantValue.asString().c_str());
}
urlOptions.AddOption(keyEmpty, valueEmpty);
{
CVariant variantValue;
EXPECT_TRUE(urlOptions.GetOption(keyEmpty, variantValue));
EXPECT_TRUE(variantValue.isString());
EXPECT_STREQ(valueEmpty, variantValue.asString().c_str());
}
urlOptions.AddOption(keyInt, valueInt);
{
CVariant variantValue;
EXPECT_TRUE(urlOptions.GetOption(keyInt, variantValue));
EXPECT_TRUE(variantValue.isInteger());
EXPECT_EQ(valueInt, (int)variantValue.asInteger());
}
urlOptions.AddOption(keyFloat, valueFloat);
{
CVariant variantValue;
EXPECT_TRUE(urlOptions.GetOption(keyFloat, variantValue));
EXPECT_TRUE(variantValue.isDouble());
EXPECT_EQ(valueFloat, variantValue.asFloat());
}
urlOptions.AddOption(keyDouble, valueDouble);
{
CVariant variantValue;
EXPECT_TRUE(urlOptions.GetOption(keyDouble, variantValue));
EXPECT_TRUE(variantValue.isDouble());
EXPECT_EQ(valueDouble, variantValue.asDouble());
}
urlOptions.AddOption(keyBool, valueBool);
{
CVariant variantValue;
EXPECT_TRUE(urlOptions.GetOption(keyBool, variantValue));
EXPECT_TRUE(variantValue.isBoolean());
EXPECT_EQ(valueBool, variantValue.asBoolean());
}
}
示例4: InternalWrite
bool CJSONVariantWriter::InternalWrite(yajl_gen g, const CVariant &value)
{
bool success = false;
switch (value.type())
{
case CVariant::VariantTypeInteger:
#if YAJL_MAJOR == 2
success = yajl_gen_status_ok == yajl_gen_integer(g, (long long int)value.asInteger());
#else
success = yajl_gen_status_ok == yajl_gen_integer(g, (long int)value.asInteger());
#endif
break;
case CVariant::VariantTypeUnsignedInteger:
#if YAJL_MAJOR == 2
success = yajl_gen_status_ok == yajl_gen_integer(g, (long long int)value.asUnsignedInteger());
#else
success = yajl_gen_status_ok == yajl_gen_integer(g, (long int)value.asUnsignedInteger());
#endif
break;
case CVariant::VariantTypeDouble:
success = yajl_gen_status_ok == yajl_gen_double(g, value.asDouble());
break;
case CVariant::VariantTypeBoolean:
success = yajl_gen_status_ok == yajl_gen_bool(g, value.asBoolean() ? 1 : 0);
break;
case CVariant::VariantTypeString:
#if YAJL_MAJOR == 2
success = yajl_gen_status_ok == yajl_gen_string(g, (const unsigned char*)value.c_str(), (size_t)value.size());
#else
success = yajl_gen_status_ok == yajl_gen_string(g, (const unsigned char*)value.c_str(), value.size());
#endif
break;
case CVariant::VariantTypeArray:
success = yajl_gen_status_ok == yajl_gen_array_open(g);
for (CVariant::const_iterator_array itr = value.begin_array(); itr != value.end_array() && success; itr++)
success &= InternalWrite(g, *itr);
if (success)
success = yajl_gen_status_ok == yajl_gen_array_close(g);
break;
case CVariant::VariantTypeObject:
success = yajl_gen_status_ok == yajl_gen_map_open(g);
for (CVariant::const_iterator_map itr = value.begin_map(); itr != value.end_map() && success; itr++)
{
#if YAJL_MAJOR == 2
success &= yajl_gen_status_ok == yajl_gen_string(g, (const unsigned char*)itr->first.c_str(), (size_t)itr->first.length());
#else
success &= yajl_gen_status_ok == yajl_gen_string(g, (const unsigned char*)itr->first.c_str(), itr->first.length());
#endif
if (success)
success &= InternalWrite(g, itr->second);
}
if (success)
success &= yajl_gen_status_ok == yajl_gen_map_close(g);
break;
case CVariant::VariantTypeConstNull:
case CVariant::VariantTypeNull:
default:
success = yajl_gen_status_ok == yajl_gen_null(g);
break;
}
return success;
}