示例#1
0
	static
	groups_map_t
	create_groups_map(const kora::dynamic_t &dynamic) {
		try {
			const auto &dynamic_keys = dynamic.as_object();

			auto groups_map = groups_map_t{};
			for (auto key_it = dynamic_keys.begin(), key_end = dynamic_keys.end()
					; key_it != key_end; ++key_it) {
				const auto &dynamic_couple_ids = key_it->second.as_object();

				auto couple_id_map = std::map<std::string, groups_t>{};
				for (auto couple_id_it = dynamic_couple_ids.begin()
						, couple_id_end = dynamic_couple_ids.end()
						; couple_id_it != couple_id_end; ++couple_id_it) {
					const auto &dynamic_info = couple_id_it->second.as_object();
					const auto &dynamic_cache_groups = dynamic_info.at("cache_groups").as_array();

					auto groups = groups_t{};
					for (auto cache_groups_it = dynamic_cache_groups.begin()
							, cache_groups_end = dynamic_cache_groups.end()
							; cache_groups_it != cache_groups_end; ++cache_groups_it) {
						groups.emplace_back(cache_groups_it->to<group_t>());
					}
					couple_id_map.insert(std::make_pair(couple_id_it->first, groups));
				}

				groups_map.insert(std::make_pair(key_it->first, couple_id_map));
			}

			return groups_map;
		} catch (const std::exception &ex) {
			throw std::runtime_error(std::string("cached_keys parse error: ") + ex.what());
		}
	}
示例#2
0
bool
mastermind_t::data::namespace_state_is_deleted(const kora::dynamic_t &raw_value) {
	const auto &state_object = raw_value.as_object();
	auto it_settings = state_object.find("settings");

	if (it_settings == state_object.end()) {
		return false;
	}

	const auto &settings_object = it_settings->second.as_object();
	auto it_service = settings_object.find("__service");

	if (it_service == settings_object.end()) {
		return false;
	}

	const auto &service_object = it_service->second.as_object();
	auto it_is_deleted = service_object.find("is_deleted");

	if (it_is_deleted == service_object.end()) {
		return false;
	}

	const auto &is_deleted_object = it_is_deleted->second;
	return is_deleted_object.to<bool>();
}
示例#3
0
bp::object
convert(const kora::dynamic_t &d, const gil_guard_t &gil_guard) {
	if (d.is_null()) {
		return bp::object{};
	} else if (d.is_bool()) {
		return bp::object{d.as_bool()};
	} else if (d.is_int()) {
		return bp::object{d.as_int()};
	} else if (d.is_uint()) {
		return bp::object{d.as_uint()};
	} else if (d.is_double()) {
		return bp::object{d.as_double()};
	} else if (d.is_string()) {
		return bp::object{d.as_string()};
	} else if (d.is_array()) {
		return convert(d.as_array(), gil_guard);
	} else if (d.is_object()) {
		return convert(d.as_object(), gil_guard);
	}

	return bp::object{};
}