|
Boost Users : |
From: Frank Bergemann (FBergemann_at_[hidden])
Date: 2007-04-22 03:10:28
i use an external XML format for configuration of CORBA (MICO) data and
managed to align that with boost::serialization
(To not write my own encoder/decoder and to minimize efforts for my
module, in case the customer wants more CORBA objects/methods in future.
Actually i think it would be a good options to let generate the
boost::serialitzation helper file directly by MICO idl compiler.)
OK, for this now i have to check, that the (external, non by
boost::serialization generated) XML image is _actually_ compliant with
C/C++ data structures - especially for dynamic sized data. That is also
covered now, the checks do fine.
But what i didn't manage is to get the _location_ of error in the XML
file - in case there is an error.
I tried use an make_nvp_wrapper:
class MakeNVPPathConcat
{
std::string org;
public:
static std::string make_nvp_path_; // TODO: make private, use
accessor
MakeNVPPathConcat(std::string name) { org = make_nvp_path_;
make_nvp_path_ += (make_nvp_path_.empty())? "" : "::";
make_nvp_path_ += name;
}
~MakeNVPPathConcat() { make_nvp_path_ = org;
}
};
namespace boost {
namespace serialization {
/************************************************
*
* boost::serialization::make_nvp(...) wrapper
*
************************************************/
template<class T>
inline
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
const
#endif
boost::serialization::nvp<T> make_nvp_wrapper (const char *
name, T & t )
{
std::string strName ( name );
MakeNVPPathConcat makeNVPPathConcat( strName );
return boost::serialization::make_nvp<T>( name, t );
}
} // namespace serialization
} // namespace boost
Then using the ( i hoped ) recursively concatenated path information
e.g. here:
template<class Archive, int TID, int max>
void load ( Archive & ar,
BoundedSequenceTmpl<CORBA::Short, TID, max> &p,
const unsigned int version)
{
std::string const
myname("boost::serialization::load[BoundedSequenceTmpl<CORBA::Short,
TID, max>]");
std::string str;
ar & make_nvp_wrapper("value", str);
std::string::size_type strlength = str.size();
if (strlength > p.maximum()) {
std::ostringstream err;
err <<myname << " - internal error: can't import XML
image for <"
<<
MakeNVPPathConcat::make_nvp_path_
<< "> (type CORBA object
BoundedSequenceTmpl<CORBA::Short, TID, max>) - size #"
<< strlength
<< " exceeds maximum length #"
<< p.maximum();
throw std::runtime_error(err.str());
}
p.length(strlength);
for (std::string::size_type pos=0; pos<strlength; ++pos) {
p[pos] = str.at(pos);
}
}
But it didn't work.
I was 1st wondering if my MakeNVPPathConcat might go out of scope too
early.
But finally i found out, that the serialize (load&save) helpers are not
invoked recursively(???)
Because if i use a modified version of my wrapper:
class MakeNVPPathConcat // TODO: hide this one
{
std::string org;
public:
// TODO: make private, use accessor
static std::string make_nvp_path_;
MakeNVPPathConcat(std::string name) { OUSTprotoDebug("###
c'tor");
org = make_nvp_path_;
make_nvp_path_ += (make_nvp_path_.empty())? "" : "::";
make_nvp_path_ += name;
}
~MakeNVPPathConcat() { // make_nvp_path_ = org;
OUSTprotoDebug("### d'tor");
make_nvp_path_
+= "-- reset --";
}
};
namespace boost {
namespace serialization {
/************************************************
*
* boost::serialization::make_nvp(...) wrapper
*
************************************************/
template<class T>
inline
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
const
#endif
boost::serialization::nvp<T> make_nvp_wrapper (const char *
name, T & t )
{
OUSTprotoDebug("### invoked for <%s>", name);
std::string strName ( name );
MakeNVPPathConcat makeNVPPathConcat( strName );
boost::serialization::nvp<T> ret =
boost::serialization::make_nvp<T>( name, t );
OUSTprotoDebug("### done for <%s>", name);
return ret;
}
} // namespace serialization
} // namespace boost
The result is:
opsc_hlr :2204 084723:D:### invoked for <pModifyHlrSubscriberIn>
opsc_hlr :2204 084723:D:### c'tor
opsc_hlr :2204 084723:D:### done for <pModifyHlrSubscriberIn>
opsc_hlr :2204 084723:D:### d'tor
opsc_hlr :2204 084723:D:### invoked for <imsi>
opsc_hlr :2204 084723:D:### c'tor
opsc_hlr :2204 084723:D:### done for <imsi>
opsc_hlr :2204 084723:D:### d'tor
opsc_hlr :2204 084723:D:### invoked for <value>
opsc_hlr :2204 084723:D:### c'tor
opsc_hlr :2204 084723:D:### done for <value>
opsc_hlr :2204 084723:D:### d'tor
So there is no recursion(???).
Is there another way to get a "where am i" information within a
serialize (load/save) helper?
- thanks!
Regards!
Frank
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