ECF 1.5
rpn.h
1#ifndef RPN_Class
2#define RPN_Class
3
4#include <cmath>
5#include <stdlib.h>
6#include <string>
7#include "nodes.h"
8extern node Nodes[TOTAL_NODES];
9typedef unsigned int uint;
10
11class RPN
12{
13public:
14 int *m_pExpression[MAX_TREES], *m_pEdited; // zapis originalnih odnosno editiranog stabla
15 uint m_iExprSize, m_iEditSize;
16 double m_pTermValues[TERMINALS+OFFSET];
17 double m_dTermValuesArray[TERMINALS+OFFSET][MAX_JOBS]; // vrijednosti terminala za vektorsku evaluaciju
18 int m_iTermNum;
19 double m_pNodeFreq[TOTAL_NODES]; // double zbog lakseg kopiranja u matricu
20 uint m_iArraySize; // velicina polja za zajednicku evaluaciju
21 uint m_iOffset, m_iEnd; // pocetni i krajnji element u polju indeksa poslova za koje se racuna stablo
22 uint *pIndex; // polje indeksa poslova - svim terminalima pristupa se preko toga polja
23 int m_iPosition, m_iEditedPos; // pozicija u originalnom odnosno editiranom stablu
24 uint m_nTree; // oznacava aktivno stablo (default = 0)
25 std::string m_output;
26
27 double evaluate();
28 void evaluate_array(double dResult[]);
29 int edit();
30 void copy();
31 void ResetNodeFreq();
32 void write();
33 void r_write();
34
36 { for(int i=0; i<MAX_TREES; i++)
37 m_pExpression[i] = NULL;
38 m_pEdited = NULL;
39 m_pTermValues[NUL] = 0;
40 m_pTermValues[ONE] = 1;
41 for(int i=0; i<MAX_JOBS; i++)
42 { m_dTermValuesArray[NUL][i] = 0;
43 m_dTermValuesArray[ONE][i] = 1;
44 }
45 m_iTermNum = TERMINALS+OFFSET;
46 ResetNodeFreq(); // brojace terminala stavljamo na nulu
47 m_nTree = 0;
48 }
49 ~RPN()
50 { for(int i=0; i<MAX_TREES; i++)
51 if(m_pExpression[i] != NULL) delete [] m_pExpression[i];
52 if(m_pEdited != NULL) delete [] m_pEdited;
53 }
54 void SetExprSize(uint _size)
55 { for(int i=0; i<MAX_TREES; i++)
56 { if(m_pExpression[i] != NULL) delete [] m_pExpression[i];
57 m_pExpression[i] = new int[_size];
58 }
59 if(m_pEdited != NULL) delete [] m_pEdited;
60 m_pEdited = new int[_size];
61 m_iExprSize = _size;
62 }
63 void SetTermArraySize(uint _size)
64 { /*int i;
65 for(i=0; i<TERMINALS+OFFSET; i++)
66 { if(m_pTermValuesArray[i])
67 delete [] m_pTermValuesArray[i];
68 m_pTermValuesArray[i] = new double[_size];
69 }*/
70 m_iArraySize = m_iEnd = _size;
71 }
72};
73
74#endif // RPN
Definition: rpn.h:12
RPN()
Definition: rpn.h:35
Definition: nodes.h:92