[opengtl-commits] [737] implement node for @var |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/opengtl-commits Archives
]
Revision: 737
Author: cyrille
Date: 2009-05-26 10:40:10 +0200 (Tue, 26 May 2009)
Log Message:
-----------
implement node for @var
Modified Paths:
--------------
trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/GenerationContext_p.cpp
trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/GenerationContext_p.h
trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST.cpp
trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST_p.h
Modified: trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/GenerationContext_p.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/GenerationContext_p.cpp 2009-05-26 08:12:31 UTC (rev 736)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/GenerationContext_p.cpp 2009-05-26 08:40:10 UTC (rev 737)
@@ -25,14 +25,14 @@
using namespace OpenCTL;
-// TemplateGenerationContext::TemplateGenerationContext() : m_hasForward(false) {
+// TemplateGenerationContext::TemplateGenerationContext() : m_isLocalContext(false) {
// }
-TemplateGenerationContext* TemplateGenerationContext::createLocalContext(const GTLCore::String& suffix) {
+TemplateGenerationContext* TemplateGenerationContext::createLocalContext(const GTLCore::String& suffix, int _currentChannel) {
TemplateGenerationContext* local = 0; // FIXME :)
- local->m_hasForward = true;
+ local->m_isLocalContext = true;
local->m_suffix = suffix;
- local->m_hasSuffix = true;
+ local->m_currentChannel = _currentChannel;
return local;
}
@@ -47,7 +47,7 @@
}
void TemplateGenerationContext::appendForward(const GTLCore::String& _c) {
- GTL_ASSERT(m_hasForward);
+ GTL_ASSERT(m_isLocalContext);
m_forward.append(_c);
}
@@ -77,6 +77,11 @@
}
const GTLCore::String& TemplateGenerationContext::suffix() {
- GTL_ASSERT(m_hasSuffix);
+ GTL_ASSERT(m_isLocalContext);
return m_suffix;
}
+
+int TemplateGenerationContext::currentChannel() {
+ GTL_ASSERT(m_isLocalContext);
+ return m_currentChannel;
+}
Modified: trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/GenerationContext_p.h
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/GenerationContext_p.h 2009-05-26 08:12:31 UTC (rev 736)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/GenerationContext_p.h 2009-05-26 08:40:10 UTC (rev 737)
@@ -26,7 +26,7 @@
namespace OpenCTL {
class TemplateGenerationContext {
public:
- TemplateGenerationContext* createLocalContext(const GTLCore::String& suffix);
+ TemplateGenerationContext* createLocalContext(const GTLCore::String& suffix, int _currentChannel);
void mergeLocalContext(TemplateGenerationContext* );
void append(const GTLCore::String& _c);
void appendForward(const GTLCore::String& _c);
@@ -36,12 +36,13 @@
void registerVariable( const GTLCore::String& variable);
bool isAllreadyRegistered( const GTLCore::String& variable);
const GTLCore::String& suffix();
+ int currentChannel();
private:
GTLCore::String m_code;
GTLCore::String m_forward;
- bool m_hasForward;
+ bool m_isLocalContext;
GTLCore::String m_suffix;
- bool m_hasSuffix;
+ int m_currentChannel;
GTLCore::PixelDescription m_pixelDescription;
std::list< GTLCore::String > m_registeredVariables;
};
Modified: trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST.cpp
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST.cpp 2009-05-26 08:12:31 UTC (rev 736)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST.cpp 2009-05-26 08:40:10 UTC (rev 737)
@@ -121,13 +121,13 @@
void AllChannelsNode::generate(TemplateGenerationContext* _context) {
const GTLCore::PixelDescription& pd = _context->pixelDescription();
- for(std::size_t i = 0; i < pd.channels(); ++i)
+ for(int i = 0; i < int(pd.channels()); ++i)
{
if( m_whichChannel == AllChannel
or ( m_whichChannel == ColorChannel and i != pd.alphaPos() )
or ( m_whichChannel == AlphaChannel and i == pd.alphaPos() ) )
{
- TemplateGenerationContext* localContext = _context->createLocalContext(GTLCore::String::number(i));
+ TemplateGenerationContext* localContext = _context->createLocalContext("_" + GTLCore::String::number(i), i);
m_nodesList->generate(localContext);
_context->mergeLocalContext(localContext);
}
@@ -149,3 +149,23 @@
void InOutNode::generate(TemplateGenerationContext* _context) {
_context->append(m_string + _context->suffix());
}
+
+VarNode::VarNode(const GTLCore::String& _name ) : m_name(_name) {
+}
+
+void VarNode::generate(TemplateGenerationContext* _context) {
+ GTLCore::String realname = m_name + _context->suffix();
+ if(not _context->isAllreadyRegistered(realname))
+ {
+ _context->registerVariable(realname);
+ _context->appendForward( typeToString(_context->pixelDescription().channelTypes()[_context->currentChannel()]) + " " + realname + ";" );
+ }
+ _context->append(realname);
+}
+
+
+
+
+
+
+
Modified: trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST_p.h
===================================================================
--- trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST_p.h 2009-05-26 08:12:31 UTC (rev 736)
+++ trunk/OpenGTL/OpenCTL/OpenCTL/templatecompiler/TemplateAST_p.h 2009-05-26 08:40:10 UTC (rev 737)
@@ -94,6 +94,14 @@
private:
GTLCore::String m_string;
};
+ class VarNode : public Node {
+ public:
+ VarNode(const GTLCore::String& _name );
+ public:
+ virtual void generate(TemplateGenerationContext* _context);
+ private:
+ GTLCore::String m_name;
+ };
class MaxNode : public Node {
public:
virtual void generate(TemplateGenerationContext* _context);