00001
00002 #ifndef AKAXISO2_FRAMEWORK_DOCUMENT_H__
00003 #define AKAXISO2_FRAMEWORK_DOCUMENT_H__
00004
00010 #include <akaxiso2/framework/qname.h>
00011 #include <akaxiso2/framework/element_props.h>
00012 #include <akaxiso2/framework/node_ptr.h>
00013
00014 namespace aka2 {
00015
00024 struct document {
00025 document() : props_(0) {}
00026 document(void* root, const element_props &def)
00027 : root_(node(root, def.op())), props_(&def) {}
00028 ~document();
00029
00030 node get_root() { return root_.get_node(); }
00031 node adopt() { return root_.adopt(); }
00032 const_node get_root() const { return root_.get_node(); }
00033 const qname &get_name() const { return props_->get_name(); }
00034 const element_op& get_op() const { return props_->op(); }
00035 const element_props &get_props() const { return *props_; }
00036 bool empty() const { return root_.get_node().ptr() == 0; }
00037 private:
00038 node_ptr root_;
00039 const element_props *props_;
00040 };
00041
00042
00050 template<class T>
00051 T* root_cast(aka2::document &doc) {
00052 return static_cast<T*>(doc.get_root().ptr());
00053 }
00054
00062 template<class T>
00063 const T* root_cast(const aka2::document &doc) {
00064 return static_cast<const T*>(doc.get_root().ptr());
00065 }
00066
00074 template<class T>
00075 T* adopt_root(aka2::document &doc) {
00076 return static_cast<T*>(doc.adopt().ptr());
00077 }
00078
00085 bool document_of(const aka2::document &doc, const std::string &tagname);
00086
00087 }
00088
00089 bool operator==(const aka2::document &lhs, const aka2::document &rhs);
00090
00091 #endif