Array IniSetting::GetAll(const String& ext_name, bool details) { Array r = Array::Create(); const Extension* ext = nullptr; if (!ext_name.empty()) { if (ext_name == s_core) { ext = IniSetting::CORE; } else { ext = ExtensionRegistry::get(ext_name); if (!ext) { raise_warning("Unable to find extension '%s'", ext_name.toCppString().c_str()); return r; } } } for (auto& iter: boost::join(s_system_ini_callbacks, *s_user_callbacks)) { if (ext && ext != iter.second.extension) { continue; } auto value = dynamic_to_variant(iter.second.getCallback()); // Cast all non-arrays to strings since that is what everything used ot be if (!value.isArray()) { value = value.toString(); } if (details) { Array item = Array::Create(); item.add(s_global_value, value); item.add(s_local_value, value); if (iter.second.mode == PHP_INI_ALL) { item.add( s_access, Variant(PHP_INI_USER | PHP_INI_SYSTEM | PHP_INI_PERDIR) ); } else if (iter.second.mode == PHP_INI_ONLY) { item.add(s_access, Variant(PHP_INI_SYSTEM)); } else { item.add(s_access, Variant(iter.second.mode)); } r.add(String(iter.first), item); } else { r.add(String(iter.first), value); } } return r; }
//------------------------------------------------------------------------------ // Name: toJson //------------------------------------------------------------------------------ QByteArray QJsonDocument::toJson(JsonFormat format) const { Q_UNUSED(format); if(isArray()) { QString s = toJson(array(), format); return s.toUtf8(); } if(isObject()) { QString s = toJson(object(), format); return s.toUtf8(); } return QByteArray(); }
bool JSON::getArrayBoolean(int index) { if (!isArray()) { return false; } json_t *jobject = json_array_get(_json, index); if (!jobject || !json_is_boolean(jobject)) { return false; } return json_is_true(jobject); }
int JSON::getArrayJSONType(int index) { if (!isArray()) { return JSON_NULL; } json_t *jobject = json_array_get(_json, index); if (!jobject) { return JSON_NULL; } return json_typeof(jobject); }
int JSON::getObjectJSONType(const char *key) { if (!_json || isArray()) { return JSON_NULL; } json_t *jobject = json_object_get(_json, key); if (!jobject) { return JSON_NULL; } return json_typeof(jobject); }
const char *JSON::getArrayString(int index) { if (!isArray()) { return ""; } json_t *jobject = json_array_get(_json, index); if (!jobject || !json_is_string(jobject)) { return ""; } return json_string_value(jobject); }
JSON JSON::getArrayArray(int index) { if (!isArray()) { return JSON(); } json_t *object = json_array_get(_json, index); if (!object || !json_is_array(object)) { return JSON(); } return JSON(object); }
JSON* JSON::getArrayArrayNew(int index) { if (!isArray()) { return NULL; } json_t *object = json_array_get(_json, index); if (!object || !json_is_array(object)) { return NULL; } return lmNew(NULL) JSON(object); }
double JSON::getArrayNumber(int index) { if (!isArray()) { return 0.f; } json_t *jobject = json_array_get(_json, index); if (!jobject || !json_is_number(jobject)) { return 0.f; } return (double)json_number_value(jobject); }
int JSON::getArrayInteger(int index) { if (!isArray()) { return 0; } json_t *jobject = json_array_get(_json, index); if (!jobject || !json_is_integer(jobject)) { return 0; } return (int)json_integer_value(jobject); }
MessagesClient::GetMessagesResult MessagesClient::getMessages( lastModified_type modifiedAfter) { auto url = baseUserUrl() + "/messages?modifiedAfter=" + std::to_string(modifiedAfter) + "&includeData=true"; sendRequest(Http::Request( Http::HttpMethod::Get, url, makeHeaders(Authenticated::True))); auto json = parseJsonBody(); if (!json.isObject()) { throw ProtocolError("Malformed JSON document (object expected)"); } auto resultsTotal = CheckedConverter::toUint32(json["resultsTotal"]); auto resultsReturned = CheckedConverter::toUint32(json["resultsReturned"]); auto data = json["data"]; if (!data.isArray()) { throw ProtocolError("Malformed JSON document (array expected)"); } auto messages = std::vector<Message>(); messages.reserve(data.size()); for (const auto &msgJson : data) { try { messages.push_back(parseJsonMessage(msgJson)); } catch (ConversionException) { std::throw_with_nested(ProtocolError("Failed to parse messages array")); } } GetMessagesResult result; result.messages = std::move(messages); result.countReturned = resultsReturned; result.countLeft = resultsTotal; return result; }
TEST(IniSetting, ini_iterate) { std::string inistr = "hhvm.ip_block_map[0][location] = /test\n" "hhvm.ip_block_map[0][allow_first] = true\n" "hhvm.ip_block_map[0][ip][allow][0] = 127.0.0.1\n" "hhvm.ip_block_map[0][ip][deny][0] = 8.32.0.0/24\n" "hhvm.ip_block_map[0][ip][deny][1] = " "aaaa:bbbb:cccc:dddd:eeee:ffff:1111::/80\n" "hhvm.ip_block_map[1][location] = /blah\n" "hhvm.ip_block_map[1][allow_first] = true\n" "hhvm.ip_block_map[1][ip][allow][0] = 127.10.10.10\n" "hhvm.ip_block_map[1][ip][deny][0] = 255.255.255.255\n" "hhvm.server.apc.ttl_limit = 1000\n" "hhvm.server.allowed_exec_cmds[]= ls\n" "hhvm.server.allowed_exec_cmds[]= cp\n" "hhvm.jit_a_cold_size = 22222222\n"; IniSettingMap ini; Config::ParseIniString(inistr, ini); auto value = ini_iterate(ini, "hhvm.ip_block_map.0.location"); EXPECT_EQ("/test", value.toString().toCppString()); value = ini_iterate(ini, "hhvm.ip_block_map.1.ip.allow.0"); EXPECT_EQ("127.10.10.10", value.toString().toCppString()); value = ini_iterate(ini, "hhvm.server.apc.ttl_limit"); EXPECT_EQ("1000", value.toString().toCppString()); value = ini_iterate(ini, "hhvm.server.bogus.ttl_limit"); EXPECT_EQ(true, value.isNull()); value = ini_iterate(ini, "hhvm.server.allowed_exec_cmds.1"); EXPECT_EQ("cp", value.toString().toCppString()); value = ini_iterate(ini, "hhvm.ip_block_map.0.ip.deny.0"); EXPECT_EQ("8.32.0.0/24", value.toString().toCppString()); value = ini_iterate(ini, "hhvm.ip_block_map.0.ip.deny.1"); EXPECT_EQ("aaaa:bbbb:cccc:dddd:eeee:ffff:1111::/80", value.toString().toCppString()); value = ini_iterate(ini, "hhvm.ip_block_map.1.ip.allow.2"); EXPECT_EQ(true, value.isNull()); value = ini_iterate(init_null(), "hhvm.ip_block_map"); EXPECT_EQ(true, value.isNull()); value = ini_iterate(ini, "hhvm.ip_block_map"); EXPECT_EQ(true, value.isArray()); EXPECT_EQ(2, value.toArray().size()); // Check some runtime options EXPECT_EQ(22222222, jit::CodeCache::AColdSize); EXPECT_EQ("", RuntimeOption::ExtensionDir); }
/* aperm (a, perm, resize = TRUE) */ SEXP attribute_hidden do_aperm(SEXP call, SEXP op, SEXP args, SEXP rho) { SEXP a, perm, r, dimsa, dimsr, dna; int i, j, n, itmp; checkArity(op, args); a = CAR(args); if (!isArray(a)) error(_("invalid first argument, must be an array")); PROTECT(dimsa = getAttrib(a, R_DimSymbol)); n = LENGTH(dimsa); int *isa = INTEGER(dimsa); /* check the permutation */ int *pp = (int *) R_alloc((size_t) n, sizeof(int)); perm = CADR(args); if (length(perm) == 0) { for (i = 0; i < n; i++) pp[i] = n-1-i; } else { if (LENGTH(perm) != n) error(_("'perm' is of wrong length %d (!= %d)"), LENGTH(perm), n); if (isString(perm)) { SEXP dna = getAttrib(a, R_DimNamesSymbol); if (isNull(dna)) error(_("'a' does not have named dimnames")); SEXP dnna = getAttrib(dna, R_NamesSymbol); if (isNull(dnna)) error(_("'a' does not have named dimnames")); for (i = 0; i < n; i++) { const char *this = translateChar(STRING_ELT(perm, i)); for (j = 0; j < n; j++) if (streql(translateChar(STRING_ELT(dnna, j)), this)) {pp[i] = j; break;} if (j >= n) error(_("'perm[%d]' does not match a dimension name"), i+1); } } else { PROTECT(perm = coerceVector(perm, INTSXP)); for (i = 0; i < n; i++) pp[i] = INTEGER(perm)[i] - 1; UNPROTECT(1); } }
void JsonWriter::begin(Type t) { if (!stack_.empty()) { if (fieldCount() > 0) { output_ << ",\n"; } else if (isArray() && fieldCount() == 0) { output_ << "\n"; } indent(); incrementFieldCount(); } push(t); }
void SymInfo::declare( const string &name, ostream &out ) const { if ( isTemp == true ) return; assert ( Type( ) != FUNC || !_isReg ); if ( isStatic( ) ) out << "static "; if ( isConst( ) ) out << " const "; if ( isUnsigned( ) ) out << " unsigned "; //output the type if ( Type( ) == NOTYPE ) { if ( getSize( ) == 4 ) out << e2str( LONG ) << ' '; else if ( getSize( ) == 2 ) out << e2str( SINT ) << ' '; else if ( getSize( ) == 1 ) out << e2str( CHAR ) << ' '; else out << e2str( LONG ) << ' '; } else out << e2str( Type( ) ) << ' '; out << name; if ( isArray( ) ) out << "[ " << getSize( ) / sizeOfType( getType( ) ) << " ]"; if ( initValue.size( ) ) { out << "= "; if ( Type( ) == FLOAT ) out << convert2Float( atoi( initValue ) ); else if ( Type( ) == CHAR ) cout << getChar( atoi( initValue ) ); else out << initValue; } out << ';'; }
/* Private */ void SpellData::ParseSpellList(std::string &response, TSpellDataList &items) { Poco::JSON::Parser parser; auto parsed = parser.parse(response); if (parsed.isArray()) { auto spellObjects = parsed.extract<JSONArray::Ptr>(); for (int i = 0; i < spellObjects->size(); i++) { JSONObject *object = spellObjects->getObject(i); auto data = std::make_shared<SpellData>(); data->FromJSON(object); items.push_back(data); } } }
optional<std::array<float, N>> operator()(const Convertible& value, Error& error) const { if (!isArray(value) || arrayLength(value) != N) { error = { "value must be an array of " + util::toString(N) + " numbers" }; return {}; } std::array<float, N> result; for (size_t i = 0; i < N; i++) { optional<float> n = toNumber(arrayMember(value, i)); if (!n) { error = { "value must be an array of " + util::toString(N) + " numbers" }; return {}; } result[i] = *n; } return result; }
void Parameter::pupAllValues(XStr &str) { str<<" if (implDestP.hasComments()) implDestP.comment(\""<<name<<"\");\n"; if (isArray()) { str<< " implDestP.synchronize(PUP::sync_begin_array);\n" " { for (int impl_i=0;impl_i*(sizeof(*"<<name<<"))<impl_cnt_"<<name<<";impl_i++) { \n" " implDestP.synchronize(PUP::sync_item);\n" " implDestP|"<<name<<"[impl_i];\n" " } } \n" " implDestP.synchronize(PUP::sync_end_array);\n" ; } else /* not an array */ { if (isConditional()) str<<" pup_pointer(&implDestP, (void**)&"<<name<<");\n"; else str<<" implDestP|"<<name<<";\n"; } }
jarray inStream_readArrayRef(PacketInputStream *stream) { jobject object = inStream_readObjectRef(stream); if (object == NULL) { /* * Could be error or just the null reference. In either case, * stop now. */ return NULL; } if (!isArray(object)) { stream->error = JDWP_ERROR(INVALID_ARRAY); return NULL; } return object; }
/* {{{ MongoDriver\BSON\Javascript */ void VariantToBsonConverter::_convertJavascript(bson_t *bson, const char *key, Object v) { bson_t *scope_bson; String code = v.o_get(s_MongoBsonJavascript_code, false, s_MongoBsonJavascript_className).toString(); auto scope = v.o_get(s_MongoBsonJavascript_scope, false, s_MongoBsonJavascript_className); if (scope.isObject() || scope.isArray()) { /* Convert scope to document */ VariantToBsonConverter converter(scope, HIPPO_BSON_NO_FLAGS); scope_bson = bson_new(); converter.convert(scope_bson); bson_append_code_with_scope(bson, key, -1, (const char*) code.c_str(), scope_bson); } else { bson_append_code(bson, key, -1, (const char*) code.c_str()); } }
size_t TType::getObjectSize() const { size_t totalSize; if (getBasicType() == EbtStruct) totalSize = structure->objectSize(); else totalSize = primarySize * secondarySize; if (isArray()) { size_t arraySize = getArraySize(); if (arraySize > INT_MAX / totalSize) totalSize = INT_MAX; else totalSize *= arraySize; } return totalSize; }
Directory* GlobStreamWrapper::opendir(const String& path) { const char* prefix = "glob://"; const char* path_str = path.data(); int path_len = path.length(); // only accept paths with the glob:// prefix if (strncmp(path_str, prefix, strlen(prefix)) != 0) { return nullptr; } path_str += strlen(prefix); path_len -= strlen(prefix); auto glob = f_glob(String(path_str, path_len, CopyString)); if (!glob.isArray()) { return nullptr; } return NEWOBJ(ArrayDirectory)(glob.toArray()); }
static void printConst(std::ostream& os, IRInstruction* inst) { os << color(ANSI_COLOR_LIGHT_BLUE); SCOPE_EXIT { os << color(ANSI_COLOR_END); }; auto t = inst->typeParam(); auto c = inst->extra<DefConst>(); if (t == Type::Int) { os << c->as<int64_t>(); } else if (t == Type::Dbl) { os << c->as<double>(); } else if (t == Type::Bool) { os << (c->as<bool>() ? "true" : "false"); } else if (t.isString()) { auto str = c->as<const StringData*>(); os << "\"" << Util::escapeStringForCPP(str->data(), str->size()) << "\""; } else if (t.isArray()) { auto arr = inst->extra<DefConst>()->as<const ArrayData*>(); if (arr->empty()) { os << "array()"; } else { os << "Array(" << arr << ")"; } } else if (t.isNull() || t.subtypeOf(Type::Nullptr)) { os << t.toString(); } else if (t.subtypeOf(Type::Func)) { auto func = c->as<const Func*>(); os << "Func(" << (func ? func->fullName()->data() : "0") << ")"; } else if (t.subtypeOf(Type::Cls)) { auto cls = c->as<const Class*>(); os << "Cls(" << (cls ? cls->name()->data() : "0") << ")"; } else if (t.subtypeOf(Type::NamedEntity)) { auto ne = c->as<const NamedEntity*>(); os << "NamedEntity(" << ne << ")"; } else if (t.subtypeOf(Type::TCA)) { TCA tca = c->as<TCA>(); auto name = Util::getNativeFunctionName(tca); SCOPE_EXIT { free(name); }; os << folly::format("TCA: {}({})", tca, boost::trim_copy(std::string(name))); } else if (t.subtypeOf(Type::None)) {
// // Recursively generate mangled names. // void TType::buildMangledName(TString& mangledName) { if (isMatrix()) mangledName += 'm'; else if (isVector()) mangledName += 'v'; switch (type) { case EbtFloat: mangledName += 'f'; break; case EbtInt: mangledName += 'i'; break; case EbtBool: mangledName += 'b'; break; case EbtSampler1D: mangledName += "s1"; break; case EbtSampler2D: mangledName += "s2"; break; case EbtSampler3D: mangledName += "s3"; break; case EbtSamplerCube: mangledName += "sC"; break; case EbtSampler1DShadow: mangledName += "sS1"; break; case EbtSampler2DShadow: mangledName += "sS2"; break; case EbtSamplerRect: mangledName += "sR2"; break; // ARB_texture_rectangle case EbtSamplerRectShadow: mangledName += "sSR2"; break; // ARB_texture_rectangle case EbtStruct: mangledName += "struct-"; if (typeName) mangledName += *typeName; {// support MSVC++6.0 for (unsigned int i = 0; i < structure->size(); ++i) { mangledName += '-'; (*structure)[i].type->buildMangledName(mangledName); } } default: break; } mangledName += static_cast<char>('0' + getNominalSize()); if (isArray()) { char buf[10]; sprintf(buf, "%d", arraySize); mangledName += '['; mangledName += buf; mangledName += ']'; } }
//------------------------------------------------------------------------------ // Name: operator== //------------------------------------------------------------------------------ bool QJsonDocument::operator==(const QJsonDocument &other) const { if(isArray() && other.isArray()) { return array() == other.array(); } if(isObject() && other.isObject()) { return object() == other.object(); } if(isEmpty() && other.isEmpty()) { return true; } if(isNull() && other.isNull()) { return true; } return false; }
UniformParameterPtr Program::resolveParameter(GpuProgramParameters::AutoConstantType autoType, size_t data) { UniformParameterPtr param; // Check if parameter already exists. param = getParameterByAutoType(autoType); if (param) { return param; } // Create new parameter size_t size = 0; if(isArray(autoType)) std::swap(size, data); // for array autotypes the extra parameter is the size param = UniformParameterPtr(OGRE_NEW UniformParameter(autoType, data, size)); addParameter(param); return param; }
PhpClass::PhpClass(const folly::dynamic &c) : m_class(c), m_idlName(c["name"].asString()), m_phpName(toPhpName(m_idlName)), m_cppName(toCppName(m_idlName)), m_flags(parseFlags(m_class["flags"])), m_desc(getFollyDynamicDefaultString(c, "desc", "")) { auto ifacesIt = m_class.find("ifaces"); if (ifacesIt != m_class.items().end()) { auto ifaces = ifacesIt->second; if (!ifaces.isArray()) { throw std::logic_error( folly::format("Class {0}.ifaces field must be an array", m_idlName).str() ); } for (auto &interface : ifaces) { m_ifaces.push_back(interface.asString()); } } for (auto const& f : c["funcs"]) { PhpFunc func(f, getCppName()); m_methods.push_back(func); } if (c.find("consts") != c.items().end()) { for (auto const& cns : c["consts"]) { PhpConst cons(cns, getCppName()); m_constants.push_back(cons); } } if (c.find("properties") != c.items().end()) { for (auto const& prp : c["properties"]) { PhpProp prop(prp, getCppName()); m_properties.push_back(prop); } } }
static bool parse_paths(w_query* res, const json_ref& query) { size_t i; auto paths = query.get_default("path"); if (!paths) { return true; } if (!paths.isArray()) { throw QueryParseError("'path' must be an array"); } res->paths.resize(json_array_size(paths)); for (i = 0; i < json_array_size(paths); i++) { const auto& ele = paths.at(i); w_string name; res->paths[i].depth = -1; if (ele.isString()) { name = json_to_w_string(ele); } else if (ele.isObject()) { name = json_to_w_string(ele.get("path")); auto depth = ele.get("depth"); if (!depth.isInt()) { throw QueryParseError("path.depth must be an integer"); } res->paths[i].depth = json_integer_value(depth); } else { throw QueryParseError( "expected object with 'path' and 'depth' properties"); } res->paths[i].name = name.normalizeSeparators(); } return true; }
void Read(const QString& fileName, SignalData& data, PlotInfo& plotInfo, std::function<void(Signal&&)> onSignal, std::function<void()> onAfterSignalRead) { QFile in(fileName); if (!in.open(QIODevice::ReadOnly | QFile::Text)) { auto mex = QString("Cannot open specified file -> %1").arg(fileName); QMessageBox::critical(nullptr, "Anvedi", mex); throw std::exception(mex.toUtf8().data()); } const auto json = QJsonDocument::fromJson(in.readAll()).object(); auto backgroundIt = json.find("background"); if (backgroundIt != json.end()) { plotInfo.setBackgroundColor(backgroundIt->toString()); } auto graphIt = json.find("signals"); if ((graphIt != json.end()) && graphIt->isArray()) { for (const auto& elem : graphIt->toArray()) { if (elem.isObject()) { onSignal(ReadGraph(elem.toObject())); } } } onAfterSignalRead(); auto domainIt = json.find("domain"); if (domainIt != json.end()) { const auto domainName = domainIt->toString(); try { data.setAsDomain(domainName); } catch (const std::exception&){} } }
void ShadowSettings::registerOnUpdateCallback(McrouterInstance& router) { handle_ = router.rtVarsData().subscribeAndCall( [this](std::shared_ptr<const RuntimeVarsData> oldVars, std::shared_ptr<const RuntimeVarsData> newVars) { if (!newVars || keyFractionRangeRv_.empty()) { return; } auto val = newVars->getVariableByName(keyFractionRangeRv_); if (val != nullptr) { checkLogic(val.isArray(), "runtime vars: {} is not an array", keyFractionRangeRv_); checkLogic(val.size() == 2, "runtime vars: size of {} is not 2", keyFractionRangeRv_); checkLogic(val[0].isNumber(), "runtime vars: {}#0 is not a number", keyFractionRangeRv_); checkLogic(val[1].isNumber(), "runtime vars: {}#1 is not a number", keyFractionRangeRv_); setKeyRange(val[0].asDouble(), val[1].asDouble()); } }); }