fix inheritance of classes
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 24 Dec 2010 22:21:46 +0000 (22:21 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Fri, 24 Dec 2010 22:21:46 +0000 (22:21 +0000)
git-svn-id: https://silmor.de/svn/softmagic/pack/trunk@668 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33

phpbase/db.php
phpbase/object.php
qtbase/include/object.h
qtbase/src/object.cpp
woc/php/phpclass.cpp
woc/qt/qtclass.cpp

index 3709102..becc0e9 100644 (file)
@@ -477,6 +477,7 @@ abstract class DbEngine
                        $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";
                                }
index ea4a937..bd3dd0a 100644 (file)
 
 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)
index 5949283..00af35d 100644 (file)
@@ -30,6 +30,12 @@ class WObject:public WHelper
 {
        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*/
index eb0f93d..49f3dcd 100644 (file)
 
 #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> >()+
index 1a9f0a1..c8bf7df 100644 (file)
@@ -143,7 +143,7 @@ QString WocPHPClass::classPropertiesList(const WocClass&cls)
 {
        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]+"\"=>";
@@ -164,7 +164,7 @@ QString WocPHPClass::classPropertiesList(const WocClass&cls)
                                code+="$this->prop_"+k[i];
                }
        }
-       code+=");\n}\n";
+       code+="));\n}\n";
        
        return code;
 }
@@ -401,12 +401,16 @@ QString WocPHPClass::classSerializers(const WocClass&cls)
        //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;
 }
 
@@ -419,6 +423,9 @@ QString WocPHPClass::classDeserializers(const WocClass&cls)
        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
@@ -452,7 +459,7 @@ QString WocPHPClass::classDeserializers(const WocClass&cls)
                        }
                }
        }
-       code+="\treturn $data;\n}\n";
+       code+="}\n";
        return code;
 }
 
index a1de708..8eb1911 100644 (file)
@@ -54,14 +54,15 @@ void WocQtClass::newClass(const WocClass&cls)
        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
@@ -225,24 +226,26 @@ void WocQtClass::classDeserializer(const WocClass&cls,MFile&hdr,MFile&src,QStrin
        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])){
@@ -346,8 +349,12 @@ void WocQtClass::classSerializers(const WocClass&cls,MFile&hdr,MFile&src,QString
        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);
@@ -425,7 +432,7 @@ void WocQtClass::classSerializers(const WocClass&cls,MFile&hdr,MFile&src,QString
                        scd+="\t}\n";
                }
        }
-       scd+="\treturn r;\n}\n";
+       scd+="\n}\n";
        hdr.write(hcd.toAscii());
        src.write(scd.toAscii());
 }