PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
VCG Class Reference

#include <VCG.h>

Public Member Functions

 VCG ()
 Standard Constructor for Main VCG class.
 
 ~VCG ()
 Standard Destructor for Main VCG class.
 
void MakeGraph (const PNode *node)
 
void PrintGraph ()
 
void Evaluate (const PNode *node, const char *parent, const int anchor)
 

Detailed Description

Definition at line 43 of file VCG.h.

Constructor & Destructor Documentation

◆ VCG()

VCG::VCG ( )

Standard Constructor for Main VCG class.

Definition at line 50 of file VCG.cpp.

50 :
51 mNodeIndex((int)0),
52 mHeader(strdup("/*PEBL VGC-Tool Graph for selected program.\n (C) 2003 Shane T. Mueller, Ph.D.*/\n"))
53{
54 mGraph = new VCGGraph();
55}
Definition VCG.h:62

◆ ~VCG()

VCG::~VCG ( )

Standard Destructor for Main VCG class.

Definition at line 59 of file VCG.cpp.

60{
61 free(mHeader);
62 delete mGraph;
63}

Member Function Documentation

◆ Evaluate()

void VCG::Evaluate ( const PNode node,
const char *  parent,
const int  anchor 
)

Definition at line 82 of file VCG.cpp.

83{
84
85
86 //First, generate a unique name for the node
87 char * name;
88 ostrstream ost1;
89 ost1 << "NODE-" << mNodeIndex++;
90 ost1.put(0); //null terminate the ostring-stream
91 name = strdup(ost1.str());
92
93
94 //Now determine what type of node it is, and what
95 //value resides within it.
96
97 //Start making a label; use an ostrstream for easy concatenation
98
99 ostrstream ost2;
100 Variant variant;
101
102 switch(node->GetType())
103 {
104 case PEBL_OP_NODE:
105
106 ost2 << "OpNode\\n" << ((OpNode*)node)->GetOpName();
107 break;
108
109 case PEBL_DATA_NODE:
110
111 //retrieve tha vlaue from tha data node
112 variant = ((DataNode*)node)->GetValue();
113
114 ost2 << variant.GetDataTypeName() << "\\n" << variant;
115
116 break;
117
118 default:
119 ost2 << "Unknown Node Type\\nUnknown Value";
120
121 }
122
123 //Null-terminate the label stream and make it into a char array
124 ost2.put(0);
125 char* label = strdup(ost2.str());
126
127 //Now, create a new node with all the right trimmings.
128 cerr << "About to make node with: ["<< name << "] and [" << label << "]." << endl;
129
130 VCGNode * tmpNode=new VCGNode(name, label);
131
132 //Change the shape and color of the node if it is an OpNode
133 if(node->GetType() == PEBL_OP_NODE)
134 {
135 tmpNode->SetShape("ellipse");
136 tmpNode->SetBorderColor("red");
137 }
138 else if(node->GetType() == PEBL_DATA_NODE)
139 {
140 tmpNode->SetShape("box");
141 tmpNode->SetBorderColor("black");
142
143 }
144 else
145 {
146 tmpNode->SetShape("rhomb");
147 tmpNode->SetBorderColor("orange");
148
149 }
150
151
152 mGraph->AddNode(tmpNode);
153
154
155 //Now, add an edge from this node's parent to the current node
156 if(parent)
157 {
158 VCGEdge * tmpEdge = new VCGEdge(parent,name);
159 tmpEdge->SetAnchor(anchor);
160 mGraph->AddEdge(tmpEdge);
161 }
162
163 // Now, if we are an OpNode, evaluate each of the child nodes (if they exist)
164
165 if(node->GetType() == PEBL_OP_NODE)
166 {
167 PNode *left, *right;
168 left = ((OpNode*)node)->GetLeft();
169 right = ((OpNode*)node)->GetRight();
170
171 if(left) Evaluate(left, name, 1);
172 if(right) Evaluate(right, name, 2);
173 }
174
175 //Clean up after ourselves
176 free(name);
177 free(label);
178}
@ PEBL_OP_NODE
Definition PNode.h:35
@ PEBL_DATA_NODE
Definition PNode.h:36
Definition PNode.h:45
PNODE_TYPE GetType() const
Access mType data.
Definition PNode.h:61
Definition VCG.h:123
void SetAnchor(const int i)
Definition VCG.h:132
void AddNode(VCGNode *node)
Definition VCG.cpp:214
void AddEdge(VCGEdge *edge)
Definition VCG.cpp:209
Definition VCG.h:98
void SetBorderColor(const char *color)
Definition VCG.h:107
void SetShape(const char *shape)
Definition VCG.h:106
void Evaluate(const PNode *node, const char *parent, const int anchor)
Definition VCG.cpp:82
std::string GetDataTypeName() const
This returns the type as a string.
Definition Variant.cpp:891

References VCGGraph::AddEdge(), VCGGraph::AddNode(), Evaluate(), Variant::GetDataTypeName(), PNode::GetType(), PEBL_DATA_NODE, PEBL_OP_NODE, VCGEdge::SetAnchor(), VCGNode::SetBorderColor(), and VCGNode::SetShape().

Referenced by Evaluate(), and MakeGraph().

◆ MakeGraph()

void VCG::MakeGraph ( const PNode node)

Definition at line 65 of file VCG.cpp.

66{
67 //First, fill up the mGraph structure by parsing the graph
68 Evaluate(node, NULL, 1);
69}
#define NULL
Definition BinReloc.cpp:317

References Evaluate(), and NULL.

Referenced by PEBLInterpret().

◆ PrintGraph()

void VCG::PrintGraph ( )

Definition at line 71 of file VCG.cpp.

72{
73 //First, put in some identifying information
74 cout << mHeader;
75 if(mGraph)
76 {
77 cout << (*mGraph) << endl;
78 }
79}

Referenced by PEBLInterpret().


The documentation for this class was generated from the following files: