[opengtl-commits] [733] add a GenerationContext for templates

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 733
Author:   cyrille
Date:     2009-05-26 09:49:35 +0200 (Tue, 26 May 2009)

Log Message:
-----------
add a GenerationContext for templates

Modified Paths:
--------------
    trunk/OpenGTL/OpenCTL/OpenCTL/CMakeLists.txt

Added Paths:
-----------
    trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/GenerationContext_p.cpp
    trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/GenerationContext_p.h


Modified: trunk/OpenGTL/OpenCTL/OpenCTL/CMakeLists.txt
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/CMakeLists.txt	2009-05-06 18:28:28 UTC (rev 732)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/CMakeLists.txt	2009-05-26 07:49:35 UTC (rev 733)
@@ -15,6 +15,7 @@
   compiler/LexerNG.cpp
   compiler/ParserNG.cpp
 # Template files
+  templatecompiler/GenerationContext_p.cpp
   templatecompiler/TemplateAST.cpp
   templatecompiler/TemplateLexer.cpp
   templatecompiler/TemplateParser.cpp

Added: trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/GenerationContext_p.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/GenerationContext_p.cpp	                        (rev 0)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/GenerationContext_p.cpp	2009-05-26 07:49:35 UTC (rev 733)
@@ -0,0 +1,82 @@
+/*
+ *  Copyright (c) 2009 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "GenerationContext_p.h"
+
+#include "GTLCore/Macros_p.h"
+
+#include "Debug.h"
+
+using namespace OpenCTL;
+
+// TemplateGenerationContext::TemplateGenerationContext() : m_hasForward(false) {
+// }
+
+TemplateGenerationContext* TemplateGenerationContext::createLocalContext(const GTLCore::String& suffix) {
+  TemplateGenerationContext* local = 0; // FIXME :)
+  local->m_hasForward = true;
+  local->m_suffix = suffix;
+  local->m_hasSuffix = true;
+  return local;
+}
+
+void TemplateGenerationContext::mergeLocalContext(TemplateGenerationContext* _localContext) {
+  append(_localContext->m_forward);
+  append(_localContext->code());
+  delete _localContext;
+}
+
+void TemplateGenerationContext::append(const GTLCore::String& _c) {
+  m_code.append(_c);
+}
+
+void TemplateGenerationContext::appendForward(const GTLCore::String& _c) {
+  GTL_ASSERT(m_hasForward);
+  m_forward.append(_c);
+}
+
+const GTLCore::String& TemplateGenerationContext::code() const {
+  return m_code;
+}
+
+const GTLCore::PixelDescription& TemplateGenerationContext::pixelDescription() const {
+  return m_pixelDescription;
+}
+
+void TemplateGenerationContext::startOperation() {
+  m_registeredVariables.clear();
+}
+
+void TemplateGenerationContext::registerVariable( const GTLCore::String& variable) {
+  GTL_ASSERT(not isAllreadyRegistered( variable ) );
+  m_registeredVariables.push_back(variable);
+}
+
+bool TemplateGenerationContext::isAllreadyRegistered( const GTLCore::String& variable) {
+  foreach( const GTLCore::String& string, m_registeredVariables)
+  {
+    if( string == variable ) return true;
+  }
+  return false;
+}
+
+const GTLCore::String& TemplateGenerationContext::suffix() {
+  GTL_ASSERT(m_hasSuffix);
+  return m_suffix;
+}


Property changes on: trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/GenerationContext_p.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/GenerationContext_p.h
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/GenerationContext_p.h	                        (rev 0)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/GenerationContext_p.h	2009-05-26 07:49:35 UTC (rev 733)
@@ -0,0 +1,50 @@
+/*
+ *  Copyright (c) 2009 Cyrille Berger <cberger@xxxxxxxxxxx>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * either version 2, or (at your option) any later version of the License.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; see the file COPYING.  If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef _GENERATION_CONTEXT_P_H_
+#define _GENERATION_CONTEXT_P_H_
+
+#include <GTLCore/PixelDescription.h>
+#include <GTLCore/String.h>
+
+namespace OpenCTL {
+  class TemplateGenerationContext {
+    public:
+      TemplateGenerationContext* createLocalContext(const GTLCore::String& suffix);
+      void mergeLocalContext(TemplateGenerationContext* );
+      void append(const GTLCore::String& _c);
+      void appendForward(const GTLCore::String& _c);
+      const GTLCore::String& code() const;
+      const GTLCore::PixelDescription& pixelDescription() const;
+      void startOperation();
+      void registerVariable( const GTLCore::String& variable);
+      bool isAllreadyRegistered( const GTLCore::String& variable);
+      const GTLCore::String& suffix();
+    private:
+      GTLCore::String m_code;
+      GTLCore::String m_forward;
+      bool m_hasForward;
+      GTLCore::String m_suffix;
+      bool m_hasSuffix;
+      GTLCore::PixelDescription m_pixelDescription;
+      std::list< GTLCore::String > m_registeredVariables;
+  };
+}
+
+#endif


Property changes on: trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/GenerationContext_p.h
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/