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


C++ Floor::GetId方法代码示例

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


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

示例1: RequestFloor

void Person::RequestFloor(Environment &env) {

	Floor *next = path_.front();

	if (!next) {
		std::ostringstream oss("Invalid operation: no next floor in path ", std::ostringstream::ate);
		oss << "ID of person: <" << GetId();
		oss << ", this error should never occur.";
		throw std::runtime_error(oss.str());
	}

	for (int i = 0; i < elevator_->GetInterfaceCount(); ++i) {

		Interface *interf = elevator_->GetInterface(i);
		Floor *floor = static_cast<Floor*>(interf->GetLoadable(0));

		if (floor == next) {
			action_ = env.SendEvent("Interface::Interact", 3, this, elevator_->GetInterface(i));

			return;
		}
	}

	std::ostringstream oss("Invalid operation: ", std::ostringstream::ate);
	oss << elevator_->GetName() << " can not go to Floor " << next->GetId();
	oss << ", this error should never occur.";
	throw std::runtime_error(oss.str());
}
开发者ID:ChrisDue,项目名称:Elevator,代码行数:28,代码来源:Person.cpp

示例2: RequestElevator

void Person::RequestElevator(Environment &env, int time) {

	if (current_ == final_)
		return;

	Floor *next = path_.front();

	if (!next) {
		std::ostringstream oss("Invalid operation: no next floor in path ", std::ostringstream::ate);
		oss << "ID of person: <" << GetId();
		oss << ", this error should never occur.";
		throw std::runtime_error(oss.str());
	}

	for (int i = 0; i < current_->GetInterfaceCount(); ++i) {

		Interface *interf = current_->GetInterface(i);
		Elevator *ele = static_cast<Elevator*>(interf->GetLoadable(0));

		if (ele->HasFloor(next)) {

			requested_ = current_->GetInterface(i);
			env.SendEvent("Interface::Interact", time - env.GetClock(), this, requested_);

			return;
		}
	}

	std::ostringstream oss("Invalid operation: no elevator available to go from Floor ", std::ostringstream::ate);
	oss << current_->GetId() << " to Floor " << next->GetId();
	oss << ", this error should never occur.";
	throw std::runtime_error(oss.str());
}
开发者ID:ChrisDue,项目名称:Elevator,代码行数:33,代码来源:Person.cpp

示例3: Validate

void Elevator::Validate() {

	Entity::Validate();

	if (speed_ <= 0) {
		std::ostringstream oss("Speed of ", std::ostringstream::ate);
		oss << GetName() << " must be positive.";
		throw TestfileException(oss.str());
	}

	if (load_ < 10) {
		std::ostringstream oss("Maximum load of ", std::ostringstream::ate);
		oss << GetName() << " must be greater or equal to 10.";
		throw TestfileException(oss.str());
	}

	if (!current_) {
		std::ostringstream oss("Starting floor of ", std::ostringstream::ate);
		oss << GetName() << " is null.";
		throw TestfileException(oss.str());
	}

	if (current_->GetType() != "Floor") {
		std::ostringstream oss("Starting floor of ", std::ostringstream::ate);
		oss << GetName() << " does not reference a floor object.";
		throw TestfileException(oss.str());
	}

	if (count_ < 2) {
		std::ostringstream oss("", std::ostringstream::ate);
		oss << GetName() << " must have at least 2 interfaces.";
		throw TestfileException(oss.str());
	}

	std::set<Interface*> unique;

	Floor *lowest = nullptr;
	Floor *highest = nullptr;

	for (int i = 0; i < count_; ++i) {

		Interface *interf = interfs_[i];

		if (!interf) {
			std::ostringstream oss("An interface of ", std::ostringstream::ate);
			oss << GetName() << " is null.";
			throw TestfileException(oss.str());
		}

		if (unique.count(interf)) {
			std::ostringstream oss("Interfaces used by ", std::ostringstream::ate);
			oss << GetName() << " are not unique.";
			throw TestfileException(oss.str());
		}
		unique.insert(interf);

		if (interf->GetType() != "Interface") {
			std::ostringstream oss("Interface ", std::ostringstream::ate);
			oss << interf->GetId() << " of ";
			oss << GetName() << " is not an interface object.";
			throw TestfileException(oss.str());
		}

		if (interf->GetLoadableCount() != 1) {
			std::ostringstream oss("", std::ostringstream::ate);
			oss << interf->GetName() << " of ";
			oss << GetName() << " must reference exactly one object.";
			throw TestfileException(oss.str());
		}

		Loadable *loadable = interf->GetLoadable(0);

		if (!loadable) {
			std::ostringstream oss("Referenced object of ", std::ostringstream::ate);
			oss << interf->GetName() << " of ";
			oss << GetName() << " is null.";
			throw TestfileException(oss.str());
		}

		if (loadable->GetType() != "Floor") {
			std::ostringstream oss("Referenced object of ", std::ostringstream::ate);
			oss << interf->GetName() << " of ";
			oss << GetName() << " must be an floor object.";
			throw TestfileException(oss.str());
		}

		Floor *floor = static_cast<Floor*>(loadable);

		if (!floor->HasElevator(this)) {
			std::ostringstream oss("Floor ", std::ostringstream::ate);
			oss << floor->GetId() << " referenced by ";
			oss << interf->GetName() << " of ";
			oss << GetName() << " does not point back to the elevator.";
			throw TestfileException(oss.str());
		}

		if (!lowest)
			lowest = floor;
		else if (lowest->IsBelow(floor)) {
			lowest = floor;
//.........这里部分代码省略.........
开发者ID:ChrisDue,项目名称:Elevator,代码行数:101,代码来源:Elevator.cpp


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