Salome HOME
CCAR: remove some memory leaks in SALOMEDS CORBA interface
[modules/kernel.git] / src / DF / DF_Document.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include "DF_definitions.hxx"
23 #include "DF_Document.hxx"
24 #include "DF_Label.hxx"
25 #include "DF_ChildIterator.hxx"
26
27 using namespace std;
28
29 //Class DF_Document is container for user's data stored as a tree of Labels
30 //with assigned Attributes
31
32 DF_Document::DF_Document(const string& theDocumentType)
33 {
34   _id = -1;
35   _type = theDocumentType;
36   _modified = true;
37 }
38
39 DF_Document::~DF_Document()
40 {
41   Clear();
42 }
43
44 DF_Application* DF_Document::GetApplication()
45 {
46    return _appli;
47 }
48
49 //Returns a Label of this Document with entry "0:1"
50 DF_Label DF_Document::Main()
51 {
52   if(!_main.IsNull()) return _main;
53
54   if(_root.IsNull()) {
55     _root = DF_Label(new DF_LabelNode());
56     _root._node->_document = this;
57   }
58
59   _main = _root.FindChild(1, true);
60
61   return _main;
62 }
63
64 //Returns a Label of this Document with entry "0:"
65 DF_Label DF_Document::Root()
66 {
67   if(!_root.IsNull()) return _root;
68   
69   if(_root.IsNull()) {
70     _root = DF_Label(new DF_LabelNode());
71     _root._node->_document = this;
72   }
73
74   return _root;
75 }
76
77
78 //Returns an ID of this 
79 int DF_Document::GetDocumentID() const
80 {
81   return _id;
82 }
83
84 //Returns a type of the Document
85 string DF_Document::GetDocumentType()
86 {
87   return _type;
88 }
89
90 //Clears the content of this Document
91 void DF_Document::Clear()
92 {
93   if(_root.IsNull()) return;
94
95   vector<DF_LabelNode*> vn;
96   DF_ChildIterator CI(_root, true);
97   for(; CI.More(); CI.Next()) {
98     DF_LabelNode* node =  CI.Value()._node; 
99     if(node) vn.push_back(node);
100   }
101
102   for(int i = 0, len = vn.size(); i<len; i++)
103     delete vn[i];
104
105   _root._node->Reset();
106   delete _root._node;
107 }
108
109 //Returns true if this document is empty
110 bool DF_Document::IsEmpty()
111 {
112   if(_root.IsNull()) return true;
113
114   DF_ChildIterator CI(_root, true);
115   for(; CI.More(); CI.Next()) {
116     DF_LabelNode* node =  CI.Value()._node; 
117     if(node->_attributes.size()) return false;
118   }
119
120   return true;
121 }
122
123 //Returns true if this document is modified
124 bool DF_Document::IsModified()
125 {
126   return _modified;
127 }
128
129 //Sets whether a document is modified
130 void DF_Document::SetModified(bool isModified)
131 {
132   _modified = isModified;
133 }
134
135
136 //Restores a content of the Document from the std::string theData
137 void DF_Document::Load(const std::string& theData)
138 {
139    //Not implemented
140 }
141
142 //Converts a content of the Document into the std::string
143 string DF_Document::Save()
144 {
145    //Not implemented
146    return "";
147 }