|
From: <dhu...@us...> - 2006-12-02 16:14:52
|
Revision: 48
http://svn.sourceforge.net/qcell/?rev=48&view=rev
Author: dhubleizh
Date: 2006-12-02 08:14:41 -0800 (Sat, 02 Dec 2006)
Log Message:
-----------
- a masterpice in architecture
- GenericPlugin now does some checkups before the actual plugin does it's job
- interface.h updated with subtype for parsing
- KIParser finished - waiting only for generic world class
- other plugins need tweaking for the new API
Modified Paths:
--------------
trunk/qcell/baseheaders/GenericParserPlugin.h
trunk/qcell/baseheaders/interfaces.h
trunk/qcell/parsers/KI/KIParserPlugin.cpp
trunk/qcell/parsers/KI/KIParserPlugin.h
Modified: trunk/qcell/baseheaders/GenericParserPlugin.h
===================================================================
--- trunk/qcell/baseheaders/GenericParserPlugin.h 2006-12-01 17:27:34 UTC (rev 47)
+++ trunk/qcell/baseheaders/GenericParserPlugin.h 2006-12-02 16:14:41 UTC (rev 48)
@@ -22,6 +22,17 @@
/// A list defined by each plugin of supported file types
QStringList supported_file_types;
+ /**
+ * @brief Parser implemented by each individual plugin.
+ *
+ * @param content Content to parse
+ * @param type Type of parsing
+ * @param subtype Type of file to parse
+ *
+ * @return A an XML string with parsed data
+ */
+ virtual QString realParser(QByteArray content, QString type, QString subtype) = 0;
+
public:
/**
* @brief What types of parsing does this plugin do
@@ -55,6 +66,54 @@
}
}
+ QString parse(const QByteArray content, const QString type, const QString subtype="")
+ {
+ if(!supported_parser_types.contains(type))
+ {
+ // Constructing supported parser types
+ QString types;
+ for(int i =0 ; i < supported_parser_types.count()-1; i++)
+ {
+ types.append(supported_parser_types[i]);
+ types.append(',');
+
+ };
+ types.append(supported_parser_types.last());
+
+ qDebug(tr("This plugin doesn't support parsing of type %1. It supports %2.")
+ .arg(type)
+ .arg(types)
+ .toAscii()
+ );
+
+ return QString();
+ }
+ else if(!supported_file_types.contains(subtype)){
+
+ // Constructing supported file types
+ QString subtypes;
+ for(int i =0 ; i < supported_file_types.count()-1; i++)
+ {
+ subtypes.append(supported_file_types[i]);
+ subtypes.append(',');
+
+ };
+ subtypes.append(supported_file_types.last());
+
+ qDebug(tr("This plugin doesn't support parsing of type %1. It supports %2.")
+ .arg(type)
+ .arg(subtypes)
+ .toAscii()
+ );
+
+ return QString();
+
+ }
+
+ return realParser(content, type, subtype);
+
+ }
+
};
#endif
Modified: trunk/qcell/baseheaders/interfaces.h
===================================================================
--- trunk/qcell/baseheaders/interfaces.h 2006-12-01 17:27:34 UTC (rev 47)
+++ trunk/qcell/baseheaders/interfaces.h 2006-12-02 16:14:41 UTC (rev 48)
@@ -45,10 +45,11 @@
*
* @param content Data do parse
* @param type Parsing category type
+ * @param subtype File type to parse
*
* @return A xml string containing the parsed data in common format
*/
- virtual QString parse(const QByteArray content, const QString type) = 0;
+ virtual QString parse(const QByteArray content, const QString type, const QString subtype) = 0;
};
Q_DECLARE_INTERFACE(ParserInterface,
Modified: trunk/qcell/parsers/KI/KIParserPlugin.cpp
===================================================================
--- trunk/qcell/parsers/KI/KIParserPlugin.cpp 2006-12-01 17:27:34 UTC (rev 47)
+++ trunk/qcell/parsers/KI/KIParserPlugin.cpp 2006-12-02 16:14:41 UTC (rev 48)
@@ -16,28 +16,20 @@
}
/// @todo Incorporate genreal Function file to output resulting XML
-QString KIParserPlugin::parse(const QByteArray content, const QString type)
+QString KIParserPlugin::realParser(const QByteArray content, const QString type, const QString subtype)
{
QStringList lines;
// Used to doublecheck the format of a line in file
QRegExp format;
// To be able to print the line in which some error occured
- int line_nr = 1;
+ int line_nr,columnt_nr;
+ line_nr = 1;
// Parameters from the file header
+ // The real world holder
+ // As this file type has no header, we have absolutely no idea of how many
+ // dimensions and how large it is, so we need to track counts
+ QVector<QVector<QVector <int> > > world;
- // If we're asked by accident to parse a file not supported by the plugin
- /// @todo redefine it the 'new' way
-// if(type != FQT_PARSER_TYPE)
-// {
-// qDebug(tr("The pluginn has been asked to parse a file type (%1) different from declared one (%2).")
-// .arg(type)
-// .arg(FQT_PARSER_TYPE)
-// .toAscii()
-// );
-//
-// return QString();
-// }
-
// Basic sanity check
lines = QString(content).split('\n');
if(lines.count() < 1)
@@ -45,6 +37,50 @@
qDebug(tr("The input file is to short!").toAscii());
return QString();
}
+
+ // Allowed signs in file
+ format.setPattern("[\\-a-Z0-9]");
+ // Append first wall (well - a 1D world has one wall in a 3D thinking fasion)
+ world.append(QVector<QVector <int> >());
+ foreach(QString line, lines)
+ {
+ // When there's nothing in a line it is a wall seperator
+ if(line.length()==0)
+ {
+ world.append(QVector<QVector <int> >());
+ }
+ else {
+
+ // A new verse for each line
+ world.last().append(QVector<int>());
+ // Reset columnt ocunter for each line
+ columnt_nr = 1;
+
+ foreach(QChar sign, line)
+ {
+ if(!format.exactMatch(sign))
+ {
+ qDebug(tr("The sign in line %1 column %2 is wrong. It should be in range of %3.")
+ .arg(line_nr)
+ .arg(columnt_nr)
+ .toAscii()
+ );
+
+ return QString();
+ }
+
+ // The real adding
+ world.last().last().append(sign.toAscii() - '0');
+
+ // Keep track of columnt nr
+ columnt_nr++;
+ }
+
+ }
+
+ // Keep track of line nr
+ line_nr++;
+ }
}
Q_EXPORT_PLUGIN2(KIFileParser, KIParserPlugin)
Modified: trunk/qcell/parsers/KI/KIParserPlugin.h
===================================================================
--- trunk/qcell/parsers/KI/KIParserPlugin.h 2006-12-01 17:27:34 UTC (rev 47)
+++ trunk/qcell/parsers/KI/KIParserPlugin.h 2006-12-02 16:14:41 UTC (rev 48)
@@ -17,10 +17,12 @@
class KIParserPlugin : public GenericParserPlugin
{
+protected:
+ QString realParser(QByteArray content, QString type, QString subtype);
+
public:
KIParserPlugin();
- QString parse(const QByteArray content, const QString type);
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|