[xsde-users] XSD/e 3.0.0 released

Della Betta Filippo filippo.dellabetta at telecomitalia.it
Mon Feb 9 08:16:34 EST 2009


Thanks!
I did the same for the serializer (providing a new implementation for listType_simpl and list_simpl with --custom-serializer, putting a std::stack of state and implementing post() callback to do pop() on the stack).
Attached the custom implementation files.
Do you think it is the correct way to do this ?

Filippo

P.S. driver program following

#include <iostream>
#include <fstream>
#include <string>

#include "resource-lists_rfc4826.h"
#include "resource-lists_rfc4826-pimpl.h"
#include "resource-lists_rfc4826-simpl.h"


using namespace std;
using namespace urn_ietf_params_xml_ns_resource_lists;

int
main (int argc, char* argv[])
{
  try
  {
        resource_lists_paggr resource_lists_p;
        ::xml_schema::document_pimpl doc_p (
                                resource_lists_p.root_parser(),
                                resource_lists_p.root_namespace(),
                                resource_lists_p.root_name() );

        resource_lists_p.pre ();
        ifstream i("rl.xml");
    doc_p.parse (i);
    resource_lists* rl = resource_lists_p.post ();


        for ( resource_lists::sequence_iterator si = rl->sequence().begin(); si != rl->sequence().end(); si++){
                for ( listType::sequence_iterator li = si->list().sequence().begin();  li != si->list().sequence().end(); li++){
                        switch (li->choice_arm()){
                                case listType::sequence_type::list_tag:
                                        {
                                                cout << "list name = " << li->list().name() << endl;
                                                for ( listType::sequence_iterator li2 = li->list().sequence().begin();  li2 != li->list().sequence().end(); li2++){
                                                                switch (li->choice_arm()){
                                                                        case listType::sequence_type::list_tag:
                                                                                cout << "list name = " << li2->list().name() << endl;
                                                                                break;
                                                                        case listType::sequence_type::entry_tag:
                                                                                cout << "entry uri = " << li2->entry().uri() << endl;
                                                                                break;
                                                                        default:
                                                                                break;
                                                                }
                                                }
                                        }
                                        break;
                                default:
                                        break;
                        }

                }


        }

        resource_lists_saggr resource_lists_s;
        ::xml_schema::document_simpl doc_s (
                                resource_lists_s.root_serializer(),
                                resource_lists_s.root_namespace(),
                                resource_lists_s.root_name() );

        resource_lists_s.pre(*rl);
        ofstream o("rlgen.xml");
        doc_s.add_prefix("","urn:ietf:params:xml:ns:resource-lists");
        doc_s.serialize(o);
        resource_lists_s.post();


        delete rl;

  }
  catch (const xml_schema::parser_exception& e)
  {
    cerr << e.line () << ":" << e.column ()
         << ": " << e.text () << endl;
    return 1;
  }
  catch (const xml_schema::serializer_exception& e)
  {
    cerr << "error: " << e.text () << endl;
    return 1;
  }
}




-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com]
Sent: venerdì 6 febbraio 2009 16.07
To: Della Betta Filippo
Cc: xsde-users at codesynthesis.com
Subject: Re: [xsde-users] XSD/e 3.0.0 released

Hi Filippo,

Della Betta Filippo <filippo.dellabetta at telecomitalia.it> writes:

> first of all thank you for your excellent work. I like the hybrid
> mapping very much.

Thank you. I am glad you like it.


> I wrote the following program to test hybrid / aggregate functionality.
> While printing the name for "2nd level" list (see rl.xml), I got access
> violation (windows, visual studio 2008).

I checked your schema and XML and it appears that it has a recursive
element (list). One of the current limitations of the generated parsing
code in the C++/Hybrid mapping is that it does not yet support recursive
parsing. This will be supported in the next release, though.

One work around would be to provide custom parser implementations for
the types involved in the recursion. In your schema they are list (the
anonymous type for the list element inside listType) and listType. I've
created a sample implementation for you which you can download via this
URI:

http://www.codesynthesis.com/~boris/tmp/resource-list-rfc4826.zip

Here is what I did:

I copied the generated parser implementations for list and listType
to list-pimpl.h/cpp and listType-pimpl.h/cpp. I then changed them
to maintain a stack of states instead of just one state. I used
STL stack for simplicity, though you can use the POD stack class
found in libxsde/xsde/cxx/parser/state.hxx if STL is not available
(this is what we are going to use in the implementation for the
next release; that stack is also optimized for the non-recursive
case).

Then I used the --custom-parser option to instruct the XSD/e compiler
to use my custom implementations instead of the generated ones (see
the cmd.txt file in the archive for the updated XSD/e command line).
After that your test driver works as expected.

For more information on parser customization see Section 6.1,
"Customizing Parsers and Serializers" in the Embedded C++/Hybrid
Mapping Getting Started Guide.

Boris

Questo messaggio e i suoi allegati sono indirizzati esclusivamente alle persone indicate. La diffusione, copia o qualsiasi altra azione derivante dalla conoscenza di queste informazioni sono rigorosamente vietate. Qualora abbiate ricevuto questo documento per errore siete cortesemente pregati di darne immediata comunicazione al mittente e di provvedere alla sua distruzione, Grazie.

This e-mail and any attachments is confidential and may contain privileged information intended for the addressee(s) only. Dissemination, copying, printing or use by anybody else is unauthorised. If you are not the intended recipient, please delete this message and any attachments and advise the sender by return e-mail, Thanks.

-------------- next part --------------
#include "resource-lists_rfc4826-simpl.h"

namespace urn_ietf_params_xml_ns_resource_lists
{
  list_simpl::
  list_simpl ()
  : list_sskel (&base_impl_)
  {
  }

  void list_simpl::
  pre (const ::urn_ietf_params_xml_ns_resource_lists::list& x)
  {
	this->base_impl_.pre (x);
    this->list_simpl_state_.push( list_simpl_state() );
	this->list_simpl_state_.top ().list_ = &x;
  }

  void list_simpl::
  post ()
  {
	  this->list_simpl_state_.pop();
  }

}
-------------- next part --------------
#include <stack>

namespace urn_ietf_params_xml_ns_resource_lists
{
  class list_simpl: public list_sskel
  {
    public:
    list_simpl ();

    virtual void
    pre (const ::urn_ietf_params_xml_ns_resource_lists::list&);

	virtual void
	post ();

    protected:
    struct list_simpl_state
    {
      const ::urn_ietf_params_xml_ns_resource_lists::list* list_;
    };

	std::stack < list_simpl_state > list_simpl_state_;

    protected:
    ::urn_ietf_params_xml_ns_resource_lists::listType_simpl base_impl_;
  };
}
-------------- next part --------------
#include "resource-lists_rfc4826-simpl.h"

namespace urn_ietf_params_xml_ns_resource_lists
{
  void listType_simpl::
  pre (const ::urn_ietf_params_xml_ns_resource_lists::listType& x)
  {
	this->listType_simpl_state_.push( listType_simpl_state() );
    this->listType_simpl_state_.top ().listType_ = &x;
    this->listType_simpl_state_.top ().sequence_end_ = this->listType_simpl_state_.top ().listType_->sequence ().end ();
    this->listType_simpl_state_.top ().sequence_ = this->listType_simpl_state_.top ().sequence_end_;
  }

  void listType_simpl::
	post()
  {
	  this->listType_simpl_state_.pop();
  }

  bool listType_simpl::
  name_present ()
  {
    return this->listType_simpl_state_.top ().listType_->name_present ();
  }

  ::std::string listType_simpl::
  name ()
  {
    return this->listType_simpl_state_.top ().listType_->name ();
  }

  bool listType_simpl::
  display_name_present ()
  {
    return this->listType_simpl_state_.top ().listType_->display_name_present ();
  }

  const ::urn_ietf_params_xml_ns_resource_lists::display_nameType& listType_simpl::
  display_name ()
  {
    return this->listType_simpl_state_.top ().listType_->display_name ();
  }

  bool listType_simpl::
  sequence_next ()
  {
    if (this->listType_simpl_state_.top ().sequence_ != this->listType_simpl_state_.top ().sequence_end_)
      this->listType_simpl_state_.top ().sequence_++;
    else
      this->listType_simpl_state_.top ().sequence_ = this->listType_simpl_state_.top ().listType_->sequence ().begin ();

    if (this->listType_simpl_state_.top ().sequence_ != this->listType_simpl_state_.top ().sequence_end_)
    {
      return true;
    }
    else
      return false;
  }

  listType_sskel::choice_arm_tag listType_simpl::
  choice_arm ()
  {
    choice_arm_tag t (static_cast< choice_arm_tag > (
                        this->listType_simpl_state_.top ().sequence_->choice_arm ()));
    return t;
  }

  const ::urn_ietf_params_xml_ns_resource_lists::list& listType_simpl::
  list ()
  {
    return this->listType_simpl_state_.top ().sequence_->list ();
  }

  const ::urn_ietf_params_xml_ns_resource_lists::externalType& listType_simpl::
  external ()
  {
    return this->listType_simpl_state_.top ().sequence_->external ();
  }

  const ::urn_ietf_params_xml_ns_resource_lists::entryType& listType_simpl::
  entry ()
  {
    return this->listType_simpl_state_.top ().sequence_->entry ();
  }

  const ::urn_ietf_params_xml_ns_resource_lists::entry_refType& listType_simpl::
  entry_ref ()
  {
    return this->listType_simpl_state_.top ().sequence_->entry_ref ();
  }
}
-------------- next part --------------
#include <stack>

namespace urn_ietf_params_xml_ns_resource_lists
{
  class listType_simpl: public listType_sskel
  {
    public:
    virtual void
    pre (const ::urn_ietf_params_xml_ns_resource_lists::listType&);

	virtual void
	post();
    // Attributes.
    //
    virtual bool
    name_present ();

    virtual ::std::string
    name ();

    // Elements.
    //
    virtual bool
    display_name_present ();

    virtual const ::urn_ietf_params_xml_ns_resource_lists::display_nameType&
    display_name ();

    virtual bool
    sequence_next ();

    virtual choice_arm_tag
    choice_arm ();

    virtual const ::urn_ietf_params_xml_ns_resource_lists::list&
    list ();

    virtual const ::urn_ietf_params_xml_ns_resource_lists::externalType&
    external ();

    virtual const ::urn_ietf_params_xml_ns_resource_lists::entryType&
    entry ();

    virtual const ::urn_ietf_params_xml_ns_resource_lists::entry_refType&
    entry_ref ();

    protected:
    struct listType_simpl_state
    {
      const ::urn_ietf_params_xml_ns_resource_lists::listType* listType_;
      ::urn_ietf_params_xml_ns_resource_lists::listType::sequence_const_iterator sequence_;
      ::urn_ietf_params_xml_ns_resource_lists::listType::sequence_const_iterator sequence_end_;
    };

	std::stack < listType_simpl_state > listType_simpl_state_;
  };
}


More information about the xsde-users mailing list