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

📄 rsesinformationvector.cpp

📁 粗慥集成算法集合 ,并有详细的文档资料和测试数据处
💻 CPP
字号:
//-------------------------------------------------------------------
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Revisions.....:
//===================================================================

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

#include <kernel/rses/structures/rsesinformationvector.h>

#include <kernel/rses/library/tdobject.h>
#include <kernel/rses/library/err.h>

//-------------------------------------------------------------------
// Methods for class RSESInformationVector.
//===================================================================

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

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

RSESInformationVector::RSESInformationVector(const RSESInformationVector &in) : InformationVector(in) {

	// Create a virgin RSES object.
	try {
		inf_ = new TDObject(0);
	}
	catch (Error &error) {
		Message::RSESError("Error creating RSES information vector.", error.GetMessage());
		inf_ = NULL;
		return;
	}

	// Copy the input object.
	try {
		*inf_ = *(in.inf_);
	}
	catch (Error &error) {
		Message::RSESError("Error copying RSES information vector.", error.GetMessage());
	}

	// We own the objects we create.
	is_owner_ = true;

}

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

RSESInformationVector::RSESInformationVector() {

	// Create a virgin RSES object.
	try {
		inf_ = new TDObject(0);
	}
	catch (Error &error) {
		Message::RSESError("Error creating RSES information vector.", error.GetMessage());
		inf_ = NULL;
	}

	is_owner_ = true;

}

//-------------------------------------------------------------------
// Method........: Constructor.
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Constructs an inf. vector of the given size.
//                 All entries are set undefined.
// Comments......:
// Revisions.....:
//===================================================================

RSESInformationVector::RSESInformationVector(int size) {

	int i;

	// Create a virgin RSES object and modify it slightly.
	try {
		inf_ = new TDObject(size);
		for (i = 0; i < size; i++)
			(*inf_)[i] = Undefined::Integer();
	}
	catch (Error &error) {
		Message::RSESError("Error creating RSES information vector.", error.GetMessage());
		inf_ = NULL;
	}

	is_owner_ = true;

}

//-------------------------------------------------------------------
// Method........: Destructor.
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Only delete the embedded object if we own it.
// Revisions.....:
//===================================================================

RSESInformationVector::~RSESInformationVector() {
	if (is_owner_)
		delete inf_;
}

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

IMPLEMENTIDMETHODS(RSESInformationVector, RSESINFORMATIONVECTOR, InformationVector)

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

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

//-------------------------------------------------------------------
// Methods inherited from InformationVector.
//===================================================================

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

int
RSESInformationVector::GetNoAttributes() const {

#ifdef _DEBUG
	if (inf_ == NULL) {
		Message::Debug("RSES inf. vector is NULL.");
		return 0;
	}
#endif

	try {
		return inf_->GetLen();
	}
	catch (Error &error) {
		Message::RSESError("Error accessing RSES inf. vector.", error.GetMessage());
		return Undefined::Integer();
	}

}

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

int
RSESInformationVector::GetEntry(int attribute_no) const {

#ifdef _DEBUG
	if ((attribute_no < 0) || (attribute_no >= GetNoAttributes())) {
		Message::Error("Index out of range.");
		return Undefined::Integer();
	}
#endif

	try {
		return (*inf_)[attribute_no];
	}
	catch (Error &error) {
		Message::RSESError("Error accessing RSES inf. vector.", error.GetMessage());
		return Undefined::Integer();
	}

}

//-------------------------------------------------------------------
// Method........: SetEntry
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Consider testing for ownership.
// Revisions.....:
//===================================================================

bool
RSESInformationVector::SetEntry(int attribute_no, int value) {

#ifdef _DEBUG
	if ((attribute_no < 0) || (attribute_no >= GetNoAttributes())) {
		Message::Error("Index out of range.");
		return false;
	}
#endif

	try {
		(*inf_)[attribute_no] = value;
	}
	catch (Error &error) {
		Message::RSESError("Error accessing RSES inf. vector.", error.GetMessage());
		return false;
	}

	return true;

}

//-------------------------------------------------------------------
// Method........: InsertAttribute
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Tests for ownership.
// Revisions.....:
//===================================================================

bool
RSESInformationVector::InsertAttribute(int attribute_no) {

#ifdef _DEBUG
	if (inf_ == NULL) {
		Message::Debug("RSES inf. vector is NULL.");
		return false;
	}
#endif

	// Test for ownership.
	if (!is_owner_)
		return false;

	try {
		inf_->InsertPos(attribute_no);
		(*inf_)[attribute_no] = Undefined::Integer();
	}
	catch (Error &error) {
		Message::RSESError("Error inserting attribute into RSES inf. vector.", error.GetMessage());
		return false;
	}

	return true;

}

//-------------------------------------------------------------------
// Method........: RemoveAttribute
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Tests for ownership.
// Revisions.....:
//===================================================================

bool
RSESInformationVector::RemoveAttribute(int attribute_no) {

#ifdef _DEBUG
	if (inf_ == NULL) {
		Message::Debug("RSES inf. vector is NULL.");
		return false;
	}
#endif

	// Test for ownership.
	if (!is_owner_)
		return false;

	try {
		inf_->RemovePos(attribute_no);
	}
	catch (Error &error) {
		Message::RSESError("Error removing attribute from RSES inf. vector.", error.GetMessage());
		return false;
	}

	return true;

}

⌨️ 快捷键说明

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