Commit fb3f8597 authored by Mathieu Faverge's avatar Mathieu Faverge

Allow multiple occurences of the same event definition with different ids

parent b2c0afcc
......@@ -40,7 +40,7 @@
** - VUCHENER Clément
**
*/
#include <assert.h>
#include <string>
#include <cstring>
#include <iostream>
......@@ -74,18 +74,15 @@ using namespace std;
i++; \
}
#define INSERT_EVENT(name, required) \
{ \
_EventDefs[_##name]._name = #name; \
_EventDefs[_##name]._id = _##name; \
_EventDefs[_##name]._trid = -1; \
_EventDefs[_##name]._fdpresent = 0; \
_EventDefs[_##name]._fdrequired = required; \
i++; \
#define INSERT_AVAILABLE_DEF(name, required) \
{ \
PajeEventDef _evdef; \
_evdef._id = _##name; \
_evdef._fdrequired = required; \
_AvailableEvDef.insert(pair<string, PajeEventDef>(#name, _evdef)); \
}
std::map<std::string, int> ParserDefinitionPaje::_EvDefStr2Id;
std::map<std::string, ParserDefinitionPaje::PajeEventDef> ParserDefinitionPaje::_AvailableEvDef;
std::map<std::string, int> ParserDefinitionPaje::_FTypeStr2Code;
bool ParserDefinitionPaje::_initialized = false;
int ParserDefinitionPaje::_nbparsers = 0;
......@@ -94,95 +91,76 @@ ParserDefinitionPaje::ParserDefinitionPaje() {
int i;
_state = _OUT_A_DEFINITION;
_defid = -1;
_defid = 0;
_nbparsers++;
if ( !_initialized ) {
_initialized = true;
// Initialize the list of EventDef's names
_EvDefStr2Id.insert(pair<string, int>("PajeDefineContainerType", _PajeDefineContainerType ));
_EvDefStr2Id.insert(pair<string, int>("PajeDefineEventType" , _PajeDefineEventType ));
_EvDefStr2Id.insert(pair<string, int>("PajeDefineStateType" , _PajeDefineStateType ));
_EvDefStr2Id.insert(pair<string, int>("PajeDefineVariableType" , _PajeDefineVariableType ));
_EvDefStr2Id.insert(pair<string, int>("PajeDefineLinkType" , _PajeDefineLinkType ));
_EvDefStr2Id.insert(pair<string, int>("PajeDefineEntityValue" , _PajeDefineEntityValue ));
_EvDefStr2Id.insert(pair<string, int>("PajeCreateContainer" , _PajeCreateContainer ));
_EvDefStr2Id.insert(pair<string, int>("PajeDestroyContainer" , _PajeDestroyContainer ));
_EvDefStr2Id.insert(pair<string, int>("PajeNewEvent" , _PajeNewEvent ));
_EvDefStr2Id.insert(pair<string, int>("PajeSetState" , _PajeSetState ));
_EvDefStr2Id.insert(pair<string, int>("PajePushState" , _PajePushState ));
_EvDefStr2Id.insert(pair<string, int>("PajePopState" , _PajePopState ));
_EvDefStr2Id.insert(pair<string, int>("PajeResetState" , _PajeResetState ));
_EvDefStr2Id.insert(pair<string, int>("PajeSetVariable" , _PajeSetVariable ));
_EvDefStr2Id.insert(pair<string, int>("PajeAddVariable" , _PajeAddVariable ));
_EvDefStr2Id.insert(pair<string, int>("PajeSubVariable" , _PajeSubVariable ));
_EvDefStr2Id.insert(pair<string, int>("PajeStartLink" , _PajeStartLink ));
_EvDefStr2Id.insert(pair<string, int>("PajeEndLink" , _PajeEndLink ));
/* Should be changed into a singleton structure */
// Initialize the list of types available for field in EventDef declaration
// This list connect the available types for event definition to a unique bitmask
_FTypeStr2Code.insert(pair<string, int>("int" ,_FieldType_Int ));
_FTypeStr2Code.insert(pair<string, int>("hex" ,_FieldType_Hex ));
_FTypeStr2Code.insert(pair<string, int>("date" ,_FieldType_Date ));
_FTypeStr2Code.insert(pair<string, int>("double",_FieldType_Double ));
_FTypeStr2Code.insert(pair<string, int>("string",_FieldType_String ));
_FTypeStr2Code.insert(pair<string, int>("color" ,_FieldType_Color ));
}
// Initialize the list of Field's names mandatory for each EventDef declaration
i = 0;
_FieldNames.resize( FIELDNAME_SIZEMAX );
INSERT_FNAME(Time, _FieldType_Date );
INSERT_FNAME(Name, _FieldType_Int | _FieldType_String );
INSERT_FNAME(Alias, _FieldType_Int | _FieldType_String );
INSERT_FNAME(Type, _FieldType_Int | _FieldType_String );
INSERT_FNAME(Container, _FieldType_Int | _FieldType_String );
INSERT_FNAME(StartContainerType, _FieldType_Int | _FieldType_String );
INSERT_FNAME(EndContainerType, _FieldType_Int | _FieldType_String );
INSERT_FNAME(StartContainer, _FieldType_Int | _FieldType_String );
INSERT_FNAME(EndContainer, _FieldType_Int | _FieldType_String );
INSERT_FNAME(Color, _FieldType_Color );
INSERT_FNAME(Value, _FieldType_Int | _FieldType_String | _FieldType_Double);
INSERT_FNAME(Key, _FieldType_Int | _FieldType_String );
INSERT_FNAME(File, _FieldType_String );
INSERT_FNAME(Line, _FieldType_Int | _FieldType_String );
// Initialize the map between the field names and the associated id
_nbFieldNames = FIELDNAME_SIZE;
for(i=0; i<FIELDNAME_SIZE; i++) {
_FNameStr2Id.insert(pair<string, int>(_FieldNames[i]._name, i));
}
// Initialize the list of Field's names for EventDef declaration
i = 0;
_FieldNames.resize( FIELDNAME_SIZEMAX );
INSERT_FNAME(Time, _FieldType_Date );
INSERT_FNAME(Name, _FieldType_Int | _FieldType_String );
INSERT_FNAME(Alias, _FieldType_Int | _FieldType_String );
INSERT_FNAME(Type, _FieldType_Int | _FieldType_String );
INSERT_FNAME(Container, _FieldType_Int | _FieldType_String );
INSERT_FNAME(StartContainerType, _FieldType_Int | _FieldType_String );
INSERT_FNAME(EndContainerType, _FieldType_Int | _FieldType_String );
INSERT_FNAME(StartContainer, _FieldType_Int | _FieldType_String );
INSERT_FNAME(EndContainer, _FieldType_Int | _FieldType_String );
INSERT_FNAME(Color, _FieldType_Color );
INSERT_FNAME(Value, _FieldType_Int | _FieldType_String | _FieldType_Double);
INSERT_FNAME(Key, _FieldType_Int | _FieldType_String );
INSERT_FNAME(File, _FieldType_String );
INSERT_FNAME(Line, _FieldType_Int | _FieldType_String );
// Initialize the map between the field names and the associated id
_nbFieldNames = FIELDNAME_SIZE;
for(i=0; i<FIELDNAME_SIZE; i++) {
_FNameStr2Id.insert(pair<string, int>(_FieldNames[i]._name, i));
}
// Former types no longer used in Paje format
_FNameStr2Id.insert(pair<string, int>("ContainerType" , _PajeFN_ContainerType ));
_FNameStr2Id.insert(pair<string, int>("EntityType" , _PajeFN_EntityType ));
_FNameStr2Id.insert(pair<string, int>("SourceContainerType", _PajeFN_SourceContainerType ));
_FNameStr2Id.insert(pair<string, int>("DestContainerType" , _PajeFN_DestContainerType ));
_FNameStr2Id.insert(pair<string, int>("SourceContainer" , _PajeFN_SourceContainer ));
_FNameStr2Id.insert(pair<string, int>("DestContainer" , _PajeFN_DestContainer ));
// Initialize the list of Events available
INSERT_AVAILABLE_DEF(PajeDefineContainerType, CODE2(Name) | CODE2(Alias) | CODE2(Type) );
INSERT_AVAILABLE_DEF(PajeDefineEventType , CODE2(Name) | CODE2(Alias) | CODE2(Type) );
INSERT_AVAILABLE_DEF(PajeDefineStateType , CODE2(Name) | CODE2(Alias) | CODE2(Type) );
INSERT_AVAILABLE_DEF(PajeDefineVariableType , CODE2(Name) | CODE2(Alias) | CODE2(Type) );
INSERT_AVAILABLE_DEF(PajeDefineEntityValue , CODE2(Name) | CODE2(Alias) | CODE2(Type) );
INSERT_AVAILABLE_DEF(PajeDestroyContainer , CODE2(Name) | CODE2(Alias) | CODE2(Time) | CODE2(Type) );
INSERT_AVAILABLE_DEF(PajeCreateContainer , CODE2(Name) | CODE2(Alias) | CODE2(Time) | CODE2(Type) | CODE2(Container) );
INSERT_AVAILABLE_DEF(PajeDefineLinkType , CODE2(Name) | CODE2(Alias) | CODE2(Type) | CODE2(StartContainerType) | CODE2(EndContainerType) );
INSERT_AVAILABLE_DEF(PajeSetState , CODE2(Time) | CODE2(Type) | CODE2(Container) | CODE2(Value) );
INSERT_AVAILABLE_DEF(PajePushState , CODE2(Time) | CODE2(Type) | CODE2(Container) | CODE2(Value) );
INSERT_AVAILABLE_DEF(PajePopState , CODE2(Time) | CODE2(Type) | CODE2(Container) );
INSERT_AVAILABLE_DEF(PajeResetState , CODE2(Time) | CODE2(Type) | CODE2(Container) );
INSERT_AVAILABLE_DEF(PajeNewEvent , CODE2(Time) | CODE2(Type) | CODE2(Container) | CODE2(Value) );
INSERT_AVAILABLE_DEF(PajeSetVariable , CODE2(Time) | CODE2(Type) | CODE2(Container) | CODE2(Value) );
INSERT_AVAILABLE_DEF(PajeAddVariable , CODE2(Time) | CODE2(Type) | CODE2(Container) | CODE2(Value) );
INSERT_AVAILABLE_DEF(PajeSubVariable , CODE2(Time) | CODE2(Type) | CODE2(Container) | CODE2(Value) );
INSERT_AVAILABLE_DEF(PajeStartLink , CODE2(Time) | CODE2(Type) | CODE2(Container) | CODE2(Value) | CODE2(Key) | CODE2(StartContainer) );
INSERT_AVAILABLE_DEF(PajeEndLink , CODE2(Time) | CODE2(Type) | CODE2(Container) | CODE2(Value) | CODE2(Key) | CODE2(EndContainer) );
// Former types no longer used in Paje format
_FNameStr2Id.insert(pair<string, int>("ContainerType" , _PajeFN_ContainerType ));
_FNameStr2Id.insert(pair<string, int>("EntityType" , _PajeFN_EntityType ));
_FNameStr2Id.insert(pair<string, int>("SourceContainerType", _PajeFN_SourceContainerType ));
_FNameStr2Id.insert(pair<string, int>("DestContainerType" , _PajeFN_DestContainerType ));
_FNameStr2Id.insert(pair<string, int>("SourceContainer" , _PajeFN_SourceContainer ));
_FNameStr2Id.insert(pair<string, int>("DestContainer" , _PajeFN_DestContainer ));
// Initialize the list of Events available
i = 0;
_EventDefs.resize(PAJE_EVENTDEF_SIZE);
INSERT_EVENT(PajeDefineContainerType, CODE2(Name) | CODE2(Alias) | CODE2(Type) );
INSERT_EVENT(PajeDefineEventType , CODE2(Name) | CODE2(Alias) | CODE2(Type) );
INSERT_EVENT(PajeDefineStateType , CODE2(Name) | CODE2(Alias) | CODE2(Type) );
INSERT_EVENT(PajeDefineVariableType , CODE2(Name) | CODE2(Alias) | CODE2(Type) );
INSERT_EVENT(PajeDefineEntityValue , CODE2(Name) | CODE2(Alias) | CODE2(Type) );
INSERT_EVENT(PajeDestroyContainer , CODE2(Name) | CODE2(Alias) | CODE2(Time) | CODE2(Type) );
INSERT_EVENT(PajeCreateContainer , CODE2(Name) | CODE2(Alias) | CODE2(Time) | CODE2(Type) | CODE2(Container) );
INSERT_EVENT(PajeDefineLinkType , CODE2(Name) | CODE2(Alias) | CODE2(Type) | CODE2(StartContainerType) | CODE2(EndContainerType) );
INSERT_EVENT(PajeSetState , CODE2(Time) | CODE2(Type) | CODE2(Container) | CODE2(Value) );
INSERT_EVENT(PajePushState , CODE2(Time) | CODE2(Type) | CODE2(Container) | CODE2(Value) );
INSERT_EVENT(PajePopState , CODE2(Time) | CODE2(Type) | CODE2(Container) );
INSERT_EVENT(PajeResetState , CODE2(Time) | CODE2(Type) | CODE2(Container) );
INSERT_EVENT(PajeNewEvent , CODE2(Time) | CODE2(Type) | CODE2(Container) | CODE2(Value) );
INSERT_EVENT(PajeSetVariable , CODE2(Time) | CODE2(Type) | CODE2(Container) | CODE2(Value) );
INSERT_EVENT(PajeAddVariable , CODE2(Time) | CODE2(Type) | CODE2(Container) | CODE2(Value) );
INSERT_EVENT(PajeSubVariable , CODE2(Time) | CODE2(Type) | CODE2(Container) | CODE2(Value) );
INSERT_EVENT(PajeStartLink , CODE2(Time) | CODE2(Type) | CODE2(Container) | CODE2(Value) | CODE2(Key) | CODE2(StartContainer) );
INSERT_EVENT(PajeEndLink , CODE2(Time) | CODE2(Type) | CODE2(Container) | CODE2(Value) | CODE2(Key) | CODE2(EndContainer) );
}
}
ParserDefinitionPaje::~ParserDefinitionPaje() {
......@@ -200,13 +178,14 @@ ParserDefinitionPaje::~ParserDefinitionPaje() {
_nbparsers--;
if ( (_nbparsers == 0) && _initialized ) {
_FTypeStr2Code.clear();
_EvDefStr2Id.clear();
_AvailableEvDef.clear();
_initialized = false;
}
}
void ParserDefinitionPaje::enter_definition(const PajeLine_t *line){
int defid, trid;
PajeDefinition def;
int evtdefid, trid;
char *defname = line->_tokens[2];
char *tridstr = line->_tokens[3];
......@@ -236,15 +215,13 @@ void ParserDefinitionPaje::enter_definition(const PajeLine_t *line){
}
// Try to find the name
if ( _EvDefStr2Id.find(defname) == _EvDefStr2Id.end() ) {
if ( _AvailableEvDef.find(defname) == _AvailableEvDef.end() ) {
Error::set(Error::VITE_ERR_UNKNOWN_EVENT_DEF, line->_id, Error::VITE_ERRCODE_ERROR);
return;
}
defid = _EvDefStr2Id[defname];
// Check if it is the first time we see this Event
if ( _EventDefs[defid]._trid != -1 ) {
if ( _EvDefTrId2Id.find(trid) != _EvDefTrId2Id.end() ) {
Error::set(Error::VITE_ERR_EVENT_ALREADY_DEF, line->_id, Error::VITE_ERRCODE_ERROR);
return;
}
......@@ -254,11 +231,18 @@ void ParserDefinitionPaje::enter_definition(const PajeLine_t *line){
Error::set(Error::VITE_ERR_EXTRA_TOKEN, line->_id, Error::VITE_ERRCODE_WARNING);
}
// Everything is ok, we start to store the event
_EventDefs[defid]._trid = trid;
_defid = defid;
// Everything is ok, we initialize the currentEvtDef
assert(_defid == _EventDefs.size());
def._name = defname;
def._id = _AvailableEvDef[defname]._id;
def._trid = trid;
def._fdpresent = 0;
def._fdrequired = _AvailableEvDef[defname]._fdrequired;
_EventDefs.push_back( def );
_state = _IN_A_DEFINITION;
_EvDefTrId2Id.insert(pair<int, int>(trid, defid));
_EvDefTrId2Id.insert(pair<int, int>(trid, _defid));
return;
}
......@@ -281,15 +265,16 @@ void ParserDefinitionPaje::leave_definition(const PajeLine_t *line){
// We remove the definition
_EvDefTrId2Id.erase(_EventDefs[_defid]._trid);
_EventDefs[_defid]._fields.clear();
_EventDefs[_defid]._trid = -1;
_EventDefs.pop_back();
assert( _defid == _EventDefs.size() );
return;
}
#ifdef DBG_PARSER_PAJE
PajeDef::print(&_FieldNames,&_EventDefs[_defid]);
#endif
_defid = -1;
_defid++;
assert( _defid == _EventDefs.size() );
}
void ParserDefinitionPaje::add_field_to_definition(const PajeLine_t *line){
......
......@@ -93,8 +93,12 @@ class ParserDefinitionPaje {
*/
private:
struct PajeEventDef {
int _id;
int _fdrequired;
};
static std::map<std::string, int> _EvDefStr2Id;
static std::map<std::string, PajeEventDef> _AvailableEvDef;
static std::map<std::string, int> _FTypeStr2Code;
static bool _initialized;
static int _nbparsers;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment