home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / Lina / source / document.cpp next >
Encoding:
C/C++ Source or Header  |  2009-09-14  |  2.2 KB  |  98 lines

  1. #pragma warning(disable: 4786)
  2. #include <set>
  3. #include "document.h"
  4.  
  5. std::set<std::string>    g_tagSetSupportingCDATA;
  6.  
  7. ///////////////////////////////////////////////////////////////////////////////
  8.  
  9. TreeDocument::TreeDocument()
  10.     : mpRoot(NULL)
  11. {
  12. }
  13.  
  14. TreeNode *TreeDocument::AllocNode() {
  15.     mNodeHeap.push_back(TreeNode());
  16.     TreeNode *t = &mNodeHeap.back();
  17.  
  18.     t->mpDocument = this;
  19.  
  20.     return t;
  21. }
  22.  
  23. ///////////////////////////////////////////////////////////////////////////////
  24.  
  25. TreeNode *TreeNode::ShallowClone() {
  26.     TreeNode *newNode = mpDocument->AllocNode();
  27.  
  28.     newNode->mpLocation        = mpLocation;
  29.     newNode->mLineno        = mLineno;
  30.     newNode->mName            = mName;
  31.     newNode->mAttribs        = mAttribs;
  32.     newNode->mbIsText        = mbIsText;
  33.     newNode->mbIsControl    = mbIsControl;
  34.  
  35.     return newNode;
  36. }
  37.  
  38. const TreeAttribute *TreeNode::Attrib(const std::string& s) const {
  39.     Attributes::const_iterator it(mAttribs.begin()), itEnd(mAttribs.end());
  40.  
  41.     for(; it!=itEnd; ++it) {
  42.         if ((*it).mName == s)
  43.             return &*it;
  44.     }
  45.  
  46.     return NULL;
  47. }
  48.  
  49. const TreeNode *TreeNode::ResolvePath(const std::string& path, std::string& name) const {
  50.     std::string::size_type p = path.find('/');
  51.  
  52.     if (!p) {
  53.         return mpDocument->mpRoot->ResolvePath(path.substr(1), name);
  54.     } else if (p != std::string::npos) {
  55.         const TreeNode *t = Child(path.substr(0, p));
  56.  
  57.         if (!t)
  58.             return NULL;
  59.  
  60.         return t->ResolvePath(path.substr(p+1), name);
  61.     } else {
  62.         name = path;
  63.         return this;
  64.     }
  65. }
  66.  
  67. const TreeNode *TreeNode::Child(const std::string& s) const {
  68.     std::string name;
  69.     const TreeNode *parent = ResolvePath(s, name);
  70.  
  71.     Children::const_iterator it(mChildren.begin()), itEnd(mChildren.end());
  72.  
  73.     for(; it!=itEnd; ++it) {
  74.         TreeNode *child = *it;
  75.         if (!child->mbIsText) {
  76.             if (child->mName == "lina:data") {
  77.                 const TreeNode *t = child->Child(name);
  78.                 if (t)
  79.                     return t;
  80.             }
  81.             if (child->mName == name)
  82.                 return *it;
  83.         }
  84.     }
  85.     return NULL;
  86. }
  87.  
  88. bool TreeNode::SupportsCDATA() const {
  89.     return g_tagSetSupportingCDATA.find(mName) != g_tagSetSupportingCDATA.end();
  90. }
  91.  
  92. void TreeNode::SetSupportsCDATA(const std::string& tagname, bool supports_cdata) {
  93.     if (supports_cdata)
  94.         g_tagSetSupportingCDATA.insert(tagname);
  95.     else
  96.         g_tagSetSupportingCDATA.erase(tagname);
  97. }
  98.