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

# item.h

Go to the documentation of this file.

    00001 // -*- c++ -*-
    00002 #ifndef AKAXISO2_FRAMEWORK_ITEM_H__
    00003 #define AKAXISO2_FRAMEWORK_ITEM_H__
    00004
    00010 #include <akaxiso2/framework/element_props.h>
    00011 #include <akaxiso2/framework/node_ptr.h>
    00012
    00013 namespace aka2 {
    00014
    00015   struct itemtype : public element_props {
    00016     itemtype() {}
    00017     itemtype(element_op &op, bool emptiable)
    00018       : element_props(op, emptiable){ }
    00019     bool equals(const void *lhs, const void *rhs) const;
    00020     void set_item_to_default(void *e) const;
    00021   };
    00022
    00023
    00032   class item {
    00033   public:
    00034     item() : props_(0) {}
    00035     item(void *e, const element_props &props)
    00036       : nodeptr_(node(e, props.op())), props_(&props) {  }
    00037     item(const item &i)
    00038       : nodeptr_(i.nodeptr_), props_(i.props_) { }
    00039     ~item(){}
    00040
    00041     const item& operator=(const item& rhs);
    00042     const qname &get_name() const { return props_->get_name(); }
    00043     node get_node() { return nodeptr_.get_node(); }
    00044     const_node get_node() const { return nodeptr_.get_node(); }
    00045     bool is_element() const { return props_->get_name().local()[0] != '&'; }
    00046     const element_props &get_props() const { return *props_; }
    00047   protected:
    00048     void assign(const item &rhs);
    00049     node_ptr nodeptr_;
    00050     const element_props *props_;
    00051   };
    00052
    00053
    00060   bool item_of(const aka2::item &i, const std::string &tagname);
    00061
    00067   template<class T>
    00068   T& item_cast(aka2::item &i) {
    00069     node nd = i.get_node();
    00070     return *static_cast<T*>(nd.ptr());
    00071   }
    00072
    00078   template<class T>
    00079   const T& item_cast(const aka2::item &i) {
    00080     const_node cnd = i.get_node();
    00081     return *static_cast<const T*>(cnd.ptr());
    00082   }
    00083
    00084 }
    00085
    00086
    00087 #endif