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


C++ Store::asRack方法代码示例

本文整理汇总了C++中Store::asRack方法的典型用法代码示例。如果您正苦于以下问题:C++ Store::asRack方法的具体用法?C++ Store::asRack怎么用?C++ Store::asRack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Store的用法示例。


在下文中一共展示了Store::asRack方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getAllStores

void StoresManagementSystem::getAllStores(StoreIndex const &index, std::vector<Store::RefT> &stores) const {
	assert(index.isHardpoint());
	Store *store = index.valid() ? m_Hardpoints.at(index.hardpoint())->getStore() : 0;
	if (store) {
		stores.push_back(store);
		if(store->asRack()) store->asRack()->getChildren(stores, true);
	}
}
开发者ID:nsmoooose,项目名称:csp,代码行数:8,代码来源:StoresManagementSystem.cpp

示例2: mountStore

bool StoresManagementSystem::mountStore(StoreIndex const &index, Store *store) {
	assert(store && index.valid());
	if (index.isHardpoint()) {
		return m_Hardpoints.at(index.hardpoint())->mountStore(store);
	}
	Hardpoint *hp = m_Hardpoints.at(index.hardpoint()).get();
	assert(hp);
	if (!hp->data()->isCompatible(store->key())) {
		CSPLOG(INFO, OBJECT) << "store " << store->name() << " incompatible with hardpoint " << hp->name();
		return false;
	}
	Store *parent = hp->getStore(index.parent());
	if (!parent || !parent->asRack()) {
		CSPLOG(INFO, OBJECT) << "cannot mount store " << store->name() << "; mount point not found on hardpoint " << hp->name();
		return false;
	}
	return parent->asRack()->setChild(index, store);
}
开发者ID:nsmoooose,项目名称:csp,代码行数:18,代码来源:StoresManagementSystem.cpp

示例3: loadStores

// FIXME the implementation leaves a bit to be desired; it works reasonably well and provides
// a simple interface to a complex selection process, but hopefully the code can be cleaned up
// and simplified a bit.  note also that this method neglects inventory constraints (although
// this probably won't be possible until a campaign system is implemented).
// the caller must call setDirtyDynamics() and signalConfiguration() afterward (multiple
// updates should be batched before calling the latter).
bool StoresManagementSystem::loadStores(StoreIndex const &idx, Key const &store, unsigned count) {
	if (!idx.isHardpoint() || count < 1) return false;
	Hardpoint *hp = m_Hardpoints.at(idx.hardpoint()).get(); assert(hp);
	HardpointData const *data = hp->data();

	// before we do a lot of work, make sure the hardpoint supports this store.
	if (!data->isCompatible(store)) return false;

	StoresDatabase &db = StoresDatabase::getInstance();

	// existing pylon?
	//   - yes: existing, compatible rack?
	//          - yes: mount on rack
	//          - no : can mount directly on pylon?
	//                 -yes: mount on pylon
	//                 -no : add prefered rack, mount on rack
	//   - no: add compatble pylon
	//   - repeat: as above

	StoreData const *store_data = db.getStoreData(store);
	if (!store_data) return false;

	bool add_pylon = false;
	Rack::RefT pylon;
	Store *existing_store = hp->getStore();
	if (existing_store) {
		pylon = existing_store->asRack();
		if (!pylon) return false;
	}

	// if no existing pylon, we are fairly unconstrained (and hence have to do the most work).
	if (!pylon) {
		// simplest case: a single store can be mounted directly on the hardpoint.
		if (data->isMountCompatible(store) && count == 1) {
			Store::RefT instance = db.getStore(store);
			return instance.valid() && mountStore(idx, instance.get());
		}

		// otherwise we'll need a pylon, so find the best.
		StoreSet mountable;
		data->getMountCompatibleStores(mountable);

		// get all possible racks and pylons.
		StoreSet const *tmp = db.getCompatibleRacks(store);
		assert(tmp);
		StoreSet racks;  // racks of racks
		db.getCompatibleRacks(*tmp, racks);
		racks.insert(tmp->begin(), tmp->end());

		// find the best rack/stack to use as a pylon
		std::vector<Key> const &pylons = data->preferredRacks();
		for (unsigned i = 0; i < pylons.size(); ++i) {
			if (racks.count(pylons[i]) > 0) {
				Store::RefT s = db.getStore(pylons[i]);
				pylon = !s ? 0 : s->asRack();
				break;
			}
		}

		// if there isn't a preferred pylon, choose the first one that is compatible.
		if (!pylon) {
			for (StoreSet::const_iterator iter = racks.begin(); iter != racks.end(); ++iter) {
				if (data->isMountCompatible(*iter)) {
					Store::RefT s = db.getStore(*iter);
					pylon = !s ? 0 : s->asRack();
					break;
				}
			}
			if (!pylon) return false;
		}

		add_pylon = true;
	}

	Rack::RefT rack = pylon;

	// now we have a mounted pylon that we know will work!  if possible, mount the
	// store(s) directly on the pylon.  otherwise we need to use existing racks or
	// add our own.
	unsigned pylon_capacity = pylon->availableSpace(store);
	if (pylon_capacity < count) {
		// first check for existing capacity.
		unsigned capacity = 0;
		for (unsigned i = 0; i < pylon->getNumChildren(); ++i) {
			Store *child = pylon->getChild(i);
			if (child && child->asRack()) {
				capacity += child->asRack()->availableSpace(store);
				if (capacity >= count) break;
			}
		}

		// if not enough space, try to add racks
		if (capacity < count) {
			// first find suitable racks
//.........这里部分代码省略.........
开发者ID:nsmoooose,项目名称:csp,代码行数:101,代码来源:StoresManagementSystem.cpp


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