Changeset 222


Ignore:
Timestamp:
04/11/14 23:39:36 (8 years ago)
Author:
Maciej Komosinski
Message:

"Distributed" deserializable class registry, so that ExtValue? does not depend on so many other classes

Location:
cpp/frams
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/util/extvalue.cpp

    r205 r222  
    706706}
    707707
    708 PtrListTempl<ParamInterface*> ExtValue::deserializable_classes;
    709 
    710 void ExtValue::initDeserializableClasses()
    711 {
    712 deserializable_classes+=&Pt3D_Ext::getStaticParam();
    713 deserializable_classes+=&Orient_Ext::getStaticParam();
    714 deserializable_classes+=&GenoObj::getStaticParam();
     708PtrListTempl<ParamInterface*> &ExtValue::getDeserializableClasses()
     709{
     710static PtrListTempl<ParamInterface*> classes;
     711return classes;
    715712}
    716713
    717714ParamInterface *ExtValue::findDeserializableClass(const char* name)
    718715{
    719 FOREACH(ParamInterface*,cls,deserializable_classes)
     716FOREACH(ParamInterface*,cls,getDeserializableClasses())
    720717        if (!strcmp(cls->getName(),name))
    721718                return cls;
  • cpp/frams/util/extvalue.h

    r205 r222  
    160160const char* deserialize(const char* in);//< @return first character after the succesfully parsed string or NULL if failed
    161161const char* deserialize_inner(const char* in);
    162 static PtrListTempl<ParamInterface*> deserializable_classes;
    163162static ParamInterface *findDeserializableClass(const char* name);
    164 static void initDeserializableClasses();
     163static PtrListTempl<ParamInterface*> &getDeserializableClasses();
     164template<typename T> class AddDeserializable
     165{
     166  public:
     167AddDeserializable() {ExtValue::getDeserializableClasses()+=&T::getStaticParam();}
     168};
     169
    165170static SString format(SString& fmt,const ExtValue **values,int count);
    166171
     
    188193};
    189194
     195#define REGISTER_DESERIALIZABLE(name) ExtValue::AddDeserializable<name> deserializable_autoinit_ ## name;
    190196
    191197#endif
  • cpp/frams/util/sstring.cpp

    r198 r222  
    44
    55#include "sstring.h"
     6#include <common/nonstd.h> //to be sure the vsnprintf-related stuff gets included
    67
    78#ifdef SSTRING_SIMPLE
     
    399400return s;
    400401}
    401 
    402 #ifdef LINUX
    403 #define VSNPRINTF_RETURNS_REQUIRED_SIZE
    404 #endif
    405 #if defined _WIN32 && !defined __BORLANDC__
    406 #define USE_VSCPRINTF
    407 #endif
    408 
    409402
    410403#if 0 //testing _vscprintf
  • cpp/frams/vm/classes/3dobject.cpp

    r197 r222  
    203203ExtObject Pt3D_Ext::makeDynamicObject(Pt3D_Ext* p)
    204204{return ExtObject(&getStaticParam(),p);}
     205
     206ExtObject Pt3D_Ext::makeDynamicObject(const Pt3D& p)
     207{
     208Pt3D_Ext *pe=new Pt3D_Ext(p);
     209return ExtObject(&getStaticParam(),pe);
     210}
    205211
    206212//////////////////////////////////////
     
    571577return (ReferenceObj*)v.getObjectTarget(getStaticParam().getName());
    572578}
     579
     580/////////////
     581
     582REGISTER_DESERIALIZABLE(Pt3D_Ext)
     583REGISTER_DESERIALIZABLE(Orient_Ext)
  • cpp/frams/vm/classes/3dobject.h

    r197 r222  
    3838static ExtObject makeStaticObject(Pt3D* p);
    3939static ExtObject makeDynamicObject(Pt3D_Ext* p);
     40static ExtObject makeDynamicObject(const Pt3D& p);
    4041static Pt3D_Ext* fromObject(const ExtValue& v);
    4142static Param& getStaticParam();
  • cpp/frams/vm/classes/genoobj.cpp

    r219 r222  
    137137        ret->setEmpty();
    138138}
     139
     140/////////////
     141
     142REGISTER_DESERIALIZABLE(GenoObj)
Note: See TracChangeset for help on using the changeset viewer.