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

simplecontent.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 #ifndef AKAXISO2_FRAMEWORK_SIMPLECONTENT_H__
00003 #define AKAXISO2_FRAMEWORK_SIMPLECONTENT_H__
00004 
00010 #include <akaxiso2/framework/operators.h>
00011 #include <akaxiso2/framework/simpletype.h>
00012 #include <akaxiso2/framework/attribute.h>
00013 #include <akaxiso2/framework/construct.h>
00014 #include <akaxiso2/framework/xmltype.h>
00015 #include <akaxiso2/builtin/builtin_xiso.h>
00016 
00017 namespace aka2 {
00018 
00019   template<class L>
00020   class simplecontent_op_dispatcher : public simplecontent_op {
00021   public:
00022     virtual schematype_id get_schematype() const { return simplecontent_id; }
00023     virtual std::string get_typename() const { return L::get_xmltype(); }
00025     virtual void construct(void *e) const {  L::construct(e); }
00026     virtual void copy_construct(void *e, const void *src) const { L::copy_construct(e, src); }
00027     virtual void destruct(void *e) const { L::destruct(e); }
00028     virtual size_t class_size() const { return L::class_size(); }
00029     virtual bool equals(const void *lhs, const void *rhs) const {
00030       return L::equals(lhs, rhs);
00031     }
00032 
00034     virtual const attribute_types *get_attribute_types() const {
00035       return &L::attribute_types_;
00036     }
00037     virtual const attribute_type *get_anyattr_type() const {
00038       return L::get_anyattr_type();
00039     }
00040     virtual const member_type& get_valuetype() const { return L::value_type_; }
00041 
00042   };
00043 
00044   template<class L>
00045   struct simplecontent_statics {
00046     static member_type value_type_;
00047     static simplecontent_op_dispatcher<L> dispatcher_;
00048     static aka2::occurrence occ_;
00049   };
00050 
00051   template<class L>
00052   member_type simplecontent_statics<L>::value_type_;
00053 
00054   template<class L>
00055   aka2::occurrence simplecontent_statics<L>::occ_;
00056 
00057   template<class L>
00058   simplecontent_op_dispatcher<L> simplecontent_statics<L>::dispatcher_;
00059 
00060 
00070   template<class T, class L=xiso::leaf<T> >
00071   class simplecontent : public attributes<L, T>, 
00072                         public simplecontent_statics<L>, 
00073                         public xmltype_statics<L> {
00074   public:
00075     typedef T value_type;
00076 
00077     virtual ~simplecontent(){}
00078 
00079     static void initialize() {
00080       if (!system_type_registry().add(L()))
00081         return;
00082       L::attribute_types_.clear();
00083       member_getter *getter = new null_getter();
00084       L::value_type_ = member_type(getter, 
00085                                    nill_leaf::dispatcher_, 
00086                                    false);
00087       L l; l.model();
00088     }
00089     static void uninitialize() {
00090       L::attribute_types_.clear();
00091     }
00092 
00093 
00094     static void construct(void *e) {
00095       new (e) T();
00096       simplecontent_construct(e, L::dispatcher_);
00097     }
00098     static void copy_construct(void *e, const void *src) {
00099       new (e) T(*static_cast<const T*>(src));
00100     }
00101     static size_t class_size() { return sizeof(T); }
00102     static void destruct(void *elm) { static_cast<T*>(elm)->~T(); }
00103 
00104 
00105     static bool equals(const void *lhs, const void *rhs) {
00106       return simplecontent_equals(lhs, rhs, L::dispatcher_);
00107     }
00108 
00109     static element_op* get_attribute_dispatcher() { return &L::dispatcher_; }
00110     static default_op* create_default_op() { return 0; }
00111 
00117     template<class V, class P, class VL>
00118     static void value(V P::* m, const VL& vl) {
00119       VL::initialize();
00120       member_getter *getter =
00121         create_ptr_getter(reinterpret_cast<T*>(0), m);
00122       L::value_type_ = member_type(getter, VL::dispatcher_, false);
00123       default_op *defop = VL::create_default_op();
00124       if (defop != 0)
00125         L::value_type_.set_default_op(defop);
00126     }
00127 
00132     template<class V, class P>
00133     static void value(V P::* m) {
00134       value(m, xiso::leaf<V>());
00135     }
00136 
00141     template<class V>
00142     struct fixed_value {
00147       fixed_value(const std::string &fixed) {
00148         new_member(fixed, xiso::leaf<V>());
00149       }
00155       template<class VL>
00156       fixed_value(const std::string &fixed, const VL &vl) {
00157         new_member(fixed, VL());
00158       }
00159     private:
00160       template<class VL>
00161       void new_member(const std::string &fixed, const VL&) {
00162         VL::initialize();
00163 
00164         if (VL::dispatcher_.get_schematype() != simpletype_id)
00165           throw tagged_error("simpleContent", L::get_xmltype(), 
00166                              "fixed value should be a simpleType.",
00167                              __FILE__, __LINE__);
00168 
00169         L::value_type_ = aka2::member_type(new null_getter(), 
00170                                            aka2::fixed<VL>::dispatcher_, 
00171                                            false);
00172         L::value_type_.set_name(aka2::qname("&value"));
00173         default_op *defop = VL::create_default_op();
00174         if (defop != 0)
00175           L::value_type_.set_default_op(defop);
00176         L::value_type_.setup_default_value(fixed);
00177       }
00178     };
00179 
00184     static void set_default(const std::string &defval) {
00185       if (L::value_type_.get_schematype() != simpletype_id)
00186         throw tagged_error("simpleContent", L::get_xmltype(), 
00187                            "default value should be a simpleType.",
00188                            __FILE__, __LINE__);
00189       L::value_type_.set_default(defval);
00190     }
00191   };
00192 
00193 } // namespace aka2
00194 
00195 #endif

Generated on Sun Dec 19 22:58:57 2004 for akaxiso2 by doxygen1.2.18