?? rsesinformationvector.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 + -