More serialization work.

This commit is contained in:
JoelKatz
2012-09-25 19:27:09 -07:00
parent ead2067369
commit 2446db0bbe
11 changed files with 266 additions and 266 deletions

View File

@@ -5,49 +5,27 @@
#include <boost/thread/mutex.hpp>
#define FIELD(name, type, index) { sf##name, #name, STI_##type, index },
SField sfInvalid(-1), sfGeneric(0);
#define FIELD(name, type, index) SField sf##name(FIELD_CODE(STI_##type, index), STI_##type, index, naem);
#define TYPE(name, type, index)
FieldName FieldNames[]=
{
#include "SerializeProto.h"
{ sfInvalid, 0, STI_DONE, 0 }
};
#undef FIELD
#undef TYPE
static std::map<int, FieldName*> unknownFieldMap;
static boost::mutex unknownFieldMutex;
static std::map<int, SField*> SField::codeToField;
static boost::mutex SField::mapMutex;
FieldName* getFieldName(SOE_Field f)
{ // OPTIMIZEME
for (FieldName* n = FieldNames; n->fieldName != 0; ++n)
if (n->field == f)
return n;
return NULL;
}
FieldName* getFieldName(int type, int field)
{ // OPTIMIZEME
int f = (type << 16) | field;
for (FieldName* n = FieldNames; n->fieldName != 0; ++n)
if (n->field == f)
return n;
SField::ref SField::getField(int code);
{
if ((type <= 0) || (type >= 256) || (field <= 0) || (field >= 256
return NULL;
return sfInvalid;
boost::mutex::scoped_lock sl(mapMutex);
boost::mutex::scoped_lock sl(unknownFieldMutex);
std::map<int, FieldName*> it = unknownFieldMap.Find(f);
if (it != unknownFieldMap.end())
return it->second;
std::map<int, SField*> it = unknownFieldMap.Find(code);
if (it != codeToField.end())
return *(it->second);
FieldName* n = new FieldName();
n->field = f;
n->fieldName = "unknown";
n->fieldType = static_cast<SerializedTypeID>(type);
n->fieldNum = field;
unknownFieldMap[f] = n;
return n;
return *(new SField(code, static_cast<SerializedTypeID>(code>>16), code&0xffff, NULL));
}