📄 ruleexporter.cpp
字号:
//-------------------------------------------------------------------
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Revisions.....:
//===================================================================
#include <stdafx.h> // Precompiled headers.
#include <copyright.h>
#include <kernel/algorithms/ruleexporter.h>
#include <kernel/structures/rules.h>
#include <kernel/basic/message.h>
#include <kernel/system/fstream.h>
//-------------------------------------------------------------------
// Methods for class RuleExporter.
//===================================================================
//-------------------------------------------------------------------
// Constructors/destructor.
//===================================================================
RuleExporter::RuleExporter() {
}
RuleExporter::~RuleExporter() {
}
//-------------------------------------------------------------------
// Methods inherited from Identifier.
//===================================================================
IMPLEMENTIDMETHODS(RuleExporter, RULEEXPORTER, Exporter)
//-------------------------------------------------------------------
// Methods inherited from Algorithm.
//===================================================================
//-------------------------------------------------------------------
// Method........: IsApplicable
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================
bool
RuleExporter::IsApplicable(const Structure &structure, bool /*warn*/) const {
return structure.IsA(RULES);
}
//-------------------------------------------------------------------
// Methods inherited from Exporter.
//===================================================================
//-------------------------------------------------------------------
// Method........: ExportPrologue
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......: Merge code with ReductExporter.
// Revisions.....:
//===================================================================
bool
RuleExporter::ExportPrologue(ofstream &stream, const Structure &structure) const {
return Exporter::ExportPrologue(stream, structure);
}
//-------------------------------------------------------------------
// Method........: ExportData
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================
bool
RuleExporter::ExportData(ofstream &stream, const Structure &structure) const {
Message message;
bool ok = true;
// We may have to update some mutable stuff.
RuleExporter *self = const_cast(RuleExporter *, this);
// Cast to type verified in Apply method.
Handle<Rules> rules = dynamic_cast(Rules *, const_cast(Structure *, &structure));
// Get originating decision table, if any.
Handle<DecisionTable> table = dynamic_cast(DecisionTable *, rules->FindParent(DECISIONTABLE));
bool masked = true;
self->no_objects_ = table->GetNoObjects(masked);
self->decisions_.erase(self->decisions_.begin(), self->decisions_.end());
self->cardinalities_.erase(self->cardinalities_.begin(), self->cardinalities_.end());
// Fill decision/cardinality vectors, if possible.
if (table != NULL)
table->GetValueSet(self->decisions_, self->cardinalities_, table->GetDecisionAttribute(masked), masked);
int i, no_rules = rules->GetNoRules();
// Do the actual exporting.
for (i = 0; i < no_rules; i++) {
if (!message.Progress("Exporting rules...", i, no_rules))
break;
Handle<Rule> rule = rules->GetRule(i);
// Export the rule (format specifics are overloaded).
if (!ExportRule(stream, i, *rule)) {
Message::Error("Failed to export rule.");
ok = false;
break;
}
}
// Make sure all windows are popped down.
/*
if (!ok)
Message::Reset();
*/
return ok;
}
//-------------------------------------------------------------------
// Method........: ExportEpilogue
// Author........: Aleksander 豩rn
// Date..........:
// Description...:
// Comments......:
// Revisions.....:
//===================================================================
bool
RuleExporter::ExportEpilogue(ofstream &stream, const Structure &structure) const {
return Exporter::ExportEpilogue(stream, structure);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -