1 #include "DF_definitions.hxx"
2 #include "DF_Document.hxx"
3 #include "DF_Label.hxx"
4 #include "DF_ChildIterator.hxx"
8 //Class DF_Document is container for user's data stored as a tree of Labels
9 //with assigned Attributes
11 DF_Document::DF_Document(const string& theDocumentType)
14 _type = theDocumentType;
18 DF_Document::~DF_Document()
23 DF_Application* DF_Document::GetApplication()
28 //Returns a Label of this Document with entry "0:1"
29 DF_Label DF_Document::Main()
31 if(!_main.IsNull()) return _main;
34 _root = DF_Label(new DF_LabelNode());
35 _root._node->_document = this;
38 _main = _root.FindChild(1, true);
43 //Returns a Label of this Document with entry "0:"
44 DF_Label DF_Document::Root()
46 if(!_root.IsNull()) return _root;
49 _root = DF_Label(new DF_LabelNode());
50 _root._node->_document = this;
57 //Returns an ID of this
58 int DF_Document::GetDocumentID() const
63 //Returns a type of the Document
64 string DF_Document::GetDocumentType()
69 //Clears the content of this Document
70 void DF_Document::Clear()
72 if(_root.IsNull()) return;
74 vector<DF_LabelNode*> vn;
75 DF_ChildIterator CI(_root, true);
76 for(; CI.More(); CI.Next()) {
77 DF_LabelNode* node = CI.Value()._node;
78 if(node) vn.push_back(node);
81 for(int i = 0, len = vn.size(); i<len; i++)
87 //Returns true if this document is empty
88 bool DF_Document::IsEmpty()
90 if(_root.IsNull()) return true;
92 DF_ChildIterator CI(_root, true);
93 for(; CI.More(); CI.Next()) {
94 DF_LabelNode* node = CI.Value()._node;
95 if(node->_attributes.size()) return false;
101 //Returns true if this document is modified
102 bool DF_Document::IsModified()
107 //Sets whether a document is modified
108 void DF_Document::SetModified(bool isModified)
110 _modified = isModified;
114 //Restores a content of the Document from the std::string theData
115 void DF_Document::Load(const std::string& theData)
120 //Converts a content of the Document into the std::string
121 string DF_Document::Save()