[opengtl-commits] [734] implement NodesList, TextNode, OperationNode and AllChannelsNode |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 734
Author: cyrille
Date: 2009-05-26 09:50:42 +0200 (Tue, 26 May 2009)
Log Message:
-----------
implement NodesList, TextNode, OperationNode and AllChannelsNode
Modified Paths:
--------------
trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST.cpp
trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST_p.h
Modified: trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST.cpp 2009-05-26 07:49:35 UTC (rev 733)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST.cpp 2009-05-26 07:50:42 UTC (rev 734)
@@ -0,0 +1,130 @@
+/*
+ * 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 "TemplateAST_p.h"
+
+#include <GTLCore/Macros_p.h>
+#include <GTLCore/Type.h>
+
+#include "GenerationContext_p.h"
+#include "Debug.h"
+
+using namespace OpenCTL;
+using namespace OpenCTL::TemplateAST;
+
+Node::~Node() {
+}
+
+GTLCore::String Node::typeToString(const GTLCore::Type* _type) {
+ switch(_type->dataType()) {
+ case GTLCore::Type::UNSIGNED_INTEGER8:
+ case GTLCore::Type::UNSIGNED_INTEGER16:
+ case GTLCore::Type::UNSIGNED_INTEGER32:
+ return " unsigned int ";
+ case GTLCore::Type::INTEGER8:
+ case GTLCore::Type::INTEGER16:
+ case GTLCore::Type::INTEGER32:
+ return " int ";
+ case GTLCore::Type::FLOAT:
+ return " float ";
+ case GTLCore::Type::HALF:
+ return " half ";
+ default:
+ GTL_ABORT("Unsupported: " << _type);
+ }
+}
+
+NodesList::NodesList( const std::list<Node*>& _nodes) : m_nodes(_nodes)
+{
+}
+
+NodesList::~NodesList()
+{
+}
+
+void NodesList::generate(TemplateGenerationContext* _context)
+{
+ foreach(Node* node, m_nodes)
+ {
+ node->generate(_context);
+ }
+}
+
+TextNode::TextNode(const GTLCore::String& _text) : m_text(_text)
+{
+}
+
+TextNode::~TextNode()
+{
+}
+
+void TextNode::generate(TemplateGenerationContext* _context)
+{
+ _context->append(m_text);
+}
+
+OperationNode::OperationNode( const GTLCore::String& _name) : m_name(_name)
+{
+}
+
+OperationNode::~OperationNode()
+{
+}
+
+void OperationNode::generate(TemplateGenerationContext* _context)
+{
+ GTLCore::String header = "void " + m_name + "(";
+ GTLCore::String outHeader;
+
+ const GTLCore::PixelDescription& pd = _context->pixelDescription();
+
+ for(std::size_t i = 0; i < pd.channels(); ++i)
+ {
+ const GTLCore::Type* type = pd.channelTypes()[i];
+ GTLCore::String string_type = typeToString(type);
+ GTLCore::String string_num = GTLCore::String::number(i);
+ header += string_type + " in_" + string_num;
+ outHeader += "output " + string_type + " out_" + string_num;
+ if(i != pd.channels() - 1 )
+ {
+ header += ", ";
+ outHeader += ", ";
+ }
+ }
+ header += "," + outHeader + " )";
+ _context->append(header);
+ _context->startOperation();
+}
+
+AllChannelsNode::AllChannelsNode( NodesList* _nodesList ) : m_nodesList(_nodesList) {
+}
+
+AllChannelsNode::~AllChannelsNode() {
+ delete m_nodesList;
+}
+
+void AllChannelsNode::generate(TemplateGenerationContext* _context) {
+ const GTLCore::PixelDescription& pd = _context->pixelDescription();
+ for(std::size_t i = 0; i < pd.channels(); ++i)
+ {
+ TemplateGenerationContext* localContext = _context->createLocalContext(GTLCore::String::number(i));
+ m_nodesList->generate(localContext);
+ _context->mergeLocalContext(localContext);
+ }
+}
Modified: trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST_p.h
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST_p.h 2009-05-26 07:49:35 UTC (rev 733)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST_p.h 2009-05-26 07:50:42 UTC (rev 734)
@@ -0,0 +1,108 @@
+/*
+ * 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 _TEMPLATE_AST_H_
+#define _TEMPLATE_AST_H_
+
+#include <GTLCore/String.h>
+
+namespace GTLCore {
+ class Type;
+}
+
+namespace OpenCTL {
+ class TemplateGenerationContext;
+ namespace TemplateAST {
+ /**
+ * @internal
+ * This class represent a node in the AST tree of CTL Templates.
+ */
+ class Node {
+ public:
+ virtual ~Node();
+ virtual void generate(TemplateGenerationContext* _context) = 0;
+ protected:
+ /**
+ * Utility function that return the string corresponding to the type.
+ */
+ static GTLCore::String typeToString(const GTLCore::Type* _type);
+ };
+ class NodesList : public Node {
+ public:
+ NodesList( const std::list<Node*>& _nodes);
+ virtual ~NodesList();
+ virtual void generate(TemplateGenerationContext* _context);
+ private:
+ std::list<Node* > m_nodes;
+ };
+ class TextNode : public Node {
+ public:
+ TextNode(const GTLCore::String& _text);
+ virtual ~TextNode();
+ virtual void generate(TemplateGenerationContext* _context);
+ private:
+ GTLCore::String m_text;
+ };
+ class OperationNode : public Node {
+ public:
+ OperationNode( const GTLCore::String& _name);
+ virtual ~OperationNode();
+ virtual void generate(TemplateGenerationContext* _context);
+ private:
+ GTLCore::String m_name;
+ };
+ class AllChannelsNode : public Node {
+ public:
+ AllChannelsNode( NodesList* _nodesList );
+ virtual ~AllChannelsNode();
+ virtual void generate(TemplateGenerationContext* _context);
+ private:
+ NodesList* m_nodesList;
+ };
+ class ColorChannelsNode : public Node {
+ public:
+ virtual void generate(TemplateGenerationContext* _context);
+ };
+ class OutNode : public Node {
+ public:
+ virtual void generate(TemplateGenerationContext* _context);
+ };
+ class InNode : public Node {
+ public:
+ virtual void generate(TemplateGenerationContext* _context);
+ };
+ class MaxNode : public Node {
+ public:
+ virtual void generate(TemplateGenerationContext* _context);
+ };
+ class MinNode : public Node {
+ public:
+ virtual void generate(TemplateGenerationContext* _context);
+ };
+ class UnitNode : public Node {
+ public:
+ virtual void generate(TemplateGenerationContext* _context);
+ };
+ class TypeNode : public Node {
+ public:
+ virtual void generate(TemplateGenerationContext* _context);
+ };
+ }
+}
+
+#endif