Boost logo

Boost Users :

From: Chengyuan Ma (chengyuan_ma_at_[hidden])
Date: 2008-02-01 13:31:23


I have a class needs to be serialized into an XML file. I can save the
object into an XML file, but i can not load it back. I found the problem is
the dynamic array, "double *pMixtureWeight".

What's the correct way to serialize a dynamic array into a XML file if i
don't want to change it to a vector<double>?

thx a lot!

class Model
{
public:
 Model();
virtual ~Model() ;

private:
 // serialization support
 friend class boost::serialization::access;
 template<class Archive>
 void serialize(Archive & ar, const unsigned int /* file_version */)
 {
  ar & boost::serialization::make_nvp("FeatureDim", FeatureDim) ;
  ar & boost::serialization::make_nvp("MixtureNum", NumMixtures) ;

  for(int ii = 0 ; ii < m_iNumMixtures; ii ++ )
  {
   string tag = "weight_" + boost::lexical_cast<string>(ii + 1) ;
   ar & boost::serialization::make_nvp(tag.c_str(), pMixtureWeight[ii]) ;
  }
}

private:
int FeatureDim;
int NumMixtures;
double *pMixtureWeight;
};


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net