$res=$this->select($tab,"*","1=1");
foreach($res as $row){
foreach($cols as $col){
+ if(!array_key_exists($col,$row))continue;
$val=$row[$col];
$ret.="value $col ".$this->escapeBackup($tab,$col,$val)."\n";
}
class WObject {
protected function __construct(){}
+
+ ///base for deserialization
+ static protected function fromXmlHelper($data,$xml,$elem){}
+
+ ///base for serialization
+ protected function toXmlHelper($xml,$root){}
+
+ ///base for property array
+ public function propertyArray(){return array();}
/**helper function that returns only the elements directly beneith the one given as $root*/
public static function elementsByTagName($root,$tag)
{
protected:
WObject(){}
+ WObject(const WObject&){}
+ WObject(const QDomElement&){}
+ virtual ~WObject(){}
+ virtual QDomElement toXml(QDomDocument&,QString name="Object");
+ virtual WObject& operator=(const WObject&){return *this;}
+ virtual void toXml(QDomDocument&,QDomElement&){}
};
/**this exception is thrown if the deserialization of an object fails on the XML parser level*/
#include "WObject"
-//do at least something useful
#include "Nullable"
+#include <QDomDocument>
+
+QDomElement WObject::toXml(QDomDocument&doc,QString name)
+{
+ return doc.createElement(name);
+}
static int itype0=
qRegisterMetaType<Nullable<qint32> >()+
{
QString code;
QStringList k=cls.propertyNames();
- code+="public function propertyArray(){\n\treturn array(";
+ code+="public function propertyArray(){\n\treturn array_merge(parent::propertyArray(),array(";
for(int i=0;i<k.size();i++){
if(i)code+=",";
code+="\n\t\t\""+k[i]+"\"=>";
code+="$this->prop_"+k[i];
}
}
- code+=");\n}\n";
+ code+="));\n}\n";
return code;
}
//toXml function:
code+="public function toXml($xml,$elementname=\""+cls.name()+"\"){\n";
code+="\t$root=$xml->createElement($elementname);\n";
+ code+="\t$this->toXmlHelper($xml,$root);\n";
+ code+="\treturn $root;\n}\n";
+ //toXmlHelper function:
+ code+="protected function toXmlHelper($xml,$root){\n";
+ code+="\tparent::toXmlHelper($xml,$root);\n";
//add properties
QStringList p=cls.propertyNames();
for(int j=0;j<p.size();j++)
code+=propertyToXml(cls,p[j]);
- //return result
- code+="\treturn $root;\n}\n";
+ code+="}\n";
return code;
}
code+="\n\t\tthrow WobXmlException(translate(\""+abstractClassName(cls)+"\",\"Unable to deserialize object of type "+className(cls)+": invalid XML.\"));";
code+="\n\treturn self::fromXml($xml,$xml->documentElement);\n}\n";
code+="static public function fromXml($xml,$elem){\n\t$data=new "+className(cls)+"();\n";
+ code+="\treturn $data;\n}\n";
+ code+="static protected function fromXmlHelper($data,$xml,$elem){\n";
+ code+="\tparent::fromXmlHelper($data,$xml,$elem);\n";
k=cls.propertyNames();
for(int i=0;i<k.size();i++){
//scan properties
}
}
}
- code+="\treturn $data;\n}\n";
+ code+="}\n";
return code;
}
QString hcd;
QString scd;
//includes
- hcd="#include \""+cls.baseClass(m_lang,m_prefix)+"\"\n#include <QCoreApplication>\n\n";
+ hcd="#include \""+cls.baseClass(m_lang,m_prefix+"O")+"\"\n#include <QCoreApplication>\n\n";
QStringList k=cls.propertyNames();
for(int i=0;i<k.size();i++)
if(cls.propertyIsObject(k[i]))
hcd+="#include \""+m_prefix+"O"+cls.propertyPlainType(k[i])+"\"\n";
//class declaration
- hcd+="class "+cna+":public "+cls.baseClass(m_lang,m_prefix)+"\n{\n Q_OBJECT\n";
+ QString cnb=cls.baseClass(m_lang,m_prefix+"O");
+ hcd+="class "+cna+":public "+cnb+"\n{\n Q_OBJECT\n";
hdr.write(hcd.toAscii());
//enums
QString hcd,scd;
hcd=" public:\n";
//this is needed to allow WObjects to be Nullable and some other operations...
- hcd+="\t"+cn+"(){}\n";
+ QString cnb=cls.baseClass(m_lang,m_prefix+"O");
+ hcd+="\t"+cn+"():"+cnb+"(){}\n";
//implement copiers
QStringList k=cls.propertyNames();
hcd+="\t"+cn+"(const "+cn+"&);\n";
- scd+=cn+"::"+cn+"(const "+cn+"&o)\n\t:WObject()\n{\n";
+ scd+=cn+"::"+cn+"(const "+cn+"&o)\n\t:"+cnb+"(o)\n{\n";
for(int i=0;i<k.size();i++)
scd+="\tmp_"+k[i]+"=o.mp_"+k[i]+";\n";
scd+="}\n";
hcd+="\t"+cn+"& operator=(const "+cn+"&);\n";
scd+=cn+"& "+cn+"::operator=(const "+cn+"&o)\n{\n";
+ scd+="\t"+cnb+"::operator=(o);\n";
for(int i=0;i<k.size();i++)
scd+="\tmp_"+k[i]+"=o.mp_"+k[i]+";\n";
scd+="\treturn *this;\n}\n";
//implement deserializer (as constructor)
hcd+="\t"+cn+"(const QDomElement&);\n";
- scd+=cn+"::"+cn+"(const QDomElement&root)\n\t:WObject()\n{\n";
+ scd+=cn+"::"+cn+"(const QDomElement&root)\n\t:"+cnb+"(root)\n{\n";
scd+="\tQList<QDomElement> nl;\n";
for(int i=0;i<k.size();i++){
if(cls.propertyIsList(k[i])){
scd+="\tQDomDocument doc;\n\tdoc.appendChild(toXml(doc));\n";
scd+="\treturn doc.toString();\n}\n";
hcd+="\tQDomElement toXml(QDomDocument&,QString name=\""+cls.name()+"\");\n";
+ hcd+="\tvoid toXml(QDomDocument&,QDomElement&);\n";
scd+="QDomElement "+cn+"::toXml(QDomDocument&doc,QString name)\n{\n";
- scd+="\tQDomElement r=doc.createElement(name);\n";
+ scd+="\tQDomElement r=doc.createElement(name);\n\ttoXml(doc,r);\n";
+ scd+="\treturn r;\n}\n";
+ scd+="void "+cn+"::toXml(QDomDocument&doc,QDomElement&r)\n{\n";
+ scd+="\t"+cls.baseClass(m_lang,m_prefix+"O")+"::toXml(doc,r);\n";
QStringList p=cls.propertyNames();
for(int j=0;j<p.size();j++){
QStringList pv=p[j].split("/",QString::SkipEmptyParts);
scd+="\t}\n";
}
}
- scd+="\treturn r;\n}\n";
+ scd+="\n}\n";
hdr.write(hcd.toAscii());
src.write(scd.toAscii());
}