More work on new serializer code.

This commit is contained in:
JoelKatz
2012-09-25 22:47:59 -07:00
parent 8a5a9e0925
commit e0587a44b8
6 changed files with 134 additions and 38 deletions

View File

@@ -4,6 +4,7 @@
#include <map>
#include <boost/thread/mutex.hpp>
#include <boost/lexical_cast.hpp>
SField sfInvalid(-1), sfGeneric(0);
@@ -19,13 +20,46 @@ static boost::mutex SField::mapMutex;
SField::ref SField::getField(int code);
{
int type = code >> 16;
int field = code % 0xffff;
if ((type <= 0) || (type >= 256) || (field <= 0) || (field >= 256
return sfInvalid;
boost::mutex::scoped_lock sl(mapMutex);
std::map<int, SField*> it = unknownFieldMap.Find(code);
if (it != codeToField.end())
return *(it->second);
return *(new SField(code, static_cast<SerializedTypeID>(code>>16), code&0xffff, NULL));
switch(type)
{ // types we are willing to dynamically extend
#define FIELD(name, type, index)
#define TYPE(name, type, index) case sf##name:
#include "SerializeProto.h"
#undef FIELD
#undef TYPE
break;
default:
return sfInvalid;
}
return *(new SField(code, static_cast<SerializedTypeID>(type), field, NULL));
}
SField::ref SField::getField(int type, int value)
{
return getField(FIELD_CODE(type, value));
}
std::string SField::getName() cosnt
{
if (fieldName != NULL)
return fieldName;
if (fieldValue == 0)
return "";
return boost::lexical_cast<std::string>(static_cast<int>(fieldType)) + "/" +
boost::lexical_cast<std::string>(fieldValue);
}