示例#1
0
void ArrayIter::secondHelper(Variant & v) {
    if (hasVector()) {
        c_Vector* vec = getVector();
        if (UNLIKELY(m_versionNumber != vec->getVersionNumber())) {
            throw_collection_modified();
        }
        v = tvAsCVarRef(vec->at(m_pos));
        return;
    }
    if (hasMap()) {
        c_Map* mp = getMap();
        if (UNLIKELY(m_versionNumber != mp->getVersionNumber())) {
            throw_collection_modified();
        }
        v = mp->iter_value(m_pos);
        return;
    }
    if (hasStableMap()) {
        c_StableMap* smp = getStableMap();
        if (UNLIKELY(m_versionNumber != smp->getVersionNumber())) {
            throw_collection_modified();
        }
        v = smp->iter_value(m_pos);
        return;
    }
    assert(hasObject());
    ObjectData* obj = getObject();
    v = obj->o_invoke(s_current, Array());
}
示例#2
0
void ArrayIter::objInit(ObjectData *obj) {
    assert(obj);
    setObject(obj);
    if (incRef) {
        obj->incRefCount();
    }
    if (!obj->isCollection()) {
        assert(obj->o_instanceof(s_Iterator));
        obj->o_invoke(s_rewind, Array());
    } else {
        if (hasVector()) {
            c_Vector* vec = getVector();
            m_versionNumber = vec->getVersionNumber();
            m_pos = 0;
        } else if (hasMap()) {
            c_Map* mp = getMap();
            m_versionNumber = mp->getVersionNumber();
            m_pos = mp->iter_begin();
        } else if (hasStableMap()) {
            c_StableMap* smp = getStableMap();
            m_versionNumber = smp->getVersionNumber();
            m_pos = smp->iter_begin();
        } else {
            assert(false);
        }
    }
}
示例#3
0
HOT_FUNC
Variant ArrayIter::second() {
    if (hasVector()) {
        c_Vector* vec = getVector();
        if (UNLIKELY(m_versionNumber != vec->getVersionNumber())) {
            throw_collection_modified();
        }
        return tvAsCVarRef(vec->at(m_pos));
    }
    if (hasMap()) {
        c_Map* mp = getMap();
        if (UNLIKELY(m_versionNumber != mp->getVersionNumber())) {
            throw_collection_modified();
        }
        return mp->iter_value(m_pos);
    }
    if (hasStableMap()) {
        c_StableMap* smp = getStableMap();
        if (UNLIKELY(m_versionNumber != smp->getVersionNumber())) {
            throw_collection_modified();
        }
        return smp->iter_value(m_pos);
    }
    if (hasObject()) {
        ObjectData* obj = getObject();
        return obj->o_invoke(s_current, Array());
    }
    assert(hasArrayData());
    assert(m_pos != ArrayData::invalid_index);
    const ArrayData* ad = getArrayData();
    assert(ad);
    return ad->getValue(m_pos);
}
示例#4
0
void ArrayIter::nextHelper() {
    if (hasVector()) {
        m_pos++;
        return;
    }
    if (hasMap()) {
        assert(m_pos != 0);
        c_Map* mp = getMap();
        if (UNLIKELY(m_versionNumber != mp->getVersionNumber())) {
            throw_collection_modified();
        }
        m_pos = mp->iter_next(m_pos);
        return;
    }
    if (hasStableMap()) {
        assert(m_pos != 0);
        c_StableMap* smp = getStableMap();
        if (UNLIKELY(m_versionNumber != smp->getVersionNumber())) {
            throw_collection_modified();
        }
        m_pos = smp->iter_next(m_pos);
        return;
    }
    assert(hasObject());
    ObjectData* obj = getObject();
    obj->o_invoke(s_next, Array());
}
示例#5
0
void ArrayIter::objInit(ObjectData *obj, bool rewind /* = true */) {
  ASSERT(obj);
  setObject(obj);
  if (incRef) {
    obj->incRefCount();
  }
  if (!obj->isCollection()) {
    ASSERT(obj->o_instanceof(s_Iterator));
    if (rewind) {
      obj->o_invoke(s_rewind, Array());
    }
    // If it is from IteratorAggregate, there is no need to rewind.
  } else {
    if (hasVector()) {
      c_Vector* vec = getVector();
      m_versionNumber = vec->getVersionNumber();
      m_pos = 0;
    } else if (hasMap()) {
      c_Map* mp = getMap();
      m_versionNumber = mp->getVersionNumber();
      m_pos = mp->iter_begin();
    } else if (hasStableMap()) {
      c_StableMap* smp = getStableMap();
      m_versionNumber = smp->getVersionNumber();
      m_pos = smp->iter_begin();
    } else {
      ASSERT(false);
    }
  }
}
示例#6
0
bool ArrayIter::endHelper() {
    if (hasVector()) {
        c_Vector* vec = getVector();
        return m_pos >= vec->t_count();
    }
    if (hasMap()) {
        return m_pos == 0;
    }
    if (hasStableMap()) {
        return m_pos == 0;
    }
    assert(hasObject());
    ObjectData* obj = getObject();
    return !obj->o_invoke(s_valid, Array());
}
示例#7
0
Variant ArrayIter::firstHelper() {
    if (hasVector()) {
        return m_pos;
    }
    if (hasMap()) {
        assert(m_pos != 0);
        c_Map* mp = getMap();
        if (UNLIKELY(m_versionNumber != mp->getVersionNumber())) {
            throw_collection_modified();
        }
        return mp->iter_key(m_pos);
    }
    if (hasStableMap()) {
        assert(m_pos != 0);
        c_StableMap* smp = getStableMap();
        if (UNLIKELY(m_versionNumber != smp->getVersionNumber())) {
            throw_collection_modified();
        }
        return smp->iter_key(m_pos);
    }
    assert(hasObject());
    ObjectData* obj = getObject();
    return obj->o_invoke(s_key, Array());
}
bool MapcrafterConfig::parse(const std::string& filename, ValidationMap& validation) {
	INIConfig config;
	ValidationMessage msg;
	if (!config.loadFile(filename, msg)) {
		validation.push_back(std::make_pair("Configuration file", makeValidationList(msg)));
		return false;
	}

	fs::path config_dir = fs::path(filename).parent_path();

	bool ok = true;

	ValidationList general_msgs;

	bool has_default_template = !util::findTemplateDir().empty();
	if (has_default_template)
		template_dir.setDefault(util::findTemplateDir());

	auto entries = config.getRootSection().getEntries();
	for (auto entry_it = entries.begin(); entry_it != entries.end(); ++entry_it) {
		std::string key = entry_it->first;
		std::string value = entry_it->second;

		if (key == "output_dir") {
			if (output_dir.load(key, value, general_msgs))
				output_dir.setValue(BOOST_FS_ABSOLUTE(output_dir.getValue(), config_dir));
		} else if (key == "template_dir") {
			if (template_dir.load(key, value, general_msgs)) {
				template_dir.setValue(BOOST_FS_ABSOLUTE(template_dir.getValue(), config_dir));
				if (!fs::is_directory(template_dir.getValue()))
					general_msgs.push_back(ValidationMessage::error(
							"'template_dir' must be an existing directory! '"
							+ template_dir.getValue().string() + "' does not exist!"));
			}
		} else {
			general_msgs.push_back(ValidationMessage::warning(
					"Unknown configuration option '" + key + "'!"));
		}
	}

	if (!output_dir.require(general_msgs, "You have to specify an output directory ('output_dir')!"))
		ok = false;
	if (!has_default_template)
		template_dir.require(general_msgs, "You have to specify a template directory ('template_dir')!");

	if (!general_msgs.empty())
		validation.push_back(std::make_pair("Configuration file", general_msgs));

	if (config.hasSection("global", "worlds")) {
		ValidationList msgs;
		world_global.setConfigDir(config_dir);
		ok = world_global.parse(config.getSection("global", "worlds"), msgs) && ok;
		if (!msgs.empty())
			validation.push_back(std::make_pair("Global world configuration", msgs));
		if (!ok)
			return false;
	}

	if (config.hasSection("global", "maps")) {
		ValidationList msgs;
		map_global.setConfigDir(config_dir);
		ok = map_global.parse(config.getSection("global", "maps"), msgs) && ok;
		if (!msgs.empty())
			validation.push_back(std::make_pair("Global map configuration", msgs));
		if (!ok)
			return false;
	}

	auto sections = config.getSections();

	for (auto it = sections.begin(); it != sections.end(); ++it)
		if (it->getType() != "world" && it->getType() != "map"
				&& it->getNameType() != "global:worlds"
				&& it->getNameType() != "global:maps") {
			validation.push_back(std::make_pair("Section '" + it->getName() + "' with type '" + it->getType() + "'",
					makeValidationList(ValidationMessage::warning("Unknown section type!"))));
		}

	for (auto it = sections.begin(); it != sections.end(); ++it) {
		if (it->getType() != "world")
			continue;
		ValidationList msgs;
		WorldSection world = world_global;
		world.setGlobal(false);
		world.setConfigDir(config_dir);
		ok = world.parse(*it, msgs) && ok;

		if (hasWorld(it->getName())) {
			msgs.push_back(ValidationMessage::error("World name '" + it->getName() + "' already used!"));
			ok = false;
		} else
			worlds[it->getName()] = world;

		if (!msgs.empty())
			validation.push_back(std::make_pair("World section '" + it->getName() + "'", msgs));
	}

	for (auto it = sections.begin(); it != sections.end(); ++it) {
		if (it->getType() != "map")
			continue;
		ValidationList msgs;
		MapSection map = map_global;
		map.setGlobal(false);
		map.setConfigDir(config_dir);
		ok = map.parse(*it, msgs) && ok;

		if (hasMap(it->getName())) {
			msgs.push_back(ValidationMessage::error("Map name '" + it->getName() + "' already used!"));
			ok = false;
		} else if (map.getWorld() != "" && !hasWorld(map.getWorld())) {
			msgs.push_back(ValidationMessage::error("World '" + map.getWorld() + "' does not exist!"));
			ok = false;
		} else
			maps.push_back(map);

		if (!msgs.empty())
			validation.push_back(std::make_pair("Map section '" + it->getName() + "'", msgs));
	}

	return ok;
}