added dereference and indirection operators to util/refptr, converted parser to use refptr<Node> as YYSTYPE

git-svn-id: svn://anubis/fart/trunk@94 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
Josh Holtrop committed 2009-02-10 00:37:49 +00:00
1 parent c6e1a2c7e4
commit 0181e82653
2 files changed
+42 -22

No files matched your search

+25 -17
View File
@@ -30,14 +30,16 @@ class Node
{
public:
Node();
Node(int type, void * ptr);
~Node();
int type;
void * ptr;
double * the_double;
Material * the_Material;
Vector * the_Vector;
};
static Scene * g_scene;
#define YYSTYPE Node
#define YYSTYPE refptr<Node>
%}
@@ -142,12 +144,14 @@ material_item: COLOR vector
number: DEC_NUMBER {
double * ptr = new double;
*ptr = atoi(yytext);
$$.ptr = ptr;
$$ = new Node();
$$->the_double = ptr;
}
| REAL_NUMBER {
double * ptr = new double;
*ptr = atof(yytext);
$$.ptr = ptr;
$$ = new Node();
$$->the_double = ptr;
}
;
@@ -196,14 +200,12 @@ union: UNION LCURLY boolean_items RCURLY
vector: LESS number COMMA number COMMA number GREATER {
Vector * ptr = new Vector();
(*ptr)[0] = * (double *) $2.ptr;
(*ptr)[1] = * (double *) $4.ptr;
(*ptr)[2] = * (double *) $6.ptr;
$$.ptr = ptr;
delete (double *) $2.ptr;
delete (double *) $4.ptr;
delete (double *) $6.ptr;
}
(*ptr)[0] = * (double *) $2->the_double;
(*ptr)[1] = * (double *) $4->the_double;
(*ptr)[2] = * (double *) $6->the_double;
$$ = new Node();
$$->the_Vector = ptr;
}
;
%%
@@ -223,11 +225,17 @@ int parse(Scene * scene, const char * fileName)
Node::Node()
{
type = -1;
ptr = NULL;
the_double = NULL;
the_Material = NULL;
the_Vector = NULL;
}
Node::Node(int type, void * ptr)
Node::~Node()
{
this->type = type;
this->ptr = ptr;
if (the_double != NULL)
delete the_double;
if (the_Material != NULL)
delete the_Material;
if (the_Vector != NULL)
delete the_Vector;
}