Revision: 1395
http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=1395&view=rev
Author: rorthomas
Date: 2010-05-22 16:21:16 +0000 (Sat, 22 May 2010)
Log Message:
-----------
added comment and description section
added explicit sections
Modified Paths:
--------------
trunk/source/serializer/serializationmodules.cpp
trunk/source/serializer/serializer.cpp
trunk/source/serializer/serializer.h
Modified: trunk/source/serializer/serializationmodules.cpp
===================================================================
--- trunk/source/serializer/serializationmodules.cpp 2010-05-21 23:10:12 UTC
(rev 1394)
+++ trunk/source/serializer/serializationmodules.cpp 2010-05-22 16:21:16 UTC
(rev 1395)
@@ -582,6 +582,10 @@
{
// setup the base descriptions, etc, then register ourself
s->registerModuleSerializer(this);
+ s->addSectionHandler("description", this);
+ s->setSectionExplicit("description", true);
+ s->addSectionHandler("comment", this);
+ s->setSectionExplicit("comment", true);
s->addCommandHandler("fileinfo", this);
s->addCommandHandler("fileformatversion", this);
}
@@ -597,7 +601,25 @@
int FileInfoSerializer::deserialize(char *line, rig_t *rig, std::string
activeSection)
{
if(!initiated) initData(rig);
- string linestr = string(line);
+ std::string linestr = std::string(line);
+
+ // ignore section header
+ if(linestr == activeSection)
+ return 1;
+
+ if(activeSection == "description")
+ {
+ if(strlen(rig->fileinfo->description) + strlen(line) < 9045)
+ {
+ strcat(rig->fileinfo->description, line);
+ strcat(rig->fileinfo->description, "\n");
+ return 1;
+ } else
+ {
+ return 0;
+ }
+ }
+
if(linestr.substr(0, 8) == "fileinfo")
{
return checkRes(1, sscanf(line, "fileinfo %s, %i, %i",
rig->fileinfo->uniquetruckid, &rig->fileinfo->categoryid,
&rig->fileinfo->truckversion));
@@ -615,7 +637,6 @@
//LogManager::getSingleton().logMessage("The Truck File
" + String(fname) +" is for a newer version or RoR! trying to continue ...");
return 0;
}
- mode=0;
}
return 0;
}
Modified: trunk/source/serializer/serializer.cpp
===================================================================
--- trunk/source/serializer/serializer.cpp 2010-05-21 23:10:12 UTC (rev
1394)
+++ trunk/source/serializer/serializer.cpp 2010-05-22 16:21:16 UTC (rev
1395)
@@ -49,18 +49,8 @@
char line[1024];
int linecounter = 0;
std::string activeSection;
-
- // first: init rig
- // TODO: IMPORTANT: FIX the rig_t initialization
- /*
- rig->patchEngineTorque = false;
- rig->forwardcommands = 0;
- rig->importcommands = 0;
- rig->wheel_contact_requested = false;
- rig->rescuer = false;
- rig->disable_default_sounds = false;
- */
-
+ bool activeSectionExplicit = false;
+
// read in truckname
ds->readLine(line, 1023);
strncpy(rig->realtruckname, line, 255);
@@ -80,8 +70,8 @@
ctx.lineNo = linecounter;
// now process the modules and try to parse the line
- // -1 = no match
- int res = processModules(line, rig, &ctx, activeSection);
+ // -1 = error, 0 = no match, > 0 = n matches
+ int res = processModules(line, rig, &ctx, activeSection,
activeSectionExplicit);
if(!activeSection.empty() && res == 0)
{
LogManager::getSingleton().logMessage("line section
parsing with no result: " + String(line));
@@ -112,24 +102,35 @@
sections[section] = module;
}
+void RoRSerializer::setSectionExplicit(std::string section, bool value)
+{
+ if(value)
+ {
+ // add it to the map
+ explictSections[section] = true;
+ } else if(!value && explictSections.find(section) !=
explictSections.end())
+ {
+ // remove it from the map
+ explictSections.erase(explictSections.find(section));
+ }
+}
void RoRSerializer::addCommandHandler(std::string command,
RoRSerializationModule *module)
{
commands[command] = module;
}
-int RoRSerializer::processModules(char *line, rig_t *rig, SerializationContext
*ctx, std::string &activeSection)
+int RoRSerializer::processModules(char *line, rig_t *rig, SerializationContext
*ctx, std::string &activeSection, bool &activeSectionExplicit)
{
- string linestr = string(line);
- // parse for commands or other sections
- // commands
+ std::string linestr = std::string(line);
+ // parse for commands
std::map < std::string, RoRSerializationModule *>::iterator it;
for(it = commands.begin(); it != commands.end() ; it++)
{
if(!it->first.size()) continue;
// check if that command is matched
- if(linestr.substr(0, it->first.size()+2) == "=="+it->first))
+ if(linestr.substr(0, it->first.size()+2) == "=="+it->first)
{
// new format
return it->second->deserialize(line+2, rig);
@@ -140,16 +141,20 @@
}
}
- // sections
+ // parse for sections
for(it = sections.begin(); it != sections.end() ; it++)
{
if(!it->first.size()) continue;
// check for a new section
- if((it->first == linestr || "=" + it->first == linestr)
+ if(!activeSectionExplicit && it->first == linestr || "=" +
it->first == linestr)
{
// match, using this module
//set section as active
activeSection = it->first;
+
+ // find out whether its explicit
+ activeSectionExplicit =
(explictSections.find(activeSection) != explictSections.end());
+
// parse this as well, could be that the section header
contains information as well
return it->second->deserialize(line, rig,
activeSection);
}
@@ -158,7 +163,8 @@
if("end_" + it->first == linestr || "=end_"+it->first ==
linestr)
{
// found section end
- activeSection = string();
+ activeSection = std::string();
+ activeSectionExplicit = false;
return 1;
}
}
Modified: trunk/source/serializer/serializer.h
===================================================================
--- trunk/source/serializer/serializer.h 2010-05-21 23:10:12 UTC (rev
1394)
+++ trunk/source/serializer/serializer.h 2010-05-22 16:21:16 UTC (rev
1395)
@@ -59,16 +59,18 @@
int registerModuleSerializer(RoRSerializationModule *module);
void addSectionHandler(std::string section, RoRSerializationModule
*module);
void addCommandHandler(std::string section, RoRSerializationModule
*module);
+ void setSectionExplicit(std::string section, bool value);
int initResources(Ogre::SceneManager *manager, Ogre::SceneNode *node,
rig_t *rig);
RoRSerializationModule *getSectionModule(rig_t *rig, std::string
section);
protected:
- int processModules(char *line, rig_t *rig, SerializationContext *ctx,
std::string &activeSection);
+ int processModules(char *line, rig_t *rig, SerializationContext *ctx,
std::string &activeSection, bool &activeSectionExplicit);
std::map < std::string, RoRSerializationModule *> sections;
+ std::map < std::string, bool> explictSections;
std::map < std::string, RoRSerializationModule *> commands;
std::vector <RoRSerializationModule *> modules;
};
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
Rigsofrods-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel