[xsd-users] Visitors (again?)

Oliver Schneider xsd-users at oli-obk.de
Tue Sep 9 02:58:09 EDT 2014


Hi Tim,

You can easily add a visit function to all your custom classes.
look at
http://wiki.codesynthesis.com/Tree/Customization_guide#Customizing_the_generated_type_.E2.80.94_the_complex_case

Then add a void accept(Visitor& v) { v.visit(*this); } function.

If you have c++11 you can even easily templatize this (can be done w/o
c++11, but the inclusion of the template would be a mess)
I created a Visitable template:

template<template <class> class T, class base>
    class Visitable : public base
    {
    public:
        using base::base;
        typedef T<base> Derived;
        typedef Visitable<T, base> VisitableBase;
        void accept(Visitor& visitor) { visitor.visit(*this); }
        virtual base*
            _clone(xml_schema::flags flags = 0,
            xml_schema::container* container = 0) const override
        {
            return new Derived(static_cast<const Derived&>(*this),
flags, container);
        }
        virtual ~Visitable() = default;
    };

I use this by instanciating the custom class this way:

template<typename base>
class Custom_impl : public Visitable<Custom_impl, base>
{
public:
    using base::base;
};

Simple enough, and easily extendable

greetings

/oliver

Am 04.09.2014 17:11, schrieb Timothy Astle:
> I've checked the list archives aboutthis andseen a few related
> threads, but I'd like to get a summary / update.  It seems like I'mnot
> the first one interested in this topic.  Also keep in mind that I'm
> new to this library, so please be kind.  :)
>
> Is there any means to generate sourcethat allows for visitors? 
> Similar to what we're adding to
> <https://java.net/jira/browse/OGC-55>the OGC Sche
> <https://java.net/jira/browse/OGC-55>mas in JAXB
> <https://java.net/jira/browse/OGC-55>.
>
> There are situations where we'd like to take OGC Filters andtraverse
> them to produce queries.
>
> If someone can point me in the right direction, it'd be much appreciated.
>
> Cheers,
>
> Tim
>



More information about the xsd-users mailing list