From: konrad Date: Tue, 17 Feb 2009 16:53:04 +0000 (+0000) Subject: start implementing wobjects X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=34db46a73ee537eb30141b6abdb31dc08afc2a19;p=web%2Fkonrad%2Fsmoke.git start implementing wobjects git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@269 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/woc/phpout.cpp b/woc/phpout.cpp index a9662cb..19a1e14 100644 --- a/woc/phpout.cpp +++ b/woc/phpout.cpp @@ -227,18 +227,48 @@ void WocPHPServerOut::newClass(const WocClass&cls) return; } tf.write(PHPSTART); + + //// //generate code - QString code="class "+cna+" extends "+cls.baseClass()+"{\n"; + QString code="class "+cna+" extends "+cls.baseClass()+"{\n\n"; + //implement enums + QStringList k=cls.enumTypes(); + for(int i=0;i >ev=cls.enumValues(k[i]); + for(int j=0;jsaveXml();\n}\n"; + code+="function toXml"+k[i]+"($xml){\n\t$root=$xml->createElement(\""+cls.name()+k[i]+"\");\n"; + //TODO: add properties + code+="\treturn $root;\n}\n"; + } //implement de-serializer + code+="\nstatic function fromString($txt){\n\t$xml=new DomDocument;\n"; + code+="\t$xml->loadXml(trim($txt));\n\treturn self::fromXml($xml,$xml->documentElement);\n}\n"; + code+="static function fromXml($xml,$elem){\n\t$data=array();\n"; + k=cls.propertyNames(); + for(int i=0;i >ev; //check whether there is a reference if(el.hasAttribute("refColumn")){ @@ -350,6 +360,7 @@ WocClass::WocClass(const QDomElement&cls) nxval=el2.attribute("value",QString::number(nxval)).toInt(0,0); ev.append(QPair(n,nxval)); nxval++; + //TODO: check that value name does not exist yet } m_enumvals.insert(nm,ev); } @@ -358,7 +369,17 @@ WocClass::WocClass(const QDomElement&cls) for(int i=0;i >map; QDomNodeList nl2=el.elementsByTagName("Map"); for(int j=0;j #include #include +#include class QDomElement; @@ -31,9 +32,23 @@ class WocClass QString baseClass()const{return m_base;} bool hasProperty(QString)const; + QStringList propertyNames()const; + QString propertyType(QString)const; + bool propertyIsId(QString)const; + bool propertyIsAbstract(QString)const; bool isAbstract()const; + QStringList enumTypes()const{return m_enumvals.keys();} + bool hasEnumType(QString t)const{return m_enumvals.contains(t);} + QList > enumValues(QString t)const{return m_enumvals[t];} + + QStringList serializers()const{return m_serial.keys();} + bool hasSerializer(QString s)const{return m_serial.contains(s);} + QStringList serializerProperties(QString s)const{return m_serial[s];} + + bool hasMapping(QString m)const{return m_maps.contains(m);} + private: bool m_valid,m_abstract; QString m_name,m_base; @@ -44,6 +59,7 @@ class WocClass QList m_props; QMap > >m_maps; QMap > >m_enumvals; + QMapm_serial; }; class WocTable diff --git a/www/inc/wbase/autoload.php b/www/inc/wbase/autoload.php index 7b3d4f6..3c446b9 100644 --- a/www/inc/wbase/autoload.php +++ b/www/inc/wbase/autoload.php @@ -11,6 +11,7 @@ $AUTOCLASS["WobTable"]="inc/wbase/table.php"; $AUTOCLASS["WobSchemaBase"]="inc/wbase/schema.php"; +$AUTOCLASS["WObject"]="inc/wbase/object.php"; function __autoload($cname) { diff --git a/www/inc/wbase/object.php b/www/inc/wbase/object.php new file mode 100644 index 0000000..154b388 --- /dev/null +++ b/www/inc/wbase/object.php @@ -0,0 +1,19 @@ + +// +---------------------------------------------------------------------- +// | +// | Copyright: See COPYING file that comes with this distribution +// +---------------------------------------------------------------------- +// + +class WObject { + protected $data; + + protected __construct($d){$this->data=$d;} + +}; + +?>