From cb3bee4bcba109126165e4c185d0803f7d159a1b Mon Sep 17 00:00:00 2001 From: konrad Date: Fri, 1 Jan 2010 12:32:34 +0000 Subject: [PATCH] modified woc to only write Qt output if it actually changed git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@384 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- woc/mfile.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ woc/mfile.h | 46 +++++++++++++++++++++++++++++++ woc/qtout.cpp | 36 +++++++++++++----------- woc/qtout.h | 13 +++++---- woc/woc.pro | 2 + 5 files changed, 160 insertions(+), 22 deletions(-) create mode 100644 woc/mfile.cpp create mode 100644 woc/mfile.h diff --git a/woc/mfile.cpp b/woc/mfile.cpp new file mode 100644 index 0000000..e6c0c9a --- /dev/null +++ b/woc/mfile.cpp @@ -0,0 +1,85 @@ +// +// C++ Implementation: mfile +// +// Description: +// +// +// Author: Konrad Rosenbaum , (C) 2010 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#include "mfile.h" + +#include + +//static +QMap MFile::touched; + +MFile::MFile(QString n,QObject*parent):QFile(n+",new",parent),name(n){isopen=false;} +MFile::MFile(QObject *parent):QFile(parent){isopen=false;} +MFile::~MFile() +{ + if(isopen)close(); +} + +void MFile::close() +{ +// qDebug("Info: closing %s",name.toAscii().data()); + //compare + bool ident=false; + if(isopen){ + QFile::close(); + QFile::open(QIODevice::ReadOnly); + QByteArray here=readAll(); + QFile there(name); + if(there.open(QIODevice::ReadOnly)){ + ident=(here == there.readAll()); + there.close(); + } + } + //actual close + QFile::close(); + //move + if(isopen){ + isopen=false; + if(ident){ + //if identical: remove new version to preserve file time + remove(); + }else{ + //if not identical: use new version, remove old one + QFile(name).remove(); + QFile(name+",new").rename(name); + } + } +} + +void MFile::setFileName(QString n) +{ + name=n; + QFile::setFileName(n+",new"); +} + +bool MFile::open(QIODevice::OpenMode m) +{ + isopen=QFile::open(m); + if(isopen){ + //remember it + QFileInfo fi(name); + QString p=fi.absolutePath(); + QString f=fi.fileName(); + if(!touched.contains(p))touched.insert(p,QStringList()); + if(!touched[p].contains(f))touched[p]<, (C) 2010 +// +// Copyright: See README/COPYING files that come with this distribution +// +// + +#ifndef WOC_MFILE_H +#define WOC_MFILE_H + +#include +#include +#include + +/**overwrites QFile to only generate a file if its new version differs from an existing one, it creates a temporary file with ",new" added to the file name; additionally it records all file names that it touches; +this is not a complete implementation - just enough for woc*/ +class MFile:public QFile +{ + public: + MFile(QString name,QObject*parent=0); + MFile(QObject *parent=0); + ~MFile(); + + virtual void close(); + virtual bool open(QIODevice::OpenMode m); + + QString fileName()const{return name;} + void setFileName(QString n); + + static bool touchedFile(QString); + private: + //flag to show whether file is open + bool isopen; + //original name of the file + QString name; + + //stores touched files + static QMap touched; +}; + +#endif diff --git a/woc/qtout.cpp b/woc/qtout.cpp index 53a336b..1d9bbf1 100644 --- a/woc/qtout.cpp +++ b/woc/qtout.cpp @@ -40,16 +40,10 @@ WocQtClientOut::WocQtClientOut(QDomElement&el) qDebug("Info: creating Qt Client Output Generator."); m_basedir=WocProcessor::instance()->baseDir()+"/"+el.attribute("sourceDir","."); m_subdir=el.attribute("subDir","qtwob"); - bool clean=str2bool(el.attribute("clean","0")); + m_clean=str2bool(el.attribute("clean","0")); m_prefix=el.attribute("classPrefix","Wob"); - //cleanup directory (remove normal files, assume remainder is harmless) - QDir d(m_basedir+"/"+m_subdir); - if(d.exists() && clean){ - QStringList ent=d.entryList(QDir::Files); - for(int i=0;i +#include "mfile.h" class QDomElement; @@ -31,18 +31,19 @@ class WocQtClientOut:public WocOutput virtual void newTransaction(const WocTransaction&); private: QString m_basedir,m_subdir,m_prefix; - QFile m_pri,m_iface,m_ifacecpp,m_hdr; + MFile m_pri,m_iface,m_ifacecpp,m_hdr; + bool m_clean; /**helper: adds a file to the project file*/ void addFile(QString basename); /**helper: generate enums for classes*/ - void classEnums(const WocClass&,QFile&,QFile&,QString); + void classEnums(const WocClass&,MFile&,MFile&,QString); /**helper: generate properties*/ - void classProperties(const WocClass&,QFile&,QFile&); + void classProperties(const WocClass&,MFile&,MFile&); /**helper: generate constructors/deserializer/copiers*/ - void classDeserializer(const WocClass&,QFile&,QFile&,QString); + void classDeserializer(const WocClass&,MFile&,MFile&,QString); /**helper: generate serializers*/ - void classSerializers(const WocClass&,QFile&,QFile&,QString); + void classSerializers(const WocClass&,MFile&,MFile&,QString); /**helper: generate a proper Qt type for a property*/ QString qttype(const WocClass&,QString,bool dolist=true); diff --git a/woc/woc.pro b/woc/woc.pro index e9ffd33..e04bdbd 100644 --- a/woc/woc.pro +++ b/woc/woc.pro @@ -17,12 +17,14 @@ SOURCES+= \ qtout.cpp \ phpout.cpp \ htmlout.cpp \ + mfile.cpp \ ../src/misc/domquery.cpp HEADERS+= \ processor.h \ phpout.h \ qtout.h \ htmlout.h \ + mfile.h \ ../src/misc/domquery.h INCLUDEPATH += ../src/misc \ No newline at end of file -- 1.7.2.5