diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 01:49:02 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 01:49:02 +0000 |
commit | 5de3dd4762ca33a0f92e79ffa4fe2ff67069d531 (patch) | |
tree | bad482b7afa4cdf47422d60a5dd2c61c7e333b09 /src/flowparts/unary.cpp | |
download | ktechlab-5de3dd4762ca33a0f92e79ffa4fe2ff67069d531.tar.gz ktechlab-5de3dd4762ca33a0f92e79ffa4fe2ff67069d531.zip |
Added KDE3 version of ktechlab
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/ktechlab@1095338 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/flowparts/unary.cpp')
-rw-r--r-- | src/flowparts/unary.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/flowparts/unary.cpp b/src/flowparts/unary.cpp new file mode 100644 index 0000000..fe0b549 --- /dev/null +++ b/src/flowparts/unary.cpp @@ -0,0 +1,90 @@ +/*************************************************************************** + * Copyright (C) 2003-2004 by David Saxton * + * david@bluehaze.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include "unary.h" + +#include "libraryitem.h" +#include "flowcode.h" + +#include <klocale.h> + +Item* Unary::construct( ItemDocument *itemDocument, bool newItem, const char *id ) +{ + return new Unary( (ICNDocument*)itemDocument, newItem, id ); +} + +LibraryItem* Unary::libraryItem() +{ + return new LibraryItem( + QString("flow/unary"), + i18n("Unary"), + i18n("Variables"), + "unary.png", + LibraryItem::lit_flowpart, + Unary::construct ); +} + +Unary::Unary( ICNDocument *icnDocument, bool newItem, const char *id ) + : FlowPart( icnDocument, newItem, (id) ? id : "unary" ) +{ + m_name = i18n("Unary"); + m_desc = i18n("A unary operation involves only one variable. Suppo operations are:<br><ul><li><b>Rotate Left</b> rotates the binary bits of the variable left (discarding the end bits).</li><li><b>Rotate Right</b> rotates the binary bits right (discarding the start bits).</li><li><b>Increment</b> increases the value of the variable by 1. A value of 255 wraps around to 0.</li><li><b>Decrement</b> decreases the value of a variable by 1. A value of 0 wraps around to 255.</li></ul>"); + initProcessSymbol(); + createStdInput(); + createStdOutput(); + + createProperty( "0-var", Variant::Type::VarName ); + property("0-var")->setValue("x"); + property("0-var")->setCaption( i18n("Variable") ); + + createProperty( "1-op", Variant::Type::Select ); + property("1-op")->setCaption( i18n("Operation") ); + property("1-op")->setAllowed( QStringList::split( ',', "Rotate Left,Rotate Right,Increment,Decrement" ) ); + property("1-op")->setValue("Rotate Left"); +} + +Unary::~Unary() +{ +} + +void Unary::dataChanged() +{ + setCaption( dataString("0-var") + " " + dataString("1-op") ); +} + +void Unary::generateMicrobe( FlowCode *code ) +{ + const QString var = dataString("0-var"); + const QString op = dataString("1-op"); + + if ( op == "Rotate Left" ) code->addCode( "rotateleft "+var ); + else if ( op == "Rotate Right" ) code->addCode( "rotateright "+var ); + else if ( op == "Increment" ) code->addCode( "increment "+var ); + else if ( op == "Decrement" ) code->addCode( "decrement "+var ); + else; // Hmm... + code->addCodeBranch( outputPart("stdoutput") ); + +#if 0 + QString rot = dataString("1-rot"); + + if ( FlowCode::isLiteral(var) ) return; + + QString newCode; + + code->addVariable(var); + if ( rot == "Left" ) newCode += "rlf " + var + ",1 ; Unary " + var + " left through Carry, place result back in " + var + "\n"; + else newCode += "rrf " + var + ",1 ; Unary " + var + " right through Carry, place result back in " + var + "\n"; + + newCode += gotoCode("stdoutput"); + code->addCodeBlock( id(), newCode ); +#endif +} + + |