summaryrefslogtreecommitdiffstats
path: root/src/flowparts/unary.cpp
blob: 077afc7dbb1fcfe760a5918872fcc8e16a1b295a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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(
		TQString("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( TQStringList::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 TQString var = dataString("0-var");
	const TQString 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
	TQString rot = dataString("1-rot");
	
	if ( FlowCode::isLiteral(var) ) return;
	
	TQString 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
}