I have a parser class that I use to parse setting files, now the parser works great except when I have have two parser running at the same time. The code of the parser.h looks like this (btw, I wrote part of the parser, not the whole thing):
Code:
#ifndef __PARSER_H__
#define __PARSER_H__
#define MAXTOKEN 1024
#define MAX_BLOCK_PROPLENGTH 64 /*!< Maximum length of a property. */
#define MAX_BLOCK_VALLENGTH 256 /*!< Maximum length of a value. */
#include "../Math/Math.h"
/**
* property-value pair.
*/
typedef struct
{
char *property;
char *val;
} spair_t;
/**
* Group of spairs.
*/
typedef struct
{
int firstpair; /**< First spair. */
int numpairs; /**< Number of spairs. */
} parse_file_t;
/**
* Parser class.
* The parser class provides methods to parse files. This is specially used
* for config parsing.
*/
class Parser
{
public:
~Parser(); /**< Destructor. */
static int parseFile(const char *name);
static void StartParseBuffer(const unsigned char *buffer, const int size);
static void StartParseString(const char *string);
static bool GetToken(bool crossline);
static int GetOffset(void);
static void GoTo(const int offset);
static char token[MAXTOKEN]; /**< buffer for tokens */
static int scriptline;
static int num_blocks;
static int num_spairs; /**< Number of spairs. */
static spair_t * spairs;
static parse_file_t * parse_data;
//! Gets the value corresponding to a property in an spair.
/*!
\param spair The spair number.
\param property The property of spair value.
\return A pointer to the spair value string.
*/
static char* spair_value(int spair, char *property);
static char* spair_value_ex(int spair, const char *property);
//! Gets the value corresponding to a property in an spair.
/*!
\param spair The spair number.
\param property The property of spair value as a float value.
\return The requested float value.
*/
static float spair_float(int spair, char *property);
//! Gets the value corresponding to a property in an spair.
/*!
\param spair The spair number.
\param property The property of spair value as a int value.
\return The requested int value.
*/
static int spair_int(int spair, char *property);
//! Gets the value corresponding to a property in an spair.
/*!
\param spair The spair number.
\param property The property of spair value as a int value.
\return The requested boolean value.
*/
static bool spair_bool(int spair, char *property);
//! Gets the value corresponding to a property in an spair.
/*!
\param spair The spair number.
\param property The property of spair value as a int value.
\return The requested VECTOR3D value.
*/
static vec3 spair_vec3(int spair, char *property);
//! Gets the value corresponding to a property in an spair.
/*!
\param spair The spair number.
\param property The property of spair value as a int value.
\return The requested COLOR value.
*/
static vec4 spair_vec4(int spair, char *property);
protected:
static const unsigned char *buffer;
static const unsigned char *buf_start;
static const unsigned char *buf_end;
};
#endif /* __PARSER_H__ */
And to create a parser I use
Code:
Parser *conf_parser = new Parser;
conf_parser->parseFile(filename);
I can get the proper values with no problems at all in conf_parser. But if while I have conf_parser I create another Parser that new parser will parse the right values then I delete that new parser and go back to keep parsing with the first parser and all the values in spairs and parse_data are gone so my query functions always fail to give me the right values. What can I do ?