Main Page Namespace List Class Hierarchy Compound List File List Namespace Members Compound Members Related Pages

# memberdef.h

Go to the documentation of this file.

    00001 /* -*- c++ -*- */
    00002 #ifndef AKAXISO2_FRAMEWORK_MEMBERDEF_H__
    00003 #define AKAXISO2_FRAMEWORK_MEMBERDEF_H__
    00004
    00010 #include <akaxiso2/framework/fixed.h>
    00011 #include <akaxiso2/framework/ptrmember.h>
    00012 #include <akaxiso2/framework/any.h>
    00013 #include <akaxiso2/framework/accessor.h>
    00014
    00015 namespace aka2 {
    00016
    00026   template<class L, class T>
    00027   struct memberdef : xmltype_statics<L> {
    00028
    00029     static member_type *define_member(const std::string tagname,
    00030                                       member_getter *mgetter,
    00031                                       element_op &op,
    00032                                       default_op *defop,
    00033                                       const occurrence &occ,
    00034                                       bool emptiable) {
    00035       aka2::member_type mtype(mgetter, op, emptiable);
    00036       mtype.set_name(qname(tagname));
    00037       if (defop != 0)
    00038         mtype.set_default_op(defop);
    00039       if (!check_occurrence(op.get_schematype(), occ))
    00040         throw tagged_error("element", tagname, "has wrong occurrence.", __FILE__, __LINE__);
    00041       mtype.set_occurrence(occ);
    00042       return L::register_membertype(mtype);
    00043     }
    00044
    00051     struct _member {
    00057       template<class P, class V>
    00058       _member(const std::string &tagname, V P::* m) {
    00059         new_member(tagname, m, xiso::leaf<V>(), 1, 1, false);
    00060       }
    00068       template<class P, class V>
    00069       _member(const std::string &tagname, V P::* m, int minOccurs, int maxOccurs) {
    00070         new_member(tagname, m, xiso::leaf<V>(), minOccurs, maxOccurs, false);
    00071       }
    00072
    00079       template<class P, class V, class VL>
    00080       _member(const std::string &tagname, V P::* m, const VL& vl) {
    00081         new_member(tagname, m, VL(), 1, 1, false);
    00082       }
    00092       template<class P, class V, class VL>
    00093       _member(const std::string &tagname, V P::* m, const VL& vl, int minOccurs, int maxOccurs,
    00094               bool emptiable = false) {
    00095         new_member(tagname, m, VL(), minOccurs, maxOccurs, emptiable);
    00096       }
    00097
    00102       void set_default(const std::string &defval) {
    00103         if (mtype_->get_schematype() != simpletype_id)
    00104           throw tagged_error("element", mtype_->get_name().qualified(),
    00105                              "default value should be simpleType.",
    00106                              __FILE__, __LINE__);
    00107         mtype_->setup_default_value(defval);
    00108       };
    00109
    00110     private:
    00111       template<class P, class V, class VL>
    00112       void new_member(const std::string &tagname, V P::* m, const VL&,
    00113                       int minOccurs, int maxOccurs,
    00114                       bool emptiable) {
    00115         VL::initialize();
    00116         member_getter *mgetter =
    00117           create_ptr_getter(reinterpret_cast<T*>(0), m);
    00118         mtype_ = define_member(tagname,
    00119                                mgetter,
    00120                                VL::dispatcher_,
    00121                                VL::create_default_op(),
    00122                                aka2::occurrence(minOccurs, maxOccurs),
    00123                                emptiable);
    00124       }
    00125       member_type *mtype_;
    00126     };
    00127
    00134     typedef _member member;
    00135
    00143     struct _ptrmember {
    00149       template<class P, class V>
    00150       _ptrmember(const std::string &tagname, V P::* m) {
    00151         new_ptr_member(tagname, m, xiso::leaf<TYPENAME V::value_type>(), false);
    00152       }
    00153
    00160       template<class P, class V, class VL>
    00161       _ptrmember(const std::string &tagname, V P::* m, const VL& vl) {
    00162         new_ptr_member(tagname, m, VL(), false);
    00163       }
    00164     private:
    00165       template<class P, class V, class VL>
    00166       void new_ptr_member(const std::string &tagname, V P::* m, const VL&,
    00167                           bool emptiable) {
    00168         VL::initialize();
    00169         member_getter *mgetter =
    00170           create_ptr_getter(reinterpret_cast<T*>(0), m);
    00171         define_member(tagname, mgetter,
    00172                       aka2::ptrmember_op_stub<V, VL>::dispatcher_,
    00173                       VL::create_default_op(),
    00174                       occurrence(0, 1), emptiable);
    00175       }
    00176     };
    00177
    00183     typedef _ptrmember ptrmember;
    00184
    00192     template<class V>
    00193     struct fixed_member { // Default value for complexType or mixed content will not be supported.
    00194       fixed_member(const std::string &tagname, const std::string &fixed_value) {
    00195         new_member(tagname, xiso::leaf<V>(), fixed_value);
    00196       }
    00197       template<class VL>
    00198       fixed_member(const std::string &tagname, const std::string &fixed_value, const VL &) {
    00199         new_member(tagname, VL(), fixed_value);
    00200       }
    00201     private:
    00202       template<class VL>
    00203       void new_member(const std::string &tagname, const VL&, const std::string &fixed_value) {
    00204         VL::initialize();
    00205         if (VL::dispatcher_.get_schematype() != simpletype_id)
    00206           throw tagged_error("fixed", L::get_xmltype(), " fixed value should be simpleType.",
    00207                              __FILE__, __LINE__);
    00208         member_type *mtype = define_member(tagname, new null_getter(),
    00209                                            aka2::fixed<VL>::dispatcher_,
    00210                                            VL::create_default_op(),
    00211                                            aka2::occurrence(), false);
    00212         mtype->setup_default_value(fixed_value);
    00213       }
    00214     };
    00215
    00223     struct _fixed_array {
    00232       template<class P, class V>
    00233       _fixed_array(const std::string &tagname, const std::string &fixed_value, V P::*m,
    00234                    int minOccurs, int maxOccurs) {
    00235         new_member(tagname, m, xiso::leaf<V>(),
    00236                    minOccurs, maxOccurs, fixed_value);
    00237       }
    00238
    00249       template<class P, class V, class VL>
    00250       _fixed_array(const std::string &tagname, const std::string &fixed_value, V P::*m,
    00251                    const VL& vl,
    00252                    int minOccurs, int maxOccurs,
    00253                    bool emptiable = false) {
    00254         new_member(tagname, m, VL(), minOccurs, maxOccurs, fixed_value, emptiable);
    00255       }
    00256     private:
    00257       template<class P, class V, class VL>
    00258       void new_member(const std::string &tagname, V P::* m, const VL&,
    00259                       int minOccurs, int maxOccurs,
    00260                       const std::string &fixed_value,
    00261                       bool emptiable) {
    00262         VL::initialize();
    00263         typedef TYPENAME VL::item_leaf_type item_leaf_type;
    00264
    00265         if (VL::dispatcher_.get_schematype() != array_id)
    00266           throw tagged_error("element", tagname, "should be array.", __FILE__, __LINE__);
    00267         if (VL::dispatcher_.get_item_op().get_schematype() != fixed_id)
    00268           throw tagged_error("element", tagname, "should be fixed.", __FILE__, __LINE__);
    00269         const fixed_op &fop = static_cast<const fixed_op&>(VL::dispatcher_.get_item_op());
    00270         if (fop.get_value_op().get_schematype() != simpletype_id)
    00271           throw tagged_error("element", tagname, "fixed value should not a simpleType.",
    00272                              __FILE__, __LINE__);
    00273
    00274         member_getter *mgetter = create_ptr_getter(static_cast<const T*>(0), m);
    00275         member_type *mtype = define_member(tagname, mgetter,
    00276                                            VL::dispatcher_,
    00277                                            item_leaf_type::create_default_op(),
    00278                                            aka2::occurrence(minOccurs, maxOccurs),
    00279                                            emptiable);
    00280         mtype->setup_default_value(fixed_value);
    00281       }
    00282     };
    00283
    00290     typedef _fixed_array fixed_array;
    00291
    00303     template<class P>
    00304     void any_ptrmember(const std::string &tagname, aka2::deep_ptr<aka2::any> P::* m,
    00305                        const std::string &ns_list = "##any") {
    00306       typedef aka2::ptrmember_op_stub<aka2::deep_ptr<aka2::any>, aka2::any_op>
    00307         op_type;
    00308       member_getter *mgetter =
    00309         create_ptr_getter(reinterpret_cast<T*>(0), m);
    00310       aka2::member_type
    00311         mtype(mgetter, op_type::dispatcher_, false);
    00312       mtype.set_name(qname(tagname));
    00313       mtype.set_occurrence(aka2::occurrence(0, 1));
    00314       mtype.set_ns_list(ns_list);
    00315       L::register_membertype(mtype);
    00316     }
    00317
    00326     template<class P>
    00327     void any(const std::string &tagname, aka2::any P::* m,
    00328              const std::string &ns_list = "##any") {
    00329       member_getter *mgetter =
    00330         create_ptr_getter(reinterpret_cast<T*>(0), m);
    00331       aka2::member_type mtype(mgetter, any_op::dispatcher_, false);
    00332       mtype.set_name(aka2::qname(tagname));
    00333       mtype.set_ns_list(ns_list);
    00334       L::register_membertype(mtype);
    00335     }
    00336
    00347     template<class P>
    00348     void any(const std::string &tagname, aka2::any_array P::* m,
    00349              int minOccurs, int maxOccurs, const std::string &ns_list = "##any") {
    00350       any(tagname, m, minOccurs, maxOccurs, false, ns_list);
    00351     }
    00352
    00364     template<class P>
    00365     void any(const std::string &tagname, aka2::any_array P::* m,
    00366              int minOccurs, int maxOccurs, bool emptiable,
    00367              const std::string &ns_list) {
    00368       member_getter *mgetter =
    00369         create_ptr_getter(reinterpret_cast<T*>(0), m);
    00370       aka2::member_type mtype(mgetter, any_array_op::dispatcher_, emptiable);
    00371       mtype.set_name(aka2::qname(tagname));
    00372       mtype.set_occurrence(aka2::occurrence(minOccurs, maxOccurs));
    00373       mtype.set_ns_list(ns_list);
    00374       L::register_membertype(mtype);
    00375     }
    00376
    00404     struct _accessor {
    00413       template<class G, class S, class VL>
    00414       _accessor(const std::string &tagname, const G &g, const S &s, const VL &vl) {
    00415         new_member(tagname, g, s, VL(), 1, 1, false);
    00416       }
    00417
    00429       template<class G, class S, class VL>
    00430       _accessor(const std::string &tagname, const G &g, const S &s, const VL &vl,
    00431                 int minOccurs, int maxOccurs,
    00432                 bool emptiable = false) {
    00433         new_member(tagname, g, s, VL(), minOccurs, maxOccurs, false);
    00434       }
    00435     private:
    00436       template<class G, class S, class VL>
    00437       void new_member(const std::string &tagname,
    00438                       const G &g, const S &s, const VL&,
    00439                       int minOccurs, int maxOccurs, bool emptiable) {
    00440         VL::initialize();
    00441
    00442         member_getter *mgetter =
    00443           create_accessor_getter(reinterpret_cast<T*>(0),
    00444                                  VL::dispatcher_,
    00445                                  g, s);
    00446         define_member(tagname,
    00447                       mgetter,
    00448                       VL::dispatcher_,
    00449                       VL::create_default_op(),
    00450                       aka2::occurrence(minOccurs, maxOccurs),
    00451                       emptiable);
    00452       }
    00453     };
    00454
    00461     typedef _accessor accessor;
    00462   };
    00463 }
    00464
    00465 #endif