Reading data from cpf file for std::vector<std::string> doesn't work

Hi everyone,

I am trying to read properties from cpf file, Simple data types like int work just fine but for std::vector<std::string> I get runtime error. Here is what I do:

PropertyBag from_file; std::string filename="config_file.cpf"; marsh::PropertyDemarshaller demarshaller(filename); demarshaller.deserialize(from_file); /// Read the properties from PropertyBag /// a_number Property< int > a_number_p; a_number_p = from_file.getProperty("aNumber"); a_number = a_number_p.get(); /// a_vector Property<std::vector<std::string> > a_vector_p; a_vector_p = from_file.getProperty("aVector"); a_vector = a_vector_p.get(); // this line produces the error

Error: deployer-gnulinux: /usr/include/boost/smart_ptr/intrusive_ptr.hpp:166: T* boost::intrusive_ptr<T>::operator->() const [with T = RTT::internal::AssignableDataSource<std::vector<std::basic_string<char> > >]: Assertion `px != 0' failed. Aborted (core dumped)

Any help and hint is much appreciated,

Bests, Mohamad

Reading data from cpf file for std::vector<std::string> doesn't

Hi everyone,

I have written some properties to cpf file , using the marshaller.
But when I try to read them back from file, I get runtime error. Simple
data types like int work just fine but for std::vector<std::string> I have
problem.

Here is what I do:

PropertyBag from_file;
std::string filename="config_file.cpf";
marsh::PropertyDemarshaller demarshaller(filename);
demarshaller.deserialize(from_file);
/// Read the properties from PropertyBag
/// a_number
Property< int > a_number_p;
a_number_p = from_file.getProperty("aNumber");
a_number = a_number_p.get(); // this works
/// a_vector
Property<std::vector a_vector_p = from_file.getProperty("aVector");
a_vector = a_vector_p.get(); // this line produces the error

Error: deployer-gnulinux:
/usr/include/boost/smart_ptr/intrusive_ptr.hpp:166: T*
boost::intrusive_ptr<T>::operator->() const [with T =
RTT::internal::AssignableDataSource<std::vector >]: Assertion `px != 0' failed. Aborted (core dumped)

Any help and hint is much appreciated,

Bests, Mohamad

Re: Reading data from cpf file for std::vector<std::string>

How have you formatted that property in your .cpf file?

For std::vector<std::string> you should use:

<struct name="aVector" type="strings">            <!-- NOTICE: strings -->
   <description>Vector of strings</description>
      <simple name="Element0" type="string">
         <description>First element of vector</description>
         <value>first_string_content</value>
      </simple>
      <simple name="Element1" type="string">
         <description>Second element of vector</description>
         <value>second_string_content</value>
      </simple>
      <!-- ... -->
</struct>

Federico

Re: Reading data from cpf file for std::vector<std::string>

Hi Federico,

I have generated the cpf file with the marshaller, so the format should be correct. In case of std::vector<std::string>, the format is the same as you stated.

Bests, Mohamad

code with correct format

Sorry for the formatting, This is the code:

PropertyBag from_file;
std::string filename="config_file.cpf";
marsh::PropertyDemarshaller demarshaller(filename);
demarshaller.deserialize(from_file);
/// Read the properties from PropertyBag
/// a_number Property< int > a_number_p;
a_number_p = from_file.getProperty("aNumber");
a_number = a_number_p.get();
/// a_vector
Property<std::vector<std::string> > a_vector_p;
a_vector_p = from_file.getProperty("aVector");
a_vector = a_vector_p.get(); // this line produces the error