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

# all.h

Go to the documentation of this file.

    00001 /* -*- c++ -*- */
    00002 #ifndef AKAXISO2_FRAMEWORK_ALL_H__
    00003 #define AKAXISO2_FRAMEWORK_ALL_H__
    00004
    00010 #include <akaxiso2/framework/simpletype.h>
    00011 #include <akaxiso2/framework/attribute.h>
    00012 #include <akaxiso2/framework/memberdef.h>
    00013
    00014 namespace aka2 {
    00015
    00016   template<class L>
    00017   class all_op_dispatcher : public all_op {
    00018   public:
    00019     virtual schematype_id get_schematype() const { return all_id; }
    00020     virtual std::string get_typename() const { return L::get_xmltype(); }
    00022     virtual void construct(void *e) const {  L::construct(e); }
    00023     virtual void copy_construct(void *e, const void *src) const { L::copy_construct(e, src); }
    00024     virtual void destruct(void *e) const { L::destruct(e); }
    00025     virtual size_t class_size() const { return L::class_size(); }
    00026     virtual bool equals(const void *lhs, const void *rhs) const {
    00027       return L::equals(lhs, rhs);
    00028     }
    00029
    00031     virtual const attribute_types *get_attribute_types() const {
    00032       return &L::attribute_types_;
    00033     }
    00034     virtual const attribute_type *get_anyattr_type() const { return L::get_anyattr_type(); }
    00036     virtual const member_map &get_member_map() const {
    00037       return L::member_map_;
    00038     }
    00039   };
    00040
    00041
    00042   template<class L>
    00043   struct all_statics {
    00044     static member_map member_map_;
    00045     static all_op_dispatcher<L> dispatcher_;
    00046   };
    00047
    00048   template<class L>
    00049   member_map all_statics<L>::member_map_;
    00050
    00051   template<class L>
    00052   all_op_dispatcher<L> all_statics<L>::dispatcher_;
    00053
    00054
    00064   template<class T, class L=xiso::leaf<T> >
    00065   class all : public all_statics<L>,
    00066               public attributes<L, T>,
    00067               public memberdef<L, T> {
    00068   public:
    00069     typedef T value_type;
    00070
    00071     virtual ~all(){}
    00072
    00073     static member_type* register_membertype(const member_type &mtype) {
    00074       std::pair<member_map::iterator, bool> res =
    00075         L::member_map_.insert(member_map::value_type(mtype.get_name(), mtype));
    00076       if (!res.second)
    00077         throw tagged_error("element", mtype.get_name().qualified(), "declared twice.",
    00078                            __FILE__, __LINE__);
    00079       return &res.first->second;
    00080     }
    00081
    00082     static void initialize() {
    00083       if (!system_type_registry().add(L()))
    00084         return;
    00085       L::member_map_.clear();
    00086       L::attribute_types_.clear();
    00087       L l; l.model(); // VC6 does not accept L().model();
    00088       check_emptiable(L::member_map_);
    00089     }
    00090
    00091     static void uninitialize() {
    00092       L::member_map_.clear();
    00093       L::attribute_types_.clear();
    00094     }
    00095
    00096     static void construct(void *e) {
    00097       new (e) T();
    00098       all_construct(e, L::dispatcher_);
    00099     }
    00100     static void copy_construct(void *e, const void *src) {
    00101       new (e) T(*static_cast<const T*>(src));
    00102     }
    00103     static size_t class_size() { return sizeof(T); }
    00104     static void destruct(void *elm) { static_cast<T*>(elm)->~T(); }
    00105
    00106     static bool equals(const void *lhs, const void *rhs) {
    00107       return all_equals(lhs, rhs, L::dispatcher_);
    00108     }
    00109
    00110     static element_op* get_attribute_dispatcher() { return &L::dispatcher_; }
    00111     static default_op* create_default_op() { return 0; }
    00112   };
    00113
    00114 } // namespace aka2
    00115
    00116 #endif