Beispiel #1
0
void iterateArray(Value::ConstValueIterator& itr,
		Value::ConstValueIterator& itrEnd, StringBuffer *buffer,
		Writer<StringBuffer> *writer, stringstream& ss) {
	for (; itr != itrEnd; itr++) {
		if (itr->IsObject()) {
			Value::ConstMemberIterator itr_ = itr->MemberBegin();
			Value::ConstMemberIterator itrEnd_ = itr->MemberEnd();
			iterateObject(itr_, itrEnd_, buffer, writer, ss);
		} else if (itr->IsArray()) {
			Value::ConstValueIterator itr_ = itr->Begin();
			Value::ConstValueIterator itrEnd_ = itr->End();
			iterateArray(itr_, itrEnd_, buffer, writer, ss);
		} else if (itr->IsBool()) {
			ss << DELIM << itr->GetBool();
		} else if (itr->IsInt()) {
			ss << DELIM << itr->GetInt();
		} else if (itr->IsInt64()) {
			ss << DELIM << itr->GetInt64();
		} else if (itr->IsDouble()) {
			ss << DELIM << itr->GetDouble();
		} else if (itr->IsString()) {
			ss << DELIM << "\"" << itr->GetString() << "\"";
		} else {
			throw runtime_error(string("Case missing from tokenizer"));
		}
	}
}
void AEPreferences::Read()
{
    rapidjson::Document document;

    String filepath = GetPreferencesFullPath();

    File jsonFile(context_, filepath);

    if (!jsonFile.IsOpen())
        return;

    String json;
    jsonFile.ReadText(json);

    if (!json.Length())
        return;

    if (document.Parse<0>(json.CString()).HasParseError())
    {
        LOGERRORF("Could not parse JSON data from %s", filepath.CString());
        return;
    }

    Clear();

    const Value::Member* recent_files = document.FindMember("recent_files");
    if (recent_files && recent_files->value.IsArray())
    {
        for (Value::ConstValueIterator itr = recent_files->value.Begin(); itr != recent_files->value.End(); itr++)
        {
             if (!(*itr).IsString())
                 continue;

            String path(itr->GetString());
            recentProjects_.Push(path.CString());
        }
    }

    const Value::Member* android_sdk_path = document.FindMember("android_sdk_path");
    if (android_sdk_path && android_sdk_path->value.IsString())
        androidSDKPath_ = android_sdk_path->value.GetString();

    const Value::Member* jdk_root_path = document.FindMember("jdk_root_path");
    if (jdk_root_path && jdk_root_path->value.IsString())
        jdkRootPath_ = jdk_root_path->value.GetString();

    const Value::Member* ant_path = document.FindMember("ant_path");
    if (ant_path && ant_path->value.IsString())
        antPath_ = ant_path->value.GetString();

    UpdateRecentFiles(false);

}
Beispiel #3
0
/*
 * Class:     com_vmc_ipc_proxy_IpcProxy
 * Method:    takeNavDataSnapshot
 * Signature: ()Lcom/vmc/ipc/proxy/NavData;
 */
JNIEXPORT jobjectArray JNICALL Java_com_vmc_ipc_proxy_IpcProxy_takeNavDataSnapshot
  (JNIEnv *env, jobject jobj,jobject navdata){
//	LOGI("-->Java_com_vmc_ipc_proxy_IpcProxy_takeNavDataSnapshot");

	jobjectArray args = 0;
	jstring 	 str;
	std::map<std::string,std::string> &map = cmd::StartServerStatusEnum();
	int i = 0,len = map.size();
	std::map<std::string,std::string>::iterator iter;
	
	args = (env)->NewObjectArray(len,(env)->FindClass("java/lang/String"),0);
#if 0
	for (Value::ConstValueIterator itr = g_serverStatus.Begin(); itr != g_serverStatus.End(); ++itr)
	{
		str = (env)->NewStringUTF(itr->GetString() );
		(env)->SetObjectArrayElement(args, i, str);
		i++;
	}
#endif
	for(iter = map.begin();iter != map.end(); iter++)
	{
		std::string s = iter->first;
		s += ":";
		s += iter->second;
		str = (env)->NewStringUTF(s.c_str() );
		(env)->SetObjectArrayElement(args, i, str);
		i++;
	}

	cmd::EndServerStatusEnum();
#if 0
	for (rapidjson::Value::ConstMemberIterator itr = g_serverStatus.MemberBegin(); itr != g_serverStatus.MemberEnd(); ++itr)
	{
		std::string s = itr->name.GetString();
		s += ",";
		s += itr->value.GetString();
		(env)->SetObjectArrayElement(args, i, s.c_str());
		i++;
		printf("Type of member %s is %s\n", itr->name.GetString(), itr->value.GetString());
	}
#endif
#if 0	
	for( i=0; i < len; i++ )
	{
		str = (env)->NewStringUTF(sa[i] );
		(env)->SetObjectArrayElement(args, i, str);
	}	
#endif
	return args;
}
Beispiel #4
0
//将支持api保存到mSupportedApiSet
void Device::loadSupportedApiList(const Document &replyJson)
{
	mSupportedApiSet.clear();
	if (replyJson == NULL || replyJson.IsNull())
		return;
	if (replyJson.HasMember("error"))
	{
		return;
	}
	Value::ConstArray a = replyJson["result"].GetArray()[0].GetArray();

	for (Value::ConstValueIterator itr = a.Begin(); itr != a.End(); ++itr)
	{
		mSupportedApiSet.insert(itr->GetString());
	}
}
Beispiel #5
0
 void JSONArray::_parseRapidJSONArray(void *value) {
     rapidjson::Value *rapidjsonValue = (rapidjson::Value *)value;
     
     for (Value::ConstValueIterator currentValue = rapidjsonValue->Begin(); currentValue != rapidjsonValue->End(); ++currentValue)
         
         switch (currentValue->GetType()) {
             case kNullType:
                 break;
             case kFalseType:
             case kTrueType:
                 this->appendValue(shared_ptr<JSONNumber> (new JSONNumber(kTrueType ? true: false)));
                 break;
             case kObjectType: {
                 shared_ptr<JSONObject> obj(new JSONObject());
                 obj->_parseRapidJSONObject((void*)currentValue);
                 this->appendValue(obj);
             }
                 break;
             case kArrayType: {
                 shared_ptr<JSONArray> obj(new JSONArray());
                 obj->_parseRapidJSONArray((void*)currentValue);
                 this->appendValue(obj);
             }
                 break;
             case kStringType:
                 this->appendValue(shared_ptr<JSONString> (new JSONString(currentValue->GetString())));
                 break;
             case kNumberType:
                 if (rapidjsonValue->IsDouble()) {
                     this->appendValue(shared_ptr<JSONNumber> (new JSONNumber(currentValue->GetDouble())));
                 } else if (rapidjsonValue->IsInt() || currentValue->IsInt64()) {
                     this->appendValue(shared_ptr<JSONNumber> (new JSONNumber(currentValue->GetInt())));
                 } else if (currentValue->IsUint() || currentValue->IsUint64()) {
                     this->appendValue(shared_ptr<JSONNumber> (new JSONNumber(currentValue->GetUint())));
                 }
                 
                 break;
         }
 }
//设置曝光模式
void CLiveview::OnCbnSelchangeCombo3()
{
	int nIndex = mExpoCombo.GetCurSel();
	CString sel;
	mExpoCombo.GetLBText(nIndex, sel);
	Document d = indevice->setExposureMode(sel);
	if (indevice->isJsonOk(d))
	{
		//获取支持的ISO
		mIsoCombo.ResetContent();
		const Document replyJson3 = indevice->getAvailableIsoSpeedRate();
		if (indevice->isJsonOk(replyJson3))
		{
			CString curIso = replyJson3["result"].GetArray()[0].GetString();
			Value::ConstArray a = replyJson3["result"].GetArray()[1].GetArray();
			for (Value::ConstValueIterator itr = a.Begin(); itr != a.End(); ++itr)
			{
				mIsoCombo.AddString(itr->GetString());
			}
			mIsoCombo.SelectString(0, curIso);
		}
	}
}
/* ****************************************************************************
*
* parseContextAttributeCompoundValue - 
*/
std::string parseContextAttributeCompoundValue
(
  const Value::ConstValueIterator&   node,
  ContextAttribute*                  caP,
  orion::CompoundValueNode*          parent
)  
{
  if (node->IsObject())
  {
    int counter  = 0;

    for (Value::ConstMemberIterator iter = node->MemberBegin(); iter != node->MemberEnd(); ++iter)
    {
      std::string                nodeType = jsonParseTypeNames[iter->value.GetType()];
      orion::CompoundValueNode*  cvnP     = new orion::CompoundValueNode();

      cvnP->valueType  = stringToCompoundType(nodeType);

      cvnP->name       = iter->name.GetString();
      cvnP->container  = parent;
      cvnP->rootP      = parent->rootP;
      cvnP->level      = parent->level + 1;
      cvnP->siblingNo  = counter;
      cvnP->path       = parent->path + cvnP->name;

      if (nodeType == "String")
      {
        cvnP->stringValue       = iter->value.GetString();
      }
      else if (nodeType == "Number")
      {
        cvnP->numberValue = iter->value.GetDouble();
      }
      else if ((nodeType == "True") || (nodeType == "False"))
      {
        cvnP->boolValue   = (nodeType == "True")? true : false;
      }
      else if (nodeType == "Null")
      {
        cvnP->valueType = orion::ValueTypeNone;
      }
      else if (nodeType == "Object")
      {
        cvnP->path += "/";
        cvnP->valueType = orion::ValueTypeObject;
      }
      else if (nodeType == "Array")
      {
        cvnP->path += "/";
        cvnP->valueType = orion::ValueTypeVector;
      }

      parent->childV.push_back(cvnP);
        
      //
      // Recursive call if Object or Array
      //
      if ((nodeType == "Object") || (nodeType == "Array"))
      {
        parseContextAttributeCompoundValue(iter, caP, cvnP);
      }

      ++counter;
    }
  }
  else if (node->IsArray())
  {
    int counter  = 0;

    for (Value::ConstValueIterator iter = node->Begin(); iter != node->End(); ++iter)
    {
      std::string                nodeType  = jsonParseTypeNames[iter->GetType()];
      orion::CompoundValueNode*  cvnP      = new orion::CompoundValueNode();
      char                       itemNo[4];

      snprintf(itemNo, sizeof(itemNo), "%03d", counter);

      cvnP->valueType  = stringToCompoundType(nodeType);
      cvnP->container  = parent;
      cvnP->rootP      = parent->rootP;
      cvnP->level      = parent->level + 1;
      cvnP->siblingNo  = counter;
      cvnP->path       = parent->path + "[" + itemNo + "]";


      if (nodeType == "String")
      {
        cvnP->stringValue       = iter->GetString();
      }
      else if (nodeType == "Number")
      {
        cvnP->numberValue = iter->GetDouble();
      }
      else if ((nodeType == "True") || (nodeType == "False"))
      {
        cvnP->boolValue   = (nodeType == "True")? true : false;
      }
      else if (nodeType == "Null")
      {
        cvnP->valueType = orion::ValueTypeNone;
      }
      else if (nodeType == "Object")
      {
        cvnP->path += "/";
        cvnP->valueType = orion::ValueTypeObject;
      }
      else if (nodeType == "Array")
      {
        cvnP->path += "/";
        cvnP->valueType = orion::ValueTypeVector;
      }

      parent->childV.push_back(cvnP);

      //
      // Recursive call if Object or Array
      //
      if ((nodeType == "Object") || (nodeType == "Array"))
      {
        parseContextAttributeCompoundValue(iter, caP, cvnP);
      }

      ++counter;
    }
  }


  return "OK";
}
/* ****************************************************************************
*
* parseContextAttributeCompoundValueStandAlone - 
*/
std::string parseContextAttributeCompoundValueStandAlone
(
  Document&            document,
  ContextAttribute*    caP,
  orion::ValueType     valueType
)
{
  caP->compoundValueP            = new orion::CompoundValueNode();
  caP->compoundValueP->name      = "TOP";
  caP->compoundValueP->container = caP->compoundValueP;
  caP->compoundValueP->valueType = caP->valueType;  // Convert to other type?
  caP->compoundValueP->path      = "/";
  caP->compoundValueP->rootP     = caP->compoundValueP;
  caP->compoundValueP->level     = 0;
  caP->compoundValueP->siblingNo = 0;

  orion::CompoundValueNode*   parent  = caP->compoundValueP;


  //
  // Children of the node
  //
  if (caP->valueType == orion::ValueTypeVector)
  {
    int counter  = 0;

    for (Value::ConstValueIterator iter = document.Begin(); iter != document.End(); ++iter)
    {
      std::string                nodeType  = jsonParseTypeNames[iter->GetType()];
      orion::CompoundValueNode*  cvnP      = new orion::CompoundValueNode();
      char                       itemNo[4];

      snprintf(itemNo, sizeof(itemNo), "%03d", counter);

      cvnP->valueType  = stringToCompoundType(nodeType);
      cvnP->container  = parent;
      cvnP->rootP      = parent->rootP;
      cvnP->level      = parent->level + 1;
      cvnP->siblingNo  = counter;
      cvnP->path       = parent->path + "[" + itemNo + "]";


      if (nodeType == "String")
      {
        cvnP->stringValue = iter->GetString();
      }
      else if (nodeType == "Number")
      {
        cvnP->numberValue = iter->GetDouble();
      }
      else if ((nodeType == "True") || (nodeType == "False"))
      {
        cvnP->boolValue   = (nodeType == "True")? true : false;
      }
      else if (nodeType == "Null")
      {
        cvnP->valueType = orion::ValueTypeNone;
      }
      else if (nodeType == "Object")
      {
        cvnP->path += "/";
        cvnP->valueType = orion::ValueTypeObject;
      }
      else if (nodeType == "Array")
      {
        cvnP->path += "/";
        cvnP->valueType = orion::ValueTypeVector;
      }

      parent->childV.push_back(cvnP);

      //
      // Start recursive calls if Object or Array
      //
      if ((nodeType == "Object") || (nodeType == "Array"))
      {
        parseContextAttributeCompoundValue(iter, caP, cvnP);
      }
      else if (!caP->typeGiven)
      {
        caP->type = defaultType(caP->valueType);
      }

      ++counter;
    }
  }
  else if (caP->valueType == orion::ValueTypeObject)
  {
    int counter  = 0;

    for (Value::ConstMemberIterator iter = document.MemberBegin(); iter != document.MemberEnd(); ++iter)
    {
      std::string                nodeType = jsonParseTypeNames[iter->value.GetType()];
      orion::CompoundValueNode*  cvnP     = new orion::CompoundValueNode();

      cvnP->name       = iter->name.GetString();
      cvnP->valueType  = stringToCompoundType(nodeType);
      cvnP->container  = parent;
      cvnP->rootP      = parent->rootP;
      cvnP->level      = parent->level + 1;
      cvnP->siblingNo  = counter;
      cvnP->path       = parent->path + cvnP->name;

      if (nodeType == "String")
      {
        cvnP->stringValue = iter->value.GetString();
      }
      else if (nodeType == "Number")
      {
        cvnP->numberValue = iter->value.GetDouble();
      }
      else if ((nodeType == "True") || (nodeType == "False"))
      {
        cvnP->boolValue   = (nodeType == "True")? true : false;
      }
      else if (nodeType == "Null")
      {
        cvnP->valueType = orion::ValueTypeNone;
      }
      else if (nodeType == "Object")
      {
        cvnP->path += "/";
        cvnP->valueType = orion::ValueTypeObject;
      }
      else if (nodeType == "Array")
      {
        cvnP->path += "/";
        cvnP->valueType = orion::ValueTypeVector;
      }

      parent->childV.push_back(cvnP);
        
      //
      // Start recursive calls if Object or Array
      //
      if ((nodeType == "Object") || (nodeType == "Array"))
      {
        parseContextAttributeCompoundValue(iter, caP, cvnP);
      }
      else if (!caP->typeGiven)
      {
        caP->type = defaultType(caP->valueType);
      }

      ++counter;
    }
  }

  return "OK";
}
bool PlayFabRequestHandler::DecodeRequest(int httpStatus, HttpRequest* request, void* userData, PlayFabBaseModel& outResult, PlayFabError& outError)
{
	std::string response = request->GetReponse();
	Document rawResult;
	rawResult.Parse<0>(response.c_str());

	// Check for bad responses
	if (response.length() == 0 // Null response
		|| rawResult.GetParseError() != NULL) // Non-Json response
	{
		// If we get here, we failed to connect meaningfully to the server - Assume a timeout
		outError.HttpCode = 408;
		outError.ErrorCode = PlayFabErrorConnectionTimeout;
		// For text returns, use the non-json response if possible, else default to no response
		outError.ErrorName = outError.ErrorMessage = outError.HttpStatus = response.length() == 0 ? "Request Timeout or null response" : response;
		return false;
	}

	// Check if the returned json indicates an error
	const Value::Member* errorCodeJson = rawResult.FindMember("errorCode");
	if (errorCodeJson != NULL)
	{
		// There was an error, BUMMER
		if (!errorCodeJson->value.IsNumber())
		{
			// unexpected json formatting - If we get here, we failed to connect meaningfully to the server - Assume a timeout
			outError.HttpCode = 408;
			outError.ErrorCode = PlayFabErrorConnectionTimeout;
			// For text returns, use the non-json response if possible, else default to no response
			outError.ErrorName = outError.ErrorMessage = outError.HttpStatus = response.length() == 0 ? "Request Timeout or null response" : response;
			return false;
		}
		// TODO: what happens when the error is not in the enum?
		outError.ErrorCode = static_cast<PlayFabErrorCode>(errorCodeJson->value.GetInt());

		const Value::Member* codeJson = rawResult.FindMember("code");
		if (codeJson != NULL && codeJson->value.IsNumber())
			outError.HttpCode = codeJson->value.GetInt();

		const Value::Member* statusJson = rawResult.FindMember("status");
		if (statusJson != NULL && statusJson->value.IsString())
			outError.HttpStatus = statusJson->value.GetString();

		const Value::Member* errorNameJson = rawResult.FindMember("error");
		if (errorNameJson != NULL && errorNameJson->value.IsString())
			outError.ErrorName = errorNameJson->value.GetString();

		const Value::Member* errorMessageJson = rawResult.FindMember("errorMessage");
		if (errorMessageJson != NULL && errorMessageJson->value.IsString())
			outError.ErrorMessage = errorMessageJson->value.GetString();

		const Value::Member* errorDetailsJson = rawResult.FindMember("errorDetails");
		if (errorDetailsJson != NULL && errorDetailsJson->value.IsObject())
		{
			const Value& errorDetailsObj = errorDetailsJson->value;

			for (Value::ConstMemberIterator itr = errorDetailsObj.MemberBegin(); itr != errorDetailsObj.MemberEnd(); ++itr)
			{
				if (itr->name.IsString() && itr->value.IsArray())
				{
					const Value& errorList = itr->value;
					for (Value::ConstValueIterator erroListIter = errorList.Begin(); erroListIter != errorList.End(); ++erroListIter)
						outError.ErrorDetails.insert(std::pair<std::string, std::string>(itr->name.GetString(), erroListIter->GetString()));
				}
			}
		}
		// We encountered no errors parsing the error
		return false;
	}

	const Value::Member* data = rawResult.FindMember("data");
	if (data == NULL || !data->value.IsObject())
		return false;

	return outResult.readFromValue(data->value);
}
Beispiel #10
0
TEST(Value, Array) {
    Value x(kArrayType);
    const Value& y = x;
    Value::AllocatorType allocator;

    EXPECT_EQ(kArrayType, x.GetType());
    EXPECT_TRUE(x.IsArray());
    EXPECT_TRUE(x.Empty());
    EXPECT_EQ(0u, x.Size());
    EXPECT_TRUE(y.IsArray());
    EXPECT_TRUE(y.Empty());
    EXPECT_EQ(0u, y.Size());

    EXPECT_FALSE(x.IsNull());
    EXPECT_FALSE(x.IsBool());
    EXPECT_FALSE(x.IsFalse());
    EXPECT_FALSE(x.IsTrue());
    EXPECT_FALSE(x.IsString());
    EXPECT_FALSE(x.IsObject());

    // PushBack()
    Value v;
    x.PushBack(v, allocator);
    v.SetBool(true);
    x.PushBack(v, allocator);
    v.SetBool(false);
    x.PushBack(v, allocator);
    v.SetInt(123);
    x.PushBack(v, allocator);
    //x.PushBack((const char*)"foo", allocator); // should not compile
    x.PushBack("foo", allocator);

    EXPECT_FALSE(x.Empty());
    EXPECT_EQ(5u, x.Size());
    EXPECT_FALSE(y.Empty());
    EXPECT_EQ(5u, y.Size());
    EXPECT_TRUE(x[SizeType(0)].IsNull());
    EXPECT_TRUE(x[1].IsTrue());
    EXPECT_TRUE(x[2].IsFalse());
    EXPECT_TRUE(x[3].IsInt());
    EXPECT_EQ(123, x[3].GetInt());
    EXPECT_TRUE(y[SizeType(0)].IsNull());
    EXPECT_TRUE(y[1].IsTrue());
    EXPECT_TRUE(y[2].IsFalse());
    EXPECT_TRUE(y[3].IsInt());
    EXPECT_EQ(123, y[3].GetInt());
    EXPECT_TRUE(y[4].IsString());
    EXPECT_STREQ("foo", y[4].GetString());

#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
    // PushBack(GenericValue&&, Allocator&);
    {
        Value y(kArrayType);
        y.PushBack(Value(true), allocator);
        y.PushBack(std::move(Value(kArrayType).PushBack(Value(1), allocator).PushBack("foo", allocator)), allocator);
        EXPECT_EQ(2u, y.Size());
        EXPECT_TRUE(y[0].IsTrue());
        EXPECT_TRUE(y[1].IsArray());
        EXPECT_EQ(2u, y[1].Size());
        EXPECT_TRUE(y[1][0].IsInt());
        EXPECT_TRUE(y[1][1].IsString());
    }
#endif

    // iterator
    Value::ValueIterator itr = x.Begin();
    EXPECT_TRUE(itr != x.End());
    EXPECT_TRUE(itr->IsNull());
    ++itr;
    EXPECT_TRUE(itr != x.End());
    EXPECT_TRUE(itr->IsTrue());
    ++itr;
    EXPECT_TRUE(itr != x.End());
    EXPECT_TRUE(itr->IsFalse());
    ++itr;
    EXPECT_TRUE(itr != x.End());
    EXPECT_TRUE(itr->IsInt());
    EXPECT_EQ(123, itr->GetInt());
    ++itr;
    EXPECT_TRUE(itr != x.End());
    EXPECT_TRUE(itr->IsString());
    EXPECT_STREQ("foo", itr->GetString());

    // const iterator
    Value::ConstValueIterator citr = y.Begin();
    EXPECT_TRUE(citr != y.End());
    EXPECT_TRUE(citr->IsNull());
    ++citr;
    EXPECT_TRUE(citr != y.End());
    EXPECT_TRUE(citr->IsTrue());
    ++citr;
    EXPECT_TRUE(citr != y.End());
    EXPECT_TRUE(citr->IsFalse());
    ++citr;
    EXPECT_TRUE(citr != y.End());
    EXPECT_TRUE(citr->IsInt());
    EXPECT_EQ(123, citr->GetInt());
    ++citr;
    EXPECT_TRUE(citr != y.End());
    EXPECT_TRUE(citr->IsString());
    EXPECT_STREQ("foo", citr->GetString());

    // PopBack()
    x.PopBack();
    EXPECT_EQ(4u, x.Size());
    EXPECT_TRUE(y[SizeType(0)].IsNull());
    EXPECT_TRUE(y[1].IsTrue());
    EXPECT_TRUE(y[2].IsFalse());
    EXPECT_TRUE(y[3].IsInt());

    // Clear()
    x.Clear();
    EXPECT_TRUE(x.Empty());
    EXPECT_EQ(0u, x.Size());
    EXPECT_TRUE(y.Empty());
    EXPECT_EQ(0u, y.Size());

    // Erase(ValueIterator)

    // Use array of array to ensure removed elements' destructor is called.
    // [[0],[1],[2],...]
    for (int i = 0; i < 10; i++)
        x.PushBack(Value(kArrayType).PushBack(i, allocator).Move(), allocator);

    // Erase the first
    itr = x.Erase(x.Begin());
    EXPECT_EQ(x.Begin(), itr);
    EXPECT_EQ(9u, x.Size());
    for (int i = 0; i < 9; i++)
        EXPECT_EQ(i + 1, x[static_cast<SizeType>(i)][0].GetInt());

    // Ease the last
    itr = x.Erase(x.End() - 1);
    EXPECT_EQ(x.End(), itr);
    EXPECT_EQ(8u, x.Size());
    for (int i = 0; i < 8; i++)
        EXPECT_EQ(i + 1, x[static_cast<SizeType>(i)][0].GetInt());

    // Erase the middle
    itr = x.Erase(x.Begin() + 4);
    EXPECT_EQ(x.Begin() + 4, itr);
    EXPECT_EQ(7u, x.Size());
    for (int i = 0; i < 4; i++)
        EXPECT_EQ(i + 1, x[static_cast<SizeType>(i)][0].GetInt());
    for (int i = 4; i < 7; i++)
        EXPECT_EQ(i + 2, x[static_cast<SizeType>(i)][0].GetInt());

    // Erase(ValueIterator, ValueIterator)
    // Exhaustive test with all 0 <= first < n, first <= last <= n cases
    const unsigned n = 10;
    for (unsigned first = 0; first < n; first++) {
        for (unsigned last = first; last <= n; last++) {
            x.Clear();
            for (unsigned i = 0; i < n; i++)
                x.PushBack(Value(kArrayType).PushBack(i, allocator).Move(), allocator);
            
            itr = x.Erase(x.Begin() + first, x.Begin() + last);
            if (last == n)
                EXPECT_EQ(x.End(), itr);
            else
                EXPECT_EQ(x.Begin() + first, itr);

            size_t removeCount = last - first;
            EXPECT_EQ(n - removeCount, x.Size());
            for (unsigned i = 0; i < first; i++)
                EXPECT_EQ(i, x[i][0].GetUint());
            for (unsigned i = first; i < n - removeCount; i++)
                EXPECT_EQ(i + removeCount, x[static_cast<SizeType>(i)][0].GetUint());
        }
    }

    // Working in gcc without C++11, but VS2013 cannot compile. To be diagnosed.
    // http://en.wikipedia.org/wiki/Erase-remove_idiom
    x.Clear();
    for (int i = 0; i < 10; i++)
        if (i % 2 == 0)
            x.PushBack(i, allocator);
        else
            x.PushBack(Value(kNullType).Move(), allocator);

    const Value null(kNullType);
    x.Erase(std::remove(x.Begin(), x.End(), null), x.End());
    EXPECT_EQ(5u, x.Size());
    for (int i = 0; i < 5; i++)
        EXPECT_EQ(i * 2, x[static_cast<SizeType>(i)]);

    // SetArray()
    Value z;
    z.SetArray();
    EXPECT_TRUE(z.IsArray());
    EXPECT_TRUE(z.Empty());
}
void CLiveview::start()
{
	Document replyJson;
	//如果支持startRecMode
	if (indevice->isCameraApiAvailable("startRecMode")) {
		replyJson = indevice->startRecMode();

		//重新获取可用API
		replyJson = indevice->getAvailableApiList();
		indevice->loadAvailableCameraApiList(replyJson);
	}

	//开始liveview  开两个子线程   一个获取图片  一个画出来
	if (indevice->isCameraApiAvailable("startLiveview")) {
		CreateThread(0, 0, retrieveJPG, this, 0, 0);
		CreateThread(0, 0, drawJPEG, this, 0, 0);
	}

	//获取支持的拍摄模式
	mComMod.ResetContent();
	const Document replyJson2 = indevice->getAvailableShootMode();
	if (indevice->isJsonOk(replyJson2))
	{
		indevice->curShootMode = replyJson2["result"].GetArray()[0].GetString();
		indevice->recording = false;
		Value::ConstArray a = replyJson2["result"].GetArray()[1].GetArray();
		for (Value::ConstValueIterator itr = a.Begin(); itr != a.End(); ++itr)
		{
			indevice->mAvailableShootMod.push_back(itr->GetString());
			mComMod.AddString(itr->GetString());
		}
		mComMod.SelectString(0, indevice->curShootMode);
	}

	//获取支持的ISO
	mIsoCombo.ResetContent();
	const Document replyJson3 = indevice->getAvailableIsoSpeedRate();
	if (indevice->isJsonOk(replyJson3))
	{
		CString curIso = replyJson3["result"].GetArray()[0].GetString();
		Value::ConstArray a = replyJson3["result"].GetArray()[1].GetArray();
		for (Value::ConstValueIterator itr = a.Begin(); itr != a.End(); ++itr)
		{
			mIsoCombo.AddString(itr->GetString());
		}
		mIsoCombo.SelectString(0, curIso);
	}


	//获取支持的曝光模式
	mExpoCombo.ResetContent();
	const Document replyJson4 = indevice->getAvailableExposureMode();
	if (indevice->isJsonOk(replyJson4))
	{
		CString curExpo = replyJson4["result"].GetArray()[0].GetString();
		Value::ConstArray a = replyJson4["result"].GetArray()[1].GetArray();
		for (Value::ConstValueIterator itr = a.Begin(); itr != a.End(); ++itr)
		{
			mExpoCombo.AddString(itr->GetString());
		}
		mExpoCombo.SelectString(0, curExpo);
	}



	indevice->getAvailableStillSize();
    indevice->setStillSize();
	indevice->setPostviewImageSize();


	//获取是否支持调节焦距
	if (!indevice->isCameraApiAvailable("actZoom"))
	{
		mBtnZoomIn.EnableWindow(0);
		mBtnZoomOut.EnableWindow(0);
	}

	FreshUI();
}
std::vector<SlotType>
MtgJsonAllSetsData::getBoosterSlots( const std::string& code ) const
{
    std::vector<SlotType> boosterSlots;

    if( mBoosterSetCodes.count(code) == 0 )
    {
        mLogger->warn( "No booster member in set {}, returning empty booster slots", code );
        return boosterSlots;
    }

    // In parse() this was vetted to be safe and yield an Array-type value.
    const Value& boosterValue = mDoc[code]["booster"];

    mLogger->debug( "{:-^40}", "assembling booster slots" );
    for( Value::ConstValueIterator iter = boosterValue.Begin(); iter != boosterValue.End(); ++iter )
    {
        if( iter->IsArray() )
        {
            // create a set of any strings in the array
            std::set<std::string> slotArraySet;
            for( unsigned i = 0; i < iter->Size(); ++i )
            {
                const Value& val = (*iter)[i];
                if( val.IsString() )
                {
                    slotArraySet.insert( val.GetString() );
                    mLogger->debug( "booster slot array[{}]: {}", i, val.GetString() );
                }
                else
                {
                    mLogger->warn( "Non-string in booster slot array, ignoring!" );
                }
            }
            const std::set<std::string> rareMythicRareSlot { "rare", "mythic rare" };
            if( slotArraySet == rareMythicRareSlot )
                boosterSlots.push_back( SLOT_RARE_OR_MYTHIC_RARE );
            else
                mLogger->warn( "Unrecognized booster slot array, ignoring!" );
        }
        else if( iter->IsString() )
        {
            std::string slotStr( iter->GetString() );
            mLogger->debug( "booster slot string: {}", slotStr );
            if( slotStr == "common" )
                boosterSlots.push_back( SLOT_COMMON );
            else if( slotStr == "uncommon" )
                boosterSlots.push_back( SLOT_UNCOMMON );
            else if( slotStr == "rare" )
                boosterSlots.push_back( SLOT_RARE );
            else if( slotStr == "timeshifted purple" )
                boosterSlots.push_back( SLOT_TIMESHIFTED_PURPLE );
            else if( slotStr == "land" )      { /* do nothing */ }
            else if( slotStr == "marketing" ) { /* do nothing */ }
            else
                mLogger->warn( "Unrecognized booster slot type {}, ignoring!", slotStr );
        }
        else
        {
            mLogger->warn( "Non-string booster slot type, ignoring!" );
        }
    }
    return boosterSlots;
}