applicator.h

来自「ROSETTA C++库是一个C++类库和例程集合」· C头文件 代码 · 共 106 行

H
106
字号
//-------------------------------------------------------------------
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Revisions.....:
//===================================================================

#ifndef __APPLICATOR_H__
#define __APPLICATOR_H__

#include <copyright.h>

#include <kernel/algorithms/algorithm.h>

#include <kernel/structures/structure.h>

//-------------------------------------------------------------------
// Class.........: Applicator
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Applies an algorithm to a structure, using exceptions.
// Revisions.....:
//===================================================================

class Applicator {
protected:

	//- The objects....................................................
	Handle<Algorithm> algorithm_;
	Handle<Structure> structure_;

	//- Constructor....................................................
	Applicator();

public:

	//- Constructor....................................................
	Applicator(Algorithm *algorithm, Structure *structure);

	//- Application....................................................
  Structure *Apply();

};

//-------------------------------------------------------------------
// Methods for class Applicator (inlined).
//===================================================================

//-------------------------------------------------------------------
// Method........: Empty constructor
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Made protected in order to render it inaccessible.
// Revisions.....:
//===================================================================

inline
Applicator::Applicator() {
}

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

inline
Applicator::Applicator(Algorithm *algorithm, Structure *structure) {
	algorithm_ = algorithm;
	structure_ = structure;
}

//-------------------------------------------------------------------
// Method........: Apply
// Author........: Aleksander 豩rn
// Date..........:
// Description...: Applies the algorithm to the structure.  If the
//                 application fails, an exception is thrown.
// Comments......:
// Revisions.....:
//===================================================================

inline Structure *
Applicator::Apply() {

	if (algorithm_ == NULL)
		throw "Algorithm is NULL.";

	if (structure_ == NULL)
		throw "Structure is NULL.";

	Handle<Structure> result = structure_->Apply(*algorithm_);

	if (result == NULL)
		throw "Application failed.";

	return result.Release();

}

#endif

⌨️ 快捷键说明

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