[xsde-users] Re: Bug?

Laurent Michel laurent1984 at gmail.com
Wed Feb 22 12:00:12 EST 2017


Hi Boris,

Basically, I have this class

  class IntrantList
  {
    private:
    IntrantList (const IntrantList&);
    IntrantList& operator= (const IntrantList&);

    public:
    IntrantList ();

    ~IntrantList ();

    // Intrant
    //
    typedef ::xsde::cxx::hybrid::var_sequence< ::N_Data::Intrant >
Intrant_sequence;
    typedef Intrant_sequence::iterator Intrant_iterator;
    typedef Intrant_sequence::const_iterator Intrant_const_iterator;

    const Intrant_sequence&
    Intrant () const;

    Intrant_sequence&
    Intrant ();

    private:
    Intrant_sequence Intrant_;
  };

which contains a sequence of intrants defined like this (it has, in
reality, more data than that):

  class Intrant
  {
    private:
    Intrant (const Intrant&);
    Intrant& operator= (const Intrant&);

    public:
    Intrant ();

    ~Intrant ();

    // title
    //
    const ::std::string&
    title () const;

    ::std::string&
    title ();

    void
    title (const ::std::string&);

    // actions
    //
    bool
    actions_present () const;

    const ::N_Data::ActionList&
    actions () const;

    ::N_Data::ActionList&
    actions ();

    void
    actions (::N_Data::ActionList*);

    private:
    ::std::string title_;
    ::N_Data::ActionList* actions_;
  };

Then, what I want to do is something like this:

  void MyClass::addIntrant(const Intrant& a_Intrant)
  {
    m_Data->Intrant().push_back(a_Intrant);
  }

where

std::unique_ptr<N_Data::IntrantList> m_Data;

This is what my application used to do when I linked it with XSD. Now I am
working with XSD/e, I can't do that any more, because I have no copy
constructor for the Intrant class. The idea is that I then do something
like what is described in the documentation

http://www.codesynthesis.com/projects/xsde/documentation/cxx/hybrid/guide/#2.5

to output my XML file with all the data I want in it.

The big "problem" I have is that I first wrote my application with XSD. One
of the features of the application is that it can fill an XML file with
Intrants based on user input. I start with an empty list and just fill it
with whatever it is the user wants. The data filled by the user are stored
in an object of type Intrant, which has now no copy constructor. I want
this object to be appended to my list of Intrants. XSD/e users surely do
that kind of things, don't they?

What is the best practice with XSD/e?

BUT, maybe I am fine with just pointers or references, because I saw that
you define your sequences like this:

template <typename T>
      class var_sequence: public sequence_base
      {

     [...]

#ifndef XSDE_EXCEPTIONS
        error
#else
        void
#endif
        push_back (T*);
    }

which means you don't store the sequence elements by value but by
reference. So, as far as I understand, as long as my objects exist
somewhere in the heap, I can add them to the sequence without using any
copy constructor. Am I right? That seems to be the whole big difference
with XSD. This would also mean that I don't have much to do to make this
work again.

Cheers,
Laurent



On Wed, Feb 22, 2017 at 5:28 PM, Boris Kolpackov <boris at codesynthesis.com>
wrote:

> Hi Laurent,
>
> Laurent Michel <laurent1984 at gmail.com> writes:
>
> > Btw, if you disable copy constructors, how do you serialize data then?
> > Because it can be that I have an xsd element made of a sequence of e.g.
> > strings that I would like to serialize. Since this has variable length, I
> > have no copy ctor for my element.
>
> I don't understand why you need a copy to serialize things? It's not like
> serialization is somehow destructive? You just pass (const) references.
>
>
> > Is xsd/e compatible with move constructors?
>
> No, XSD/e doesn't generate move constructors yet.
>
> Boris
>


More information about the xsde-users mailing list