void serialize(IArchive& ar, IndividualHumanMalaria::gametocytes_strain_map_t& mapping)
 {
     size_t count = ar.IsWriter() ? mapping.size() : -1;
     ar.startArray(count);
     if (ar.IsWriter())
     {
         for (auto& entry : mapping)
         {
             StrainIdentity* strain = const_cast<StrainIdentity*>(&entry.first);
             ar.startObject();
                 ar.labelElement("key"); serialize(ar, strain);
                 ar.labelElement("value") & entry.second;
             ar.endObject();
         }
     }
     else
     {
         for (size_t i = 0; i < count; i++)
         {
             StrainIdentity* strain;
             int64_t value;
             ar.startObject();
                 ar.labelElement("key"); serialize(ar, strain);
                 ar.labelElement("value") & value;
             ar.endObject();
             mapping[*strain] = value;
         }
     }
     ar.endArray();
 }
Exemple #2
0
    void ISerializable::serialize(IArchive& ar, ISerializable*& obj)
    {
        static std::string nullptr_string( "nullptr" );

        if ( ar.IsWriter() && ( obj == nullptr ) )
        {
            ar.startClass( nullptr_string );
            ar.endClass();
            return;
        }

        std::string class_name = ar.IsWriter() ? obj->GetClassName() : "__UNK__";
        ar.startClass(class_name);

        if ( ar.IsReader() && (class_name == nullptr_string) )
        {
            ar.endClass();
            obj = nullptr;
            return;
        }

        auto serialize_function = SerializationRegistrar::_get_serializer(class_name);
        if (!ar.IsWriter())
        {
            auto constructor_function = SerializationRegistrar::_get_constructor(class_name);
            if( constructor_function == nullptr )
            {
                std::stringstream msg;
                msg << "Could not find constructor for class_name='" << class_name << "'";
                throw SerializationException( __FILE__, __LINE__, __FUNCTION__, msg.str().c_str() );
            }
            obj = constructor_function();
        }
        serialize_function(ar, obj);
        ar.endClass();
    }
Exemple #3
0
    void VectorProbabilities::serialize(IArchive& ar, VectorProbabilities*& probabilities)
    {
        probabilities = ar.IsWriter() ? probabilities : new VectorProbabilities();

        ar.startObject();
            ar.labelElement("effective_host_population") & probabilities->effective_host_population;

            ar.labelElement("outdoorareakilling") & probabilities->outdoorareakilling;
            ar.labelElement("outdoorareakilling_male") & probabilities->outdoorareakilling_male;
            ar.labelElement("diebeforeattempttohumanfeed") & probabilities->diebeforeattempttohumanfeed;
            ar.labelElement("diewithoutattemptingfeed") & probabilities->diewithoutattemptingfeed;
            ar.labelElement("survivewithoutsuccessfulfeed") & probabilities->survivewithoutsuccessfulfeed;
            ar.labelElement("successfulfeed_animal") & probabilities->successfulfeed_animal;
            ar.labelElement("successfulfeed_AD") & probabilities->successfulfeed_AD;
            ar.labelElement("indoorattempttohumanfeed") & probabilities->indoorattempttohumanfeed;
            ar.labelElement("outdoorattempttohumanfeed") & probabilities->outdoorattempttohumanfeed;

            ar.labelElement("ADbiocontrol_additional_mortality") & probabilities->ADbiocontrol_additional_mortality;

            ar.labelElement("outdoor_returningmortality") & probabilities->outdoor_returningmortality;

            ar.labelElement("indoor_diebeforefeeding") & probabilities->indoor_diebeforefeeding;
            ar.labelElement("indoor_hostnotavailable") & probabilities->indoor_hostnotavailable;
            ar.labelElement("indoor_dieduringfeeding") & probabilities->indoor_dieduringfeeding;
            ar.labelElement("indoor_diepostfeeding") & probabilities->indoor_diepostfeeding;
            ar.labelElement("indoor_successfulfeed_human") & probabilities->indoor_successfulfeed_human;
            ar.labelElement("indoor_successfulfeed_AD") & probabilities->indoor_successfulfeed_AD;

            ar.labelElement("outdoor_diebeforefeeding") & probabilities->outdoor_diebeforefeeding;
            ar.labelElement("outdoor_hostnotavailable") & probabilities->outdoor_hostnotavailable;
            ar.labelElement("outdoor_dieduringfeeding") & probabilities->outdoor_dieduringfeeding;
            ar.labelElement("outdoor_diepostfeeding") & probabilities->outdoor_diepostfeeding;
            ar.labelElement("outdoor_successfulfeed_human") & probabilities->outdoor_successfulfeed_human;

            ar.labelElement("sugarTrapKilling") & probabilities->sugarTrapKilling;
            ar.labelElement("individualRepellentBlock") & probabilities->individualRepellentBlock;

            ar.labelElement("attraction_ADOV") & probabilities->attraction_ADOV;
            ar.labelElement("attraction_ADIV") & probabilities->attraction_ADIV;
            ar.labelElement("kill_livestockfeed") & probabilities->kill_livestockfeed;
            ar.labelElement("kill_PFV") & probabilities->kill_PFV;
            ar.labelElement("spatial_repellent") & probabilities->spatial_repellent;
            ar.labelElement("nooutdoorhumanfound") & probabilities->nooutdoorhumanfound;
            ar.labelElement("outdoorRestKilling") & probabilities->outdoorRestKilling;
        ar.endObject();
    }
    void PropertyValueChanger::serialize(IArchive& ar, PropertyValueChanger* obj)
    {
        BaseIntervention::serialize( ar, obj );
        PropertyValueChanger& changer = *obj;

        ar.labelElement("target_property_key"  ) & changer.target_property_key;
        ar.labelElement("target_property_value") & changer.target_property_value;
        ar.labelElement("probability"          ) & changer.probability;
        ar.labelElement("revert"               ) & changer.revert;
        ar.labelElement("max_duration"         ) & changer.max_duration;
        ar.labelElement("action_timer"         ) & changer.action_timer;
        ar.labelElement("reversion_timer"      ) & changer.reversion_timer;

        if( !ar.IsWriter() )
        {
            changer.target_property_key.constraints   = "<demographics>::Defaults.Individual_Properties.*.Property.<keys>";
            changer.target_property_value.constraints = "<demographics>::Defaults.Individual_Properties.*.Value.<keys>";

            //TODO - Need to actual use the constrained string
        }
    }
    void PropertyValueChanger::serialize(IArchive& ar, PropertyValueChanger* obj)
    {
        BaseIntervention::serialize( ar, obj );
        PropertyValueChanger& changer = *obj;

        ar.labelElement("target_property_key"  ) & changer.target_property_key;
        ar.labelElement("target_property_value") & changer.target_property_value;
        ar.labelElement("probability"          ) & changer.probability;
        ar.labelElement("revert"               ) & changer.revert;
        ar.labelElement("max_duration"         ) & changer.max_duration;
        ar.labelElement("action_timer"         ) & changer.action_timer;
        ar.labelElement("reversion_timer"      ) & changer.reversion_timer;

        if( !ar.IsWriter() )
        {
            changer.target_property_key.constraints   = IPKey::GetConstrainedStringConstraintKey();
            changer.target_property_value.constraints = IPKey::GetConstrainedStringConstraintValue();

            //TODO - Need to actual use the constrained string
        }
    }