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:
parent
c6e1a2c7e4
commit
0181e82653
@ -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;
|
||||
}
|
||||
|
@ -9,17 +9,19 @@ class refptr
|
||||
{
|
||||
public:
|
||||
refptr<T>();
|
||||
refptr<T>(const T * ptr);
|
||||
refptr<T>(T * ptr);
|
||||
refptr<T>(const refptr<T> & orig);
|
||||
refptr<T> & operator=(const refptr<T> & orig);
|
||||
refptr<T> & operator=(const T * ptr);
|
||||
refptr<T> & operator=(T * ptr);
|
||||
~refptr<T>();
|
||||
T & operator*();
|
||||
T * operator->();
|
||||
|
||||
private:
|
||||
void cloneFrom(const refptr<T> & orig);
|
||||
void destroy();
|
||||
|
||||
const T * m_ptr;
|
||||
T * m_ptr;
|
||||
int * m_refCount;
|
||||
};
|
||||
|
||||
@ -29,7 +31,7 @@ template <typename T> refptr<T>::refptr()
|
||||
m_refCount = NULL;
|
||||
}
|
||||
|
||||
template <typename T> refptr<T>::refptr(const T * ptr)
|
||||
template <typename T> refptr<T>::refptr(T * ptr)
|
||||
{
|
||||
m_ptr = ptr;
|
||||
m_refCount = new int;
|
||||
@ -48,7 +50,7 @@ template <typename T> refptr<T> & refptr<T>::operator=(const refptr<T> & orig)
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename T> refptr<T> & refptr<T>::operator=(const T * ptr)
|
||||
template <typename T> refptr<T> & refptr<T>::operator=(T * ptr)
|
||||
{
|
||||
destroy();
|
||||
m_ptr = ptr;
|
||||
@ -86,5 +88,15 @@ template <typename T> void refptr<T>::destroy()
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> T & refptr<T>::operator*()
|
||||
{
|
||||
return *m_ptr;
|
||||
}
|
||||
|
||||
template <typename T> T * refptr<T>::operator->()
|
||||
{
|
||||
return m_ptr;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user