Grantlee  0.2.0
templates/lib/template.h
00001 /*
00002   This file is part of the Grantlee template system.
00003 
00004   Copyright (c) 2009,2010 Stephen Kelly <steveire@gmail.com>
00005 
00006   This library is free software; you can redistribute it and/or
00007   modify it under the terms of the GNU Lesser General Public
00008   License as published by the Free Software Foundation; either version
00009   2.1 of the Licence, or (at your option) any later version.
00010 
00011   This library is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   Lesser General Public License for more details.
00015 
00016   You should have received a copy of the GNU Lesser General Public
00017   License along with this library.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019 */
00020 
00021 #ifndef GRANTLEE_TEMPLATE_H
00022 #define GRANTLEE_TEMPLATE_H
00023 
00024 #include "exception.h"
00025 #include "grantlee_core_export.h"
00026 #include "node.h"
00027 
00028 #include <QtCore/QSharedPointer>
00029 #include <QtCore/QStringList>
00030 
00031 namespace Grantlee
00032 {
00033 class Context;
00034 class Engine;
00035 class TemplateImpl;
00036 class OutputStream;
00037 
00038 #ifdef Q_QDOC
00039 #define TemplateImpl Template
00040 #else
00041 typedef QSharedPointer<TemplateImpl> Template;
00042 #endif
00043 
00044 class TemplatePrivate;
00045 
00047 
00089 class GRANTLEE_CORE_EXPORT TemplateImpl : public QObject
00090 {
00091   Q_OBJECT
00092 public:
00093   ~TemplateImpl();
00094 
00098   virtual QString render( Context *c );
00099 
00103   // ### BIC make this const and non-virtual.
00104   virtual OutputStream* render( OutputStream *stream, Context *c );
00105 
00106 #ifndef Q_QDOC
00107 
00110   NodeList nodeList() const;
00111 
00115   void setNodeList( const NodeList &list );
00116 #endif
00117 
00121   Error error();
00122 
00126   QString errorString();
00127 
00131   Engine const * engine() const;
00132 
00133 #ifndef Q_QDOC
00134 protected:
00135   TemplateImpl( Engine const *engine, QObject *parent = 0 );
00136   TemplateImpl( Engine const *engine, bool smartTrim, QObject *parent = 0 );
00137 
00138   void setContent( const QString &templateString );
00139 #endif
00140 
00141 private:
00142   //Don't allow setting the parent on a Template, which is memory managed as a QSharedPointer.
00143   using QObject::setParent;
00144 
00145 private:
00146   Q_DECLARE_PRIVATE( Template )
00147   TemplatePrivate * const d_ptr;
00148 #ifndef Q_QDOC
00149   friend class Engine;
00150   friend class Parser;
00151 #endif
00152 };
00153 
00154 }
00155 
00156 Q_DECLARE_METATYPE( Grantlee::Template )
00157 
00158 #endif
00159