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       }
00069       template<class P, class V> 
00070       _member(const std::string &tagname, V P::* m, int minOccurs, int maxOccurs, 
00071               bool emptiable = false) {
00072         new_member(tagname, m, xiso::leaf<V>(), minOccurs, maxOccurs, emptiable);
00073       }
00074 
00081       template<class P, class V, class VL> 
00082       _member(const std::string &tagname, V P::* m, const VL& vl) {
00083         new_member(tagname, m, VL(), 1, 1, false);
00084       }
00094       template<class P, class V, class VL> 
00095       _member(const std::string &tagname, V P::* m, const VL& vl, int minOccurs, int maxOccurs,
00096               bool emptiable = false) {
00097         new_member(tagname, m, VL(), minOccurs, maxOccurs, emptiable);
00098       }
00099 
00104       void set_default(const std::string &defval) {
00105         if (mtype_->get_schematype() != simpletype_id)
00106           throw tagged_error("element", mtype_->get_name().qualified(), 
00107                              "default value should be simpleType.",
00108                              __FILE__, __LINE__);
00109         mtype_->setup_default_value(defval);
00110       };
00111 
00112     private:
00113       template<class P, class V, class VL> 
00114       void new_member(const std::string &tagname, V P::* m, const VL&, 
00115                       int minOccurs, int maxOccurs,
00116                       bool emptiable) {
00117         VL::initialize();
00118         member_getter *mgetter = 
00119           create_ptr_getter(reinterpret_cast<T*>(0), m);          
00120         mtype_ = define_member(tagname, 
00121                                mgetter, 
00122                                VL::dispatcher_, 
00123                                VL::create_default_op(),
00124                                aka2::occurrence(minOccurs, maxOccurs),
00125                                emptiable);
00126       }
00127       member_type *mtype_;
00128     };
00129 
00136     typedef _member member;
00137 
00145     struct _ptrmember {
00151       template<class P, class V> 
00152       _ptrmember(const std::string &tagname, V P::* m) {
00153         new_ptr_member(tagname, m, xiso::leaf<TYPENAME V::value_type>(), false);
00154       }
00155 
00162       template<class P, class V, class VL>
00163       _ptrmember(const std::string &tagname, V P::* m, const VL& vl) {
00164         new_ptr_member(tagname, m, VL(), false);
00165       }
00166     private:
00167       template<class P, class V, class VL> 
00168       void new_ptr_member(const std::string &tagname, V P::* m, const VL&, 
00169                           bool emptiable) {
00170         VL::initialize();
00171         member_getter *mgetter = 
00172           create_ptr_getter(reinterpret_cast<T*>(0), m);          
00173         define_member(tagname, mgetter, 
00174                       aka2::ptrmember_op_stub<V, VL>::dispatcher_,
00175                       VL::create_default_op(),
00176                       occurrence(0, 1), emptiable);
00177       }
00178     };
00179 
00185     typedef _ptrmember ptrmember;
00186 
00194     template<class V>
00195     struct fixed_member { // Default value for complexType or mixed content will not be supported.
00196       fixed_member(const std::string &tagname, const std::string &fixed_value) {
00197         new_member(tagname, xiso::leaf<V>(), fixed_value);
00198       }
00199       template<class VL>
00200       fixed_member(const std::string &tagname, const std::string &fixed_value, const VL &) {
00201         new_member(tagname, VL(), fixed_value);
00202       }
00203     private:
00204       template<class VL>
00205       void new_member(const std::string &tagname, const VL&, const std::string &fixed_value) {
00206         VL::initialize();
00207         if (VL::dispatcher_.get_schematype() != simpletype_id)
00208           throw tagged_error("fixed", L::get_xmltype(), " fixed value should be simpleType.",
00209                              __FILE__, __LINE__);
00210         member_type *mtype = define_member(tagname, new null_getter(),
00211                                            aka2::fixed<VL>::dispatcher_,
00212                                            VL::create_default_op(),
00213                                            aka2::occurrence(), false);
00214         mtype->setup_default_value(fixed_value);
00215       }
00216     };
00217     
00225     struct _fixed_array { 
00234       template<class P, class V>
00235       _fixed_array(const std::string &tagname, const std::string &fixed_value, V P::*m, 
00236                    int minOccurs, int maxOccurs) {
00237         new_member(tagname, m, xiso::leaf<V>(),
00238                    minOccurs, maxOccurs, fixed_value);
00239       }
00240 
00251       template<class P, class V, class VL>
00252       _fixed_array(const std::string &tagname, const std::string &fixed_value, V P::*m, 
00253                    const VL& vl,
00254                    int minOccurs, int maxOccurs,
00255                    bool emptiable = false) {
00256         new_member(tagname, m, VL(), minOccurs, maxOccurs, fixed_value, emptiable);
00257       }
00258     private:
00259       template<class P, class V, class VL>
00260       void new_member(const std::string &tagname, V P::* m, const VL&, 
00261                       int minOccurs, int maxOccurs,
00262                       const std::string &fixed_value,
00263                       bool emptiable) {
00264         VL::initialize();
00265         typedef TYPENAME VL::item_leaf_type item_leaf_type;
00266 
00267         if (VL::dispatcher_.get_schematype() != array_id)
00268           throw tagged_error("element", tagname, "should be array.", __FILE__, __LINE__);
00269         if (VL::dispatcher_.get_item_op().get_schematype() != fixed_id)
00270           throw tagged_error("element", tagname, "should be fixed.", __FILE__, __LINE__);
00271         const fixed_op &fop = static_cast<const fixed_op&>(VL::dispatcher_.get_item_op());
00272         if (fop.get_value_op().get_schematype() != simpletype_id)
00273           throw tagged_error("element", tagname, "fixed value should not a simpleType.",
00274                              __FILE__, __LINE__);
00275         
00276         member_getter *mgetter = create_ptr_getter(static_cast<const T*>(0), m);
00277         member_type *mtype = define_member(tagname, mgetter,
00278                                            VL::dispatcher_,
00279                                            item_leaf_type::create_default_op(),
00280                                            aka2::occurrence(minOccurs, maxOccurs),
00281                                            emptiable);
00282         mtype->setup_default_value(fixed_value);
00283       }
00284     };
00285 
00292     typedef _fixed_array fixed_array;
00293 
00305     template<class P>
00306     void any_ptrmember(const std::string &tagname, aka2::deep_ptr<aka2::any> P::* m,
00307                        const std::string &ns_list = "##any") {
00308       typedef aka2::ptrmember_op_stub<aka2::deep_ptr<aka2::any>, aka2::any_op>
00309         op_type;
00310       member_getter *mgetter = 
00311         create_ptr_getter(reinterpret_cast<T*>(0), m);    
00312       aka2::member_type 
00313         mtype(mgetter, op_type::dispatcher_, false);
00314       mtype.set_name(qname(tagname));
00315       mtype.set_occurrence(aka2::occurrence(0, 1));
00316       mtype.set_ns_list(ns_list);
00317       L::register_membertype(mtype);
00318     }
00319 
00328     template<class P>
00329     void any(const std::string &tagname, aka2::any P::* m, 
00330              const std::string &ns_list = "##any") {
00331       member_getter *mgetter = 
00332         create_ptr_getter(reinterpret_cast<T*>(0), m);    
00333       aka2::member_type mtype(mgetter, any_op::dispatcher_, false);
00334       mtype.set_name(aka2::qname(tagname));
00335       mtype.set_ns_list(ns_list);
00336       L::register_membertype(mtype);
00337     }
00338 
00349     template<class P>
00350     void any(const std::string &tagname, aka2::any_array P::* m, 
00351              int minOccurs, int maxOccurs, const std::string &ns_list = "##any") {
00352       any(tagname, m, minOccurs, maxOccurs, false, ns_list);
00353     }
00354 
00366     template<class P>
00367     void any(const std::string &tagname, aka2::any_array P::* m, 
00368              int minOccurs, int maxOccurs, bool emptiable,
00369              const std::string &ns_list) {
00370       member_getter *mgetter = 
00371         create_ptr_getter(reinterpret_cast<T*>(0), m);    
00372       aka2::member_type mtype(mgetter, any_array_op::dispatcher_, emptiable);
00373       mtype.set_name(aka2::qname(tagname));
00374       mtype.set_occurrence(aka2::occurrence(minOccurs, maxOccurs));
00375       mtype.set_ns_list(ns_list);
00376       L::register_membertype(mtype);
00377     }
00378 
00406     struct _accessor {
00415       template<class G, class S, class VL>
00416       _accessor(const std::string &tagname, const G &g, const S &s, const VL &vl) {
00417         new_member(tagname, g, s, VL(), 1, 1, false);
00418       }
00419 
00431       template<class G, class S, class VL>
00432       _accessor(const std::string &tagname, const G &g, const S &s, const VL &vl,
00433                 int minOccurs, int maxOccurs,
00434                 bool emptiable = false) {
00435         new_member(tagname, g, s, VL(), minOccurs, maxOccurs, false);
00436       }
00437     private:
00438       template<class G, class S, class VL> 
00439       void new_member(const std::string &tagname, 
00440                       const G &g, const S &s, const VL&,
00441                       int minOccurs, int maxOccurs, bool emptiable) {
00442         VL::initialize();
00443 
00444         member_getter *mgetter = 
00445           create_accessor_getter(reinterpret_cast<T*>(0), 
00446                                  VL::dispatcher_,
00447                                  g, s);   
00448         define_member(tagname, 
00449                       mgetter,
00450                       VL::dispatcher_,
00451                       VL::create_default_op(),
00452                       aka2::occurrence(minOccurs, maxOccurs),
00453                       emptiable);
00454       }
00455     };
00456 
00463     typedef _accessor accessor;
00464   };
00465 }
00466 
00467 #endif

Generated on Sat Dec 18 22:43:28 2004 for akaxiso2 by doxygen1.2.18