mydecisiontableexporter.cpp

来自「The ROSETTA C++ library is a collection 」· C++ 代码 · 共 132 行

CPP
132
字号
//-------------------------------------------------------------------// Author........: Aleksander 豩rn// Date..........:// Description...:// Revisions.....://===================================================================#include <stdafx.h> // Precompiled headers.#include <copyright.h>#include <kernel/algorithms/mydecisiontableexporter.h>#include <kernel/structures/decisiontable.h>#include <kernel/structures/informationvector.h>#include <kernel/system/fstream.h>//-------------------------------------------------------------------// Methods for class MyDecisionTableExporter.//===================================================================//-------------------------------------------------------------------// Constructors/destructor.//===================================================================MyDecisionTableExporter::MyDecisionTableExporter() {}MyDecisionTableExporter::~MyDecisionTableExporter() {}//-------------------------------------------------------------------// Methods inherited from Identifier.//===================================================================IMPLEMENTIDMETHODS(MyDecisionTableExporter, MYDECISIONTABLEEXPORTER, DecisionTableExporter)//-------------------------------------------------------------------// Methods inherited from Exporter.//===================================================================//-------------------------------------------------------------------// Method........: ExportPrologue// Author........: Aleksander 豩rn// Date..........:// Description...:// Comments......:// Revisions.....://===================================================================boolMyDecisionTableExporter::ExportPrologue(ofstream &stream, const Structure &structure) const {	// Cast to already verified type (in Apply method).	Handle<DecisionTable> table = dynamic_cast(DecisionTable *, const_cast(Structure *, &structure));	bool masked = false;	int i;	int no_objects    = table->GetNoObjects(masked);	int no_attributes = table->GetNoAttributes(masked);	// Write some general information.	stream << "% Exported " << SystemKit::GetTimestamp() << " from ROSETTA by " << SystemKit::GetUser() << "." << endl;	stream << "%" << endl;	stream << "% " << table->GetName() << endl;	stream << "%" << endl;	stream << "% " << no_objects << " objects, " << no_attributes << " attributes." << endl;	stream << endl;	// Write attribute names, possibly padded.	for (i = 0; i < no_attributes; i++) {		String name = table->GetAttributeName(i, masked);		if (name.Contains(' ') || name.Contains('\t') || name.Contains(','))			name = '\"' + name + '\"';		stream << name;		if (i < no_attributes - 1)			stream << '\t';		else			stream << endl;	}	// Write attribute types, possibly with exponent fields.	for (i = 0; i < no_attributes; i++) {		String type = Attribute::GetString(table->GetAttributeType(i, masked));		if (table->IsFloat(i, masked))			type += '(' + String::Format(table->GetAttributeScalingExponent(i, masked)) + ')';		stream << type;		if (i < no_attributes - 1)			stream << '\t';		else			stream << endl;	}	return true;}//-------------------------------------------------------------------// Methods inherited from DecisionTableExporter.//===================================================================//-------------------------------------------------------------------// Method........: ExportInformationVector// Author........: Aleksander 豩rn// Date..........:// Description...:// Comments......:// Revisions.....://===================================================================boolMyDecisionTableExporter::ExportInformationVector(ofstream &stream, const DecisionTable &table, int object_no, bool masked) const {	int i, no_attributes = table.GetNoAttributes(masked);	// Save textual entries, possibly padded.	for (i = 0; i < no_attributes; i++) {		String entry = table.GetEntry(object_no, i, true, masked);		if (entry.Contains(' ') || entry.Contains('\t') || entry.Contains(','))			entry = '\"' + entry + '\"';		stream << entry;		if (i < no_attributes - 1)			stream << '\t';		else			stream << endl;	}	return true;}

⌨️ 快捷键说明

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