formatting 90% done; encapsulated everything in the TinyJS namespace, and renamed...
[tinyjs-rewrite.git] / src / varlink.cpp
bloba1c3a703e5974295e34ae643cdac5599d385c658
2 #include "private.h"
4 namespace TinyJS
6 VarLink::VarLink(Variable* nvar, const std::string& nname)
8 #if DEBUG_MEMORY
9 mark_allocated(this);
10 #endif
11 this->name = nname;
12 this->nextSibling = 0;
13 this->prevSibling = 0;
14 this->var = nvar->ref();
15 this->owned = false;
18 VarLink::VarLink(const VarLink& link)
20 // Copy constructor
21 #if DEBUG_MEMORY
22 mark_allocated(this);
23 #endif
24 this->name = link.name;
25 this->nextSibling = 0;
26 this->prevSibling = 0;
27 this->var = link.var->ref();
28 this->owned = false;
31 VarLink::~VarLink()
33 #if DEBUG_MEMORY
34 mark_deallocated(this);
35 #endif
36 var->unref();
39 void VarLink::replaceWith(Variable* newVar)
41 Variable* oldVar = var;
42 var = newVar->ref();
43 oldVar->unref();
46 void VarLink::replaceWith(VarLink* newVar)
48 if(newVar)
50 replaceWith(newVar->var);
52 else
54 replaceWith(new Variable());
58 int VarLink::getIntName()
60 return atoi(name.c_str());
63 void VarLink::setIntName(int n)
65 char sIdx[64];
66 sprintf_s(sIdx, sizeof(sIdx), "%d", n);
67 name = sIdx;