本文整理汇总了C++中json::value::iterator类的典型用法代码示例。如果您正苦于以下问题:C++ iterator类的具体用法?C++ iterator怎么用?C++ iterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了iterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadJsonSheet
void Furnitures::loadJsonSheet(const std::string& jsonSheetPath, const double zoomX, const double zoomY)
{
Json::Reader jsonReader;
Json::Value jsonRoot;
ifstream jsonFile;
jsonFile.open(jsonSheetPath.c_str(), ios::binary);
if (jsonFile.is_open())
{
if (jsonReader.parse(jsonFile, jsonRoot))
{
for(Json::Value::iterator it = jsonRoot.begin(); it != jsonRoot.end(); it++)
{
SDL_Rect rect;
rect = {(*it)["x"].asInt(), (*it)["y"].asInt(), (*it)["w"].asInt(), (*it)["h"].asInt()};
if (zoomX != 1 && zoomY != 1)
{
rect.x *= zoomX;
rect.y *= zoomY;
rect.w *= zoomX;
rect.h *= zoomY;
}
furnituresPixelDimensions.insert(make_pair(it.key().asString(), rect));
}
}
}
else
{
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_ERROR,
"Error reading Json SpriteSheet file in : %s because:", jsonSheetPath.c_str(), strerror( errno ));
throw error::READ_SPRITESHEETS_JSON_FAIL;
}
}
示例2: load_config
int load_config(const char *cfg_root)
{
Json::Value root;
if (this->load_json_cfg(cfg_root, TIANFU_SKILL_UPGRADE_CFG_PATH, root) != 0)
return -1;
for(Json::Value::iterator iter = root.begin();
iter != root.end();
++iter)
{
int lvl = ::atoi(iter.key().asCString());
if (lvl > global_param_cfg::tianfu_lvl_limit)
return -1;
tianfu_skill_upgrade_cfg_obj *p = new tianfu_skill_upgrade_cfg_obj();
this->upgrade_cfg_obj_map_.insert(lvl, p);
p->cost_ = (*iter)["cost"].asInt();
p->exp_ = (*iter)["exp"].asInt();
p->item_cid_ = (*iter)["item_cid"].asInt();
p->item_cnt_ = (*iter)["item_cnt"].asInt();
p->item_exp_ = (*iter)["item_exp"].asInt();
}
return 0;
}
示例3: load_activity_data
int gameplay_ctrl_db_proc::load_activity_data()
{
ctrl_data::instance()->map_act_.clear();
Json::Value root;
Game_Data::Container_Mgr::instance()->get_json_value_by_file_name( root, ACTIVITY_CFG_FILE);
for (Json::Value::iterator p = root.begin();
p != root.end();
p++)
{
//load each activity
std::string s_act_id = p.key().asCString();
activity *act = new activity;
act->id_ = atoi(s_act_id.c_str());
if (load_act_item(act,root[s_act_id]) == 0)
gameplay_ctrl_data_mgr::load_act_item(act);
}
cout << "\n load activity data over----------------" << endl;
return 0;
}
示例4: load_json
int load_json(Json::Value &root, skill_cfg_obj *sco, const int skill_cid)
{
sco->skill_cid_ = skill_cid;
sco->career_ = root["career"].asInt();
sco->hurt_delay_ = root["hurt_delay"].asInt();
Json::Value &detail_v = root["info"];
if (detail_v.empty()) return -1;
for (Json::Value::iterator iter = detail_v.begin();
iter != detail_v.end();
++iter)
{
int i = ::atoi(iter.key().asCString());
Json::Value &dv = *iter;
if (!dv.empty())
{
if (i < 1 || i >= MAX_SKILL_LEVEL)
{
e_log->error("skill lvl is invalid! lvl = %d", i);
return -1;
}
skill_detail *sd = new skill_detail();
sd->cur_lvl_ = i;
sco->details_[i] = sd;
if (this->load_json(dv, sd) != 0)
return -1;
}
}
if (sco->get_detail(1) == NULL)
{
e_log->error("skill %d not found lvl 1 info!", skill_cid);
return -1;
}
return 0;
}
示例5: GetLights
bool CPhilipsHue::GetLights(const Json::Value &root)
{
if (root["lights"].empty())
return false;
for (Json::Value::iterator iLight = root["lights"].begin(); iLight != root["lights"].end(); ++iLight)
{
Json::Value light = *iLight;
if (light.isObject())
{
std::string szLID = iLight.key().asString();
int lID = atoi(szLID.c_str());
_tHueLight tlight;
int BrightnessLevel = 0;
tlight.level = 0;
tlight.sat = 0;
tlight.hue = 0;
int tbri = 0;
bool bIsOn = light["state"]["on"].asBool();
bool bDoSend = true;
_eHueLightType LType = HLTYPE_NORMAL;
if (bIsOn)
{
tlight.cmd = light2_sOn;
}
else
tlight.cmd = light2_sOff;
if (!light["state"]["bri"].empty())
{
//Lamp with brightness control
LType = HLTYPE_DIM;
tbri = light["state"]["bri"].asInt();
if ((tbri != 0) && (tbri != 255))
tbri += 1; //hue reports 255 as 254
tlight.level = tbri;
BrightnessLevel = int((100.0f / 255.0f)*float(tbri));
if (bIsOn)
{
tlight.cmd = (BrightnessLevel != 0) ? light2_sSetLevel : light2_sOn;
}
else
tlight.cmd = light2_sOff;
}
if ((!light["state"]["sat"].empty()) && (!light["state"]["hue"].empty()))
{
//Lamp with hue/sat control
LType = HLTYPE_RGBW;
tlight.sat = light["state"]["sat"].asInt();
tlight.hue = light["state"]["hue"].asInt();
if (bIsOn)
{
tlight.cmd = (BrightnessLevel != 0) ? Limitless_SetBrightnessLevel : Limitless_LedOn;
}
else
tlight.cmd = Limitless_LedOff;
}
if (m_lights.find(lID) != m_lights.end())
{
_tHueLight alight = m_lights[lID];
if (
(alight.cmd == tlight.cmd) &&
(alight.level == tlight.level) &&
(alight.sat == tlight.sat) &&
(alight.hue == tlight.hue)
)
{
bDoSend = false;
}
}
m_lights[lID] = tlight;
if (bDoSend)
{
InsertUpdateSwitch(lID, LType, bIsOn, BrightnessLevel, tlight.sat, tlight.hue, light["name"].asString(), "");
}
}
}
return true;
}
示例6: Load
bool Resource::Load()
{
if (m_loaded)
return true;
Json::Reader reader;
Json::Value data;
std::string filename = "lang/" + m_name + "/" + m_langCode + ".json";
RefCountedPtr<FileSystem::FileData> fd = FileSystem::gameDataFiles.ReadFile(filename);
if (!fd) {
Output("couldn't open language file '%s'\n", filename.c_str());
return false;
}
if (!reader.parse(fd->GetData(), fd->GetData()+fd->GetSize(), data)) {
Output("couldn't read language file '%s': %s\n", filename.c_str(), reader.getFormattedErrorMessages().c_str());
return false;
}
fd.Reset();
for (Json::Value::iterator i = data.begin(); i != data.end(); ++i) {
const std::string token(i.key().asString());
if (token.empty()) {
Output("%s: found empty token, skipping it\n", filename.c_str());
continue;
}
if (!valid_token(token)) {
Output("%s: invalid token '%s', skipping it\n", filename.c_str(), token.c_str());
continue;
}
Json::Value message((*i).get("message", Json::nullValue));
if (message.isNull()) {
Output("%s: no 'message' key for token '%s', skipping it\n", filename.c_str(), token.c_str());
continue;
}
if (!message.isString()) {
Output("%s: value for token '%s' is not a string, skipping it\n", filename.c_str(), token.c_str());
continue;
}
std::string text(message.asString());
if (text.empty()) {
Output("%s: empty value for token '%s', skipping it\n", filename.c_str(), token.c_str());
continue;
}
// extracted quoted string
if (text[0] == '"' && text[text.size()-1] == '"')
text = text.substr(1, text.size()-2);
// adjust for escaped newlines
{
std::string adjustedText;
adjustedText.reserve(text.size());
unsigned int ii;
for (ii = 0; ii < text.size()-1; ii++) {
const char *c = &text[ii];
if (c[0] == '\\' && c[1] == 'n') {
ii++;
adjustedText += '\n';
}
else
adjustedText += *c;
}
if (ii != text.size())
adjustedText += text[ii++];
assert(ii == text.size());
text = adjustedText;
}
m_strings[token] = text;
}
m_loaded = true;
return true;
}
示例7: each
void ConfigManager::each( std::function< void( std::string, Json::Value& ) > func ) {
for( Json::Value::iterator jsonIterator = configRoot.begin(); jsonIterator != configRoot.end(); ++jsonIterator ) {
func( jsonIterator.key().asString(), *jsonIterator );
}
}
示例8: if
ShipType::ShipType(const Id &_id, const std::string &path)
{
Json::Reader reader;
Json::Value data;
auto fd = FileSystem::gameDataFiles.ReadFile(path);
if (!fd) {
Output("couldn't open ship def '%s'\n", path.c_str());
return;
}
if (!reader.parse(fd->GetData(), fd->GetData()+fd->GetSize(), data)) {
Output("couldn't read ship def '%s': %s\n", path.c_str(), reader.getFormattedErrorMessages().c_str());
return;
}
// determine what kind (tag) of ship this is.
const std::string tagStr = data.get("tag", "").asString();
if( tagStr.empty() || strcasecmp(tagStr.c_str(), "ship")==0 ) {
tag = TAG_SHIP;
} else if( strcasecmp(tagStr.c_str(), "static")==0 ) {
tag = TAG_STATIC_SHIP;
} else if( strcasecmp(tagStr.c_str(), "missile")==0 ) {
tag = TAG_MISSILE;
}
id = _id;
name = data.get("name", "").asString();
shipClass = data.get("ship_class", "").asString();
manufacturer = data.get("manufacturer", "").asString();
modelName = data.get("model", "").asString();
cockpitName = data.get("cockpit", "").asString();
linThrust[THRUSTER_REVERSE] = data.get("reverse_thrust", 0.0f).asFloat();
linThrust[THRUSTER_FORWARD] = data.get("forward_thrust", 0.0f).asFloat();
linThrust[THRUSTER_UP] = data.get("up_thrust", 0.0f).asFloat();
linThrust[THRUSTER_DOWN] = data.get("down_thrust", 0.0f).asFloat();
linThrust[THRUSTER_LEFT] = data.get("left_thrust", 0.0f).asFloat();
linThrust[THRUSTER_RIGHT] = data.get("right_thrust", 0.0f).asFloat();
angThrust = data.get("angular_thrust", 0.0f).asFloat();
// invert values where necessary
linThrust[THRUSTER_FORWARD] *= -1.f;
linThrust[THRUSTER_LEFT] *= -1.f;
linThrust[THRUSTER_DOWN] *= -1.f;
// angthrust fudge (XXX: why?)
angThrust = angThrust * 0.5f;
hullMass = data.get("hull_mass", 100).asInt();
capacity = data.get("capacity", 0).asInt();
fuelTankMass = data.get("fuel_tank_mass", 5).asInt();
for( Json::Value::iterator slot = data["slots"].begin() ; slot != data["slots"].end() ; ++slot ) {
const std::string slotname = slot.key().asString();
slots[slotname] = data["slots"].get(slotname, 0).asInt();
}
{
const auto it = slots.find("engine");
if (it != slots.end())
{
it->second = Clamp(it->second, 0, 1);
}
}
effectiveExhaustVelocity = data.get("effective_exhaust_velocity", -1.0f).asFloat();
const float thruster_fuel_use = data.get("thruster_fuel_use", -1.0f).asFloat();
if(effectiveExhaustVelocity < 0 && thruster_fuel_use < 0) {
// default value of v_c is used
effectiveExhaustVelocity = 55000000;
} else if(effectiveExhaustVelocity < 0 && thruster_fuel_use >= 0) {
// v_c undefined and thruster fuel use defined -- use it!
effectiveExhaustVelocity = GetEffectiveExhaustVelocity(fuelTankMass, thruster_fuel_use, linThrust[ShipType::THRUSTER_FORWARD]);
} else {
if(thruster_fuel_use >= 0) {
Output("Warning: Both thruster_fuel_use and effective_exhaust_velocity defined for %s, using effective_exhaust_velocity.\n", modelName.c_str());
}
}
baseprice = data.get("price", 0.0).asDouble();
minCrew = data.get("min_crew", 1).asInt();
maxCrew = data.get("max_crew", 1).asInt();
hyperdriveClass = data.get("hyperdrive_class", 1).asInt();
}
示例9: GetMeterDetails
void CNest::GetMeterDetails()
{
std::string sResult;
#ifdef DEBUG_NextThermostatR
sResult = ReadFile("E:\\nest.json");
#else
if (m_UserName.size()==0)
return;
if (m_Password.size()==0)
return;
if (m_bDoLogin)
{
if (!Login())
return;
}
std::vector<std::string> ExtraHeaders;
ExtraHeaders.push_back("user-agent:Nest/1.1.0.10 CFNetwork/548.0.4");
ExtraHeaders.push_back("Authorization:Basic " + m_AccessToken);
ExtraHeaders.push_back("X-nl-user-id:" + m_UserID);
ExtraHeaders.push_back("X-nl-protocol-version:1");
//Get Data
std::string sURL = m_TransportURL + NEST_GET_STATUS + m_UserID;
if (!HTTPClient::GET(sURL, ExtraHeaders, sResult))
{
_log.Log(LOG_ERROR, "Nest: Error getting current state!");
m_bDoLogin = true;
return;
}
#endif
#ifdef DEBUG_NextThermostatW
SaveString2Disk(sResult, "E:\\nest.json");
#endif
Json::Value root;
Json::Reader jReader;
if (!jReader.parse(sResult, root))
{
_log.Log(LOG_ERROR, "Nest: Invalid data received!");
m_bDoLogin = true;
return;
}
bool bHaveShared = !root["shared"].empty();
bool bHaveTopaz = !root["topaz"].empty();
if ((!bHaveShared) && (!bHaveTopaz))
{
_log.Log(LOG_ERROR, "Nest: request not successful, restarting..!");
m_bDoLogin = true;
return;
}
//Protect
if (bHaveTopaz)
{
if (root["topaz"].size() < 1)
{
_log.Log(LOG_ERROR, "Nest: request not successful, restarting..!");
m_bDoLogin = true;
return;
}
Json::Value::Members members = root["topaz"].getMemberNames();
if (members.size() < 1)
{
_log.Log(LOG_ERROR, "Nest: request not successful, restarting..!");
m_bDoLogin = true;
return;
}
int SwitchIndex = 1;
for (Json::Value::iterator itDevice = root["topaz"].begin(); itDevice != root["topaz"].end(); ++itDevice)
{
Json::Value device = *itDevice;
std::string devstring = itDevice.key().asString();
if (device["where_id"].empty())
continue;
std::string whereid = device["where_id"].asString();
//lookup name
std::string devName = devstring;
if (!root["where"].empty())
{
for (Json::Value::iterator itWhere = root["where"].begin(); itWhere != root["where"].end(); ++itWhere)
{
Json::Value iwhere = *itWhere;
if (!iwhere["wheres"].empty())
{
for (Json::Value::iterator itWhereNest = iwhere["wheres"].begin(); itWhereNest != iwhere["wheres"].end(); ++itWhereNest)
{
Json::Value iwhereItt = *itWhereNest;
if (!iwhereItt["where_id"].empty())
{
std::string tmpWhereid = iwhereItt["where_id"].asString();
if (tmpWhereid == whereid)
{
devName = iwhereItt["name"].asString();
break;
}
}
//.........这里部分代码省略.........
示例10: load_config
int load_config(const char *cfg_root)
{
Json::Value root;
if (this->load_json_cfg(cfg_root, KAI_FU_ACT_CFG_PATH, root) != 0)
return -1;
for (Json::Value::iterator iter = root.begin();
iter != root.end();
++iter)
{
int act_id = ::atoi(iter.key().asCString());
ilist<kai_fu_act_cfg_obj *> *pl = new ilist<kai_fu_act_cfg_obj *>();
this->kai_fu_act_cfg_map_.insert(std::make_pair(act_id, pl));
Json::Value &sub_v = *iter;
for (Json::Value::iterator sub_iter = sub_v.begin();
sub_iter != sub_v.end();
++sub_iter)
{
kai_fu_act_cfg_obj *p = new kai_fu_act_cfg_obj();
pl->push_back(p);
p->param_ = (*sub_iter)["param"].asInt();
p->open_ = (*sub_iter)["open"].asBool();
{
Json::Value &award_v = (*sub_iter)["award"];
if (award_v.empty()) continue;
char *tok_p = NULL;
char *token = NULL;
char bf[256] = {0};
::strncpy(bf, award_v.asCString(), sizeof(bf) - 1);
for (token = ::strtok_r(bf, ";", &tok_p);
token != NULL;
token = ::strtok_r(NULL, ";", &tok_p))
{
item_amount_bind_t item;
int bind = 0;
::sscanf(token, "%d,%d,%d", &item.cid_, &item.amount_, &bind);
item.bind_ = bind;
p->award_list_.push_back(item);
if (!item_config::instance()->find(item.cid_))
return -1;
}
}
{
Json::Value &award_v = (*sub_iter)["award_2"];
if (award_v.empty()) continue;
char *tok_p = NULL;
char *token = NULL;
char bf[256] = {0};
::strncpy(bf, award_v.asCString(), sizeof(bf) - 1);
for (token = ::strtok_r(bf, ";", &tok_p);
token != NULL;
token = ::strtok_r(NULL, ";", &tok_p))
{
item_amount_bind_t item;
int bind = 0;
::sscanf(token, "%d,%d,%d", &item.cid_, &item.amount_, &bind);
item.bind_ = bind;
p->award_list_2_.push_back(item);
if (!item_config::instance()->find(item.cid_))
return -1;
}
}
}
}
return 0;
}
示例11: loadResources
void Game::loadResources() {
Log::Out << "Game: Loading resources..." << endl;
istream* resourcesFile = Pack::GetInstance()->GetStream("resources.json");
if (!resourcesFile->good()) {
Log::Out << "Couldn't load file resources.json" << endl;
return;
}
Json::Value root;
(*resourcesFile) >> root;
delete resourcesFile;
Log::Out << "Game: Initializing Scanlines..." << endl;
Json::Value shaders = root["outputShaders"];
if (Json::Value::null != shaders) {
ShaderMgr* shaderMgr = ShaderMgr::GetInstance();
for (Json::Value::iterator itShaderDesc = shaders.begin(); itShaderDesc != shaders.end(); ++itShaderDesc) {
vector<Shader*> shaderPtrs;
Json::Value child = *itShaderDesc;
string name = child["name"].asString();
Json::Value pathArray = child["shaderPaths"];
for (Json::Value::iterator itShaderPath = pathArray.begin(); itShaderPath != pathArray.end(); ++itShaderPath) {
string shaderFile = itShaderPath->asString();
ShaderType shaderType = shaderFile.find(".vertex") == string::npos ? Fragment : Vertex;
stringstream ss;
ss << "Loading " << ((shaderType == Vertex) ? "vertex" : "fragment") << " shader: " << shaderFile;
drawStatusMsg(ss.str());
shaderPtrs.push_back(shaderMgr->LoadShader(shaderFile, shaderType));
}
Program* p = new Program(shaderPtrs);
if (p->ProgramId != 0) {
p->Textures.push_back(_g->GetFramebufferTexture());
}
Json::Value texArray = child["additionalTextures"];
for (Json::Value::iterator itTexturePath = texArray.begin(); itTexturePath != texArray.end(); ++itTexturePath) {
string texPath = itTexturePath->asString();
p->Textures.push_back(Frame(texPath).Texture);
}
this->_blitProgramMap[name] = p;
if (child.isMember("default") && child["default"].asBool()) {
this->_blitProgram = p;
}
}
if (this->_blitProgram == NULL && this->_blitProgramMap.size() > 0) {
this->_blitProgram = (this->_blitProgramMap.end())->second;
}
}
Json::Value images = root["images"];
if (Json::Value::null != images) {
TextureMgr* texMgr = TextureMgr::GetInstance();
for (Json::Value::iterator img = images.begin(); img != images.end(); ++img) {
string file = img->asString();
stringstream ss;
ss << "Loading image: " << file;
drawStatusMsg(ss.str());
texMgr->LoadTexture(file);
}
}
Json::Value music = root["music"];
if (Json::Value::null != music) {
MusicManager* musicMgr = MusicManager::GetInstance();
for (Json::Value::iterator mus = music.begin(); mus != music.end(); ++mus) {
string file = mus->asString();
stringstream ss;
ss << "Loading song " << file;
drawStatusMsg(ss.str());
musicMgr->LoadMusic(mus->asString());
}
}
Json::Value effects = root["fx"];
if (Json::Value::null != effects) {
MusicManager* musicMgr = MusicManager::GetInstance();
for (Json::Value::iterator fx = effects.begin(); fx != effects.end(); ++fx) {
stringstream ss;
string file = fx->asString();
ss << "Loading effect " << file;
drawStatusMsg(ss.str());
musicMgr->LoadMusic(fx->asString());
}
}
drawStatusMsg("Done!");
}
示例12: parse
void Myself::parse(const std::string& body) throw(ParseJsonError)
{
User::parse(body);
Json::Value root;
Json::Reader reader;
if(!reader.parse(body,root)) throw ParseJsonError(reader.getFormattedErrorMessages().c_str());
for (Json::Value::iterator it = root.begin(); it != root.end(); ++it)
{
if(it.key().asString() == "total_private_repos")
{
_totalPrivateRepos = root.get(it.key().asString(), 0).asInt();
} else
if(it.key().asString() == "owned_private_repos")
{
_ownedPrivateRepos = root.get(it.key().asString(), 0).asInt();
} else
if(it.key().asString() == "private_gists")
{
_privateGists = root.get(it.key().asString(), 0).asInt();
} else
if(it.key().asString() == "disk_usage")
{
_diskUsage = root.get(it.key().asString(), 0).asInt();
} else
if(it.key().asString() == "collaborators")
{
_collaborators = root.get(it.key().asString(), 0).asInt();
} else
if(it.key().asString() == "plan")
{
_plan.name = root.get(it.key().asString(), 0).get("name",0).asString();
_plan.space = root.get(it.key().asString(), 0).get("space",0).asInt();
_plan.privateRepos = root.get(it.key().asString(), 0).get("private_repos",0).asInt();
_plan.collaborators = root.get(it.key().asString(), 0).get("collaborators",0).asInt();
}
}
}
示例13: GetLights
bool CPhilipsHue::GetLights(const Json::Value &root)
{
if (root["lights"].empty())
return false;
for (Json::Value::iterator iLight = root["lights"].begin(); iLight != root["lights"].end(); ++iLight)
{
Json::Value light = *iLight;
if (light.isObject())
{
std::string szLID = iLight.key().asString();
int lID = atoi(szLID.c_str());
std::string ltype = light["type"].asString();
if (
(ltype == "Dimmable plug-in unit") ||
(ltype == "Dimmable light") ||
(ltype == "Color temperature light")
)
{
//Normal light (with dim option)
bool bIsOn = light["state"]["on"].asBool();
int tbri = light["state"]["bri"].asInt();
if ((tbri != 0) && (tbri != 255))
tbri += 1; //hue reports 255 as 254
int BrightnessLevel = int((100.0f / 255.0f)*float(tbri));
_tHueLight tlight;
if (bIsOn)
{
tlight.cmd = (BrightnessLevel != 0) ? light2_sSetLevel : light2_sOn;
}
else
tlight.cmd = light2_sOff;
tlight.level = BrightnessLevel;
tlight.sat = 0;
tlight.hue = 0;
bool bDoSend = true;
if (m_lights.find(lID) != m_lights.end())
{
_tHueLight alight = m_lights[lID];
if (
(alight.cmd == tlight.cmd) &&
(alight.level == tlight.level)
)
{
bDoSend = false;
}
}
m_lights[lID] = tlight;
if (bDoSend)
InsertUpdateSwitch(lID, HLTYPE_DIM, bIsOn, BrightnessLevel, 0, 0, light["name"].asString(), "");
}
else if (
(ltype == "Extended color light") ||
(ltype == "Color light")
)
{
//RGBW type
bool bIsOn = light["state"]["on"].asBool();
int tbri = light["state"]["bri"].asInt();
int tsat = light["state"]["sat"].asInt();
int thue = light["state"]["hue"].asInt();
if ((tbri != 0) && (tbri != 255))
tbri += 1; //hue reports 255 as 254
int BrightnessLevel = int((100.0f / 255.0f)*float(tbri));
_tHueLight tlight;
if (bIsOn)
{
tlight.cmd = (BrightnessLevel != 0) ? Limitless_SetBrightnessLevel : Limitless_LedOn;
}
else
tlight.cmd = Limitless_LedOff;
tlight.level = BrightnessLevel;
tlight.sat = tsat;
tlight.hue = thue;
bool bDoSend = true;
if (m_lights.find(lID) != m_lights.end())
{
_tHueLight alight = m_lights[lID];
if (
(alight.cmd == tlight.cmd) &&
(alight.level == tlight.level) &&
(alight.sat == tlight.sat) &&
(alight.hue == tlight.hue)
)
{
bDoSend = false;
}
}
m_lights[lID] = tlight;
if (bDoSend)
{
InsertUpdateSwitch(lID, HLTYPE_RGBW, bIsOn, BrightnessLevel, tsat, thue, light["name"].asString(), "");
}
}
}
}
return true;
}
示例14: GetScenes
bool CPhilipsHue::GetScenes(const Json::Value &root)
{
if (root["scenes"].empty())
return false;
for (Json::Value::iterator iScene = root["scenes"].begin(); iScene != root["scenes"].end(); ++iScene)
{
Json::Value scene = *iScene;
if (scene.isObject())
{
_tHueScene hscene;
hscene.id = iScene.key().asString();;
hscene.name = scene["name"].asString();
hscene.lastupdated = scene["lastupdated"].asString();
if (hscene.lastupdated.empty())
continue; //old scene/legacy scene
//Strip some info
size_t tpos = hscene.name.find(" from ");
if (tpos != std::string::npos)
{
hscene.name = hscene.name.substr(0, tpos);
}
bool bDoSend = true;
if (m_scenes.find(hscene.id) != m_scenes.end())
{
_tHueScene ascene = m_scenes[hscene.id];
if (ascene.lastupdated == hscene.lastupdated)
{
bDoSend = false;
}
}
m_scenes[hscene.id] = hscene;
if (bDoSend)
{
int sID = -1;
std::vector<std::vector<std::string> > result;
result = m_sql.safe_query("SELECT ID FROM WOLNodes WHERE (HardwareID==%d) AND (MacAddress=='%q')", m_HwdID, hscene.id.c_str());
if (!result.empty())
{
//existing scene
sID = atoi(result[0][0].c_str());
}
else
{
//New scene
m_sql.safe_query("INSERT INTO WOLNodes (HardwareID, Name, MacAddress) VALUES (%d, '%q', '%q')", m_HwdID, hscene.name.c_str(), hscene.id.c_str());
result = m_sql.safe_query("SELECT ID FROM WOLNodes WHERE (HardwareID==%d) AND (MacAddress=='%q')", m_HwdID, hscene.id.c_str());
if (result.empty())
{
_log.Log(LOG_ERROR, "Philips Hue: Problem adding new Scene!!");
return false;
}
sID = atoi(result[0][0].c_str());
}
std::string Name = "Scene " + hscene.name;
InsertUpdateSwitch(2000 + sID, HLTYPE_SCENE, false, 100, 0, 0, Name, hscene.id);
}
}
}
return true;
}
示例15: GetGroups
bool CPhilipsHue::GetGroups(const Json::Value &root)
{
//Groups (0=All)
if (root["groups"].empty())
return false;
for (Json::Value::iterator iGroup = root["groups"].begin(); iGroup != root["groups"].end(); ++iGroup)
{
Json::Value group = *iGroup;
if (group.isObject())
{
std::string szGID = iGroup.key().asString();
int gID = atoi(szGID.c_str());
bool bIsOn = false;
int tbri = 255;
int tsat = 255;
int thue = 255;
if (!group["action"]["on"].empty())
bIsOn = group["action"]["on"].asBool();
if (!group["action"]["bri"].empty())
tbri = group["action"]["bri"].asInt();
if (!group["action"]["sat"].empty())
tsat = group["action"]["sat"].asInt();
if (!group["action"]["hue"].empty())
thue = group["action"]["hue"].asInt();
if ((tbri != 0) && (tbri != 255))
tbri += 1; //hue reports 255 as 254
int BrightnessLevel = int((100.0f / 255.0f)*float(tbri));
_tHueLight tstate;
if (bIsOn)
{
tstate.cmd = (BrightnessLevel != 0) ? Limitless_SetBrightnessLevel : Limitless_LedOn;
}
else
tstate.cmd = Limitless_LedOff;
tstate.level = BrightnessLevel;
tstate.sat = tsat;
tstate.hue = thue;
bool bDoSend = true;
if (m_groups.find(gID) != m_groups.end())
{
_tHueGroup agroup = m_groups[gID];
if (
(agroup.gstate.cmd == tstate.cmd) &&
(agroup.gstate.level == tstate.level) &&
(agroup.gstate.sat == tstate.sat) &&
(agroup.gstate.hue == tstate.hue)
)
{
bDoSend = false;
}
}
m_groups[gID].gstate = tstate;
if (bDoSend)
{
std::string Name = "Group " + group["name"].asString();
InsertUpdateSwitch(1000 + gID, HLTYPE_RGBW, bIsOn, BrightnessLevel, tsat, thue, Name, "");
}
}
}
//Special Request for Group0 (All Lights)
std::stringstream sstr2;
sstr2 << "http://" << m_IPAddress
<< ":" << m_Port
<< "/api/" << m_UserName
<< "/groups/0";
std::string sResult;
std::vector<std::string> ExtraHeaders;
if (!HTTPClient::GET(sstr2.str(), ExtraHeaders, sResult))
{
//No group all(0)
return true;
}
Json::Reader jReader;
Json::Value root2;
bool ret = jReader.parse(sResult, root2);
ret = jReader.parse(sResult, root2);
if (!ret)
{
_log.Log(LOG_ERROR, "Philips Hue: Invalid data received, or invalid IPAddress/Username!");
return false;
}
if (sResult.find("\"error\":") != std::string::npos)
{
//We had an error
_log.Log(LOG_ERROR, "Philips Hue: Error received: %s", root2[0]["error"]["description"].asString().c_str());
return false;
}
if (sResult.find("lights") == std::string::npos)
{
return false;
}
bool bIsOn = false;
int tbri = 255;
int tsat = 255;
int thue = 255;
//.........这里部分代码省略.........