当前位置: 首页>>代码示例>>C++>>正文


C++ value::iterator类代码示例

本文整理汇总了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;
     }
     
 }    
开发者ID:dokoto,项目名称:el-barrio-es-lo-primero-2,代码行数:36,代码来源:Furnitures.cpp

示例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;
  }
开发者ID:chenbk85,项目名称:gserver,代码行数:24,代码来源:tianfu_skill_upgrade_cfg.cpp

示例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; 
}
开发者ID:ff78,项目名称:son,代码行数:24,代码来源:gameplay_ctrl_db_proc.cpp

示例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;
  }
开发者ID:chenbk85,项目名称:gserver,代码行数:36,代码来源:skill_config.cpp

示例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;
}
开发者ID:interxis,项目名称:domoticz,代码行数:80,代码来源:PhilipsHue.cpp

示例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;
}
开发者ID:Action-Committee,项目名称:pioneer,代码行数:81,代码来源:Lang.cpp

示例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 );
   }
 }
开发者ID:ne0ndrag0n,项目名称:BlueBear,代码行数:5,代码来源:configmanager.cpp

示例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();
}
开发者ID:christiank,项目名称:pioneer,代码行数:85,代码来源:ShipType.cpp

示例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;
								}
							}
//.........这里部分代码省略.........
开发者ID:AbsolutK,项目名称:domoticz,代码行数:101,代码来源:Nest.cpp

示例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;
  }
开发者ID:chenbk85,项目名称:gserver,代码行数:67,代码来源:kai_fu_act_cfg.cpp

示例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!");
}
开发者ID:AugustoRuiz,项目名称:UWOL,代码行数:84,代码来源:Game.cpp

示例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();
        }
    }
    
}
开发者ID:Dzhekson6000,项目名称:GitHub-API,代码行数:41,代码来源:Myself.cpp

示例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;
}
开发者ID:maartenbreddels,项目名称:domoticz,代码行数:98,代码来源:PhilipsHue.cpp

示例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;
}
开发者ID:IgorYbema,项目名称:domoticz,代码行数:64,代码来源:PhilipsHue.cpp

示例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;
//.........这里部分代码省略.........
开发者ID:interxis,项目名称:domoticz,代码行数:101,代码来源:PhilipsHue.cpp


注:本文中的json::value::iterator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。