⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 equivalenceclass.cpp

📁 粗糙集应用软件
💻 CPP
字号:
//-------------------------------------------------------------------
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Revisions.....:
//===================================================================

#include <stdafx.h> // Precompiled headers.
#include <copyright.h>

#include <kernel/structures/equivalenceclass.h>

#include <kernel/utilities/iokit.h>

#include <kernel/basic/algorithm.h>

//-------------------------------------------------------------------
// Methods for class EquivalenceClass.
//===================================================================

//-------------------------------------------------------------------
// Constructors/destructor.
//===================================================================

//-------------------------------------------------------------------
// Method........: Copy constructor.
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================

EquivalenceClass::EquivalenceClass(const EquivalenceClass &in) : Structure(in) {
	objects_ = in.objects_;
}

//-------------------------------------------------------------------
// Method........: Constructor.
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================

EquivalenceClass::EquivalenceClass() {
}

EquivalenceClass::EquivalenceClass(int size) {
	objects_.reserve(size);
}

//-------------------------------------------------------------------
// Method........: Destructor.
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================

EquivalenceClass::~EquivalenceClass() {
}

//-------------------------------------------------------------------
// Methods inherited from Identifier.
//===================================================================

IMPLEMENTIDMETHODS(EquivalenceClass, EQUIVALENCECLASS, Structure)

//-------------------------------------------------------------------
// Methods inherited from Persistent.
//===================================================================

//-------------------------------------------------------------------
// Method........: Load
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================

bool
EquivalenceClass::Load(ifstream &stream) {

	// Clear present representation.
	Clear();

	int i, no_objects, object_no;

	// Load cardinality.
	if (!IOKit::Load(stream, no_objects))
		return false;

	// Load and add set members.
	for (i = 0; i < no_objects; i++) {
		if (!IOKit::Load(stream, object_no) || !InsertObject(object_no))
			return false;
	}

	return true;

}

//-------------------------------------------------------------------
// Method........: Save
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================

bool
EquivalenceClass::Save(ofstream &stream) const {

	int i, no_objects = GetNoObjects();

	// Save cardinality.
	if (!IOKit::Save(stream, no_objects))
		return false;

	if (!IOKit::Save(stream, '\n'))
		return false;

	// Save set members.
	for (i = 0; i < no_objects; i++) {
		if (!IOKit::Save(stream, GetObject(i)))
			return false;
	}

	if (!IOKit::Save(stream, '\n'))
		return false;

	return true;

}

//-------------------------------------------------------------------
// Methods inherited from Structure.
//===================================================================

//-------------------------------------------------------------------
// Method........: Duplicate
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================

Structure *
EquivalenceClass::Duplicate() const {
  return new EquivalenceClass(*this);
}

//-------------------------------------------------------------------
// Method........: Clear
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================

void
EquivalenceClass::Clear() {
	objects_.erase(objects_.begin(), objects_.end());
}

//-------------------------------------------------------------------
// Local methods.
//===================================================================

//-------------------------------------------------------------------
// Method........: GetNoObjects
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Returns the number of objects in the eq. class.
// Comments......:
// Revisions.....:
//===================================================================

int
EquivalenceClass::GetNoObjects() const {
	return objects_.size();
}

//-------------------------------------------------------------------
// Method........: GetObject
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Returns the object in the eq. class in the given
//                 position.
// Comments......:
// Revisions.....:
//===================================================================

int
EquivalenceClass::GetObject(int position_no) const {
	return objects_[position_no];
}

//-------------------------------------------------------------------
// Method........: InsertObject
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Adds a new member (i.e. object index) to the
//                 eq. class.
//
//                 Keeps the vector sorted and unique.
//
// Comments......: Multiple inserts are not accepted.
// Revisions.....: A

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -