PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PNode.h
Go to the documentation of this file.
1//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: src/base/PNode.h
4// Purpose: Primary data structure for code
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2003-2026 Shane T. Mueller <smueller@obereed.net>
7// License: GPL 2
8//
9//
10//
11// This file is part of the PEBL project.
12//
13// PEBL is free software; you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation; either version 2 of the License, or
16// (at your option) any later version.
17//
18// PEBL is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with PEBL; if not, write to the Free Software
25// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27#ifndef __PNODE_H__
28#define __PNODE_H__
29
30#include "Variant.h" //This contains definition for enum VariantDataType
31#include <string>
32#include "../utility/Defs.h"
38
39
44
45class PNode {
46
47public:
48
50 PNode();
51
52 PNode(const PNode & pn);
53 PNode(const std::string & filename, int linenumber);
54 // PNode (const PNode * pn);
55 // PNode(PNODE_TYPE type);
56 PNode(PNODE_TYPE type, const std::string & filename, int linenumber);
58 virtual ~PNode();
59
61 PNODE_TYPE GetType() const {return mType;};
62
63
64 //Overload of the << operator
65 friend std::ostream& operator<<(std::ostream& out, const PNode & node );
66
67 void SetFileInfo(const std::string & filename, int linenumber);
68 std::string GetFilename()const {return mSourceFile;};
69 int GetLineNumber()const {return mLineNumber;};
70 void SetFunctionName(const std::string &funcname);
71 std::string GetFunctionName()const{return mFunctName;};
72
73 virtual void DestroyChildren();
74private:
75
76protected:
77
78 //Inheritable printing Method.
79 virtual std::ostream& SendToStream(std::ostream& out)const;
80
81
85
86
88 int mTrace;
89
90
92 std::string mSourceFile;
93
96
97 std::string mFunctName;
98};
99
100
101
102class OpNode: public PNode
103{
104public:
105 //Constructor
106 //OpNode(int type, PNode *left, PNode *right);
107 OpNode(int type, PNode *left, PNode *right,const std::string & filename, int linenumber);
108 OpNode(const OpNode &);
109 virtual ~OpNode();
110 OpNode operator = (const OpNode & op);
111 int GetOp()const{return mOp;};
112 std::string GetOpName() const;
113
114 PNode* GetLeft() const {return mLeft;};
115 PNode* GetRight() const{return mRight;};
116
117 virtual void DestroyChildren();
118 virtual void DestroyFunctionTree();
119
120
121private:
122protected:
123
124 virtual std::ostream& SendToStream(std::ostream& out) const;
125 int mOp;
126
129
132};
133
134
135class DataNode: public PNode
136{
137public:
138 // DataNode(const Variant value);
139 // DataNode();
140 // DataNode(pInt ivalue);
141 // DataNode(pDouble fvalue);
142 DataNode(const Variant value, const std::string & filename, int linenumber);
143 DataNode(const std::string & filename, int linenumber);
144 DataNode(pInt ivalue, const std::string & filename, int linenumber);
145 DataNode(pDouble fvalue, const std::string & filename, int linenumber);
146
147
148 virtual ~DataNode();
150
151 //GetValue() returns a const reference to mValue to avoid copy issues in Emscripten
152 const Variant& GetValue()const{return mValue;};
153
154
155
156private:
157
158protected:
159 virtual std::ostream& SendToStream(std::ostream& out) const;
160
161
165};
166
167
168
169#endif
#define pInt
Definition Defs.h:8
#define pDouble
Definition Defs.h:7
PNODE_TYPE
Definition PNode.h:33
@ PEBL_OP_NODE
Definition PNode.h:35
@ PEBL_UNDEFINED_NODE
Definition PNode.h:34
@ PEBL_DATA_NODE
Definition PNode.h:36
VariantDataType
Definition Variant.h:40
virtual std::ostream & SendToStream(std::ostream &out) const
Definition PNode.cpp:463
Variant mValue
Definition PNode.h:164
DataNode(pInt ivalue, const std::string &filename, int linenumber)
DataNode(pDouble fvalue, const std::string &filename, int linenumber)
virtual ~DataNode()
Definition PNode.cpp:455
DataNode(const std::string &filename, int linenumber)
const Variant & GetValue() const
Definition PNode.h:152
VariantDataType GetDataType() const
Definition PNode.h:149
virtual void DestroyChildren()
Definition PNode.cpp:174
virtual ~OpNode()
Definition PNode.cpp:237
PNode * mRight
A link to the right-child node.
Definition PNode.h:131
PNode * GetRight() const
Definition PNode.h:115
std::string GetOpName() const
Definition PNode.cpp:245
int GetOp() const
Definition PNode.h:111
virtual std::ostream & SendToStream(std::ostream &out) const
Definition PNode.cpp:346
PNode * GetLeft() const
Definition PNode.h:114
int mOp
Definition PNode.h:125
PNode * mLeft
A link to the left-child node.
Definition PNode.h:128
OpNode operator=(const OpNode &op)
Definition PNode.cpp:164
virtual void DestroyFunctionTree()
Definition PNode.cpp:197
Definition PNode.h:45
virtual void DestroyChildren()
Definition PNode.cpp:112
virtual ~PNode()
The Standard destructor.
Definition PNode.cpp:83
PNode(const std::string &filename, int linenumber)
int GetLineNumber() const
Definition PNode.h:69
PNODE_TYPE mType
Definition PNode.h:84
void SetFileInfo(const std::string &filename, int linenumber)
Definition PNode.cpp:102
std::string mSourceFile
Source file of origin.
Definition PNode.h:92
virtual std::ostream & SendToStream(std::ostream &out) const
Definition PNode.cpp:96
int mLineNumber
Closest Line number of origin.
Definition PNode.h:95
std::string mFunctName
Definition PNode.h:97
void SetFunctionName(const std::string &funcname)
Definition PNode.cpp:107
int mTrace
Whether to produce a trace.
Definition PNode.h:88
PNODE_TYPE GetType() const
Access mType data.
Definition PNode.h:61
std::string GetFilename() const
Definition PNode.h:68
std::string GetFunctionName() const
Definition PNode.h:71
friend std::ostream & operator<<(std::ostream &out, const PNode &node)
PNode()
The Standard constructor.
Definition PNode.cpp:53
PNode(PNODE_TYPE type, const std::string &filename, int linenumber)
VariantDataType GetDataType() const
This returns the type as an enum.
Definition Variant.cpp:885