-// File: XmlMDataStd_TreeNodeDriver.cxx
-// Created: Fri Aug 24 20:46:58 2001
-// Author: Alexnder GRIGORIEV
-// Copyright: Open Cascade 2001
-// History:
-
-#include <XmlMDataStd_TreeNodeDriver.ixx>
+// Created on: 2001-08-24
+// Created by: Alexnder GRIGORIEV
+// Copyright (c) 2001-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+
+#include <CDM_MessageDriver.hxx>
+#include <NCollection_LocalArray.hxx>
+#include <Standard_Type.hxx>
#include <TDataStd_TreeNode.hxx>
+#include <TDF_Attribute.hxx>
+#include <XmlMDataStd_TreeNodeDriver.hxx>
#include <XmlObjMgt.hxx>
+#include <XmlObjMgt_Persistent.hxx>
+#include <XmlLDrivers.hxx>
+IMPLEMENT_STANDARD_RTTIEXT(XmlMDataStd_TreeNodeDriver,XmlMDF_ADriver)
IMPLEMENT_DOMSTRING (TreeIdString, "treeid")
IMPLEMENT_DOMSTRING (ChildrenString, "children")
const XmlObjMgt_Element& anElement = theSource;
// tree id
+ Standard_GUID aGUID;
XmlObjMgt_DOMString aGUIDStr = anElement.getAttribute(::TreeIdString());
- Standard_GUID aGUID (Standard_CString(aGUIDStr.GetString()));
+ if (aGUIDStr.Type() == XmlObjMgt_DOMString::LDOM_NULL)
+ aGUID = TDataStd_TreeNode::GetDefaultTreeID();
+ else
+ aGUID = Standard_GUID(Standard_CString(aGUIDStr.GetString()));
aT->SetTreeID(aGUID);
// children
{
Handle(TDataStd_TreeNode) aS = Handle(TDataStd_TreeNode)::DownCast(theSource);
- Standard_Integer aNb;
-
- TCollection_AsciiString aChildrenStr;
-
// tree id
- Standard_Character aGuidStr [40];
- Standard_PCharacter pGuidStr=aGuidStr;
- aS->ID().ToCString (pGuidStr);
- theTarget.Element().setAttribute(::TreeIdString(), aGuidStr);
+ // A not default ID is skipped for storage version 8 and newer.
+ if (aS->ID() != TDataStd_TreeNode::GetDefaultTreeID() ||
+ XmlLDrivers::StorageVersion() < 8)
+ {
+ Standard_Character aGuidStr [40];
+ Standard_PCharacter pGuidStr=aGuidStr;
+ aS->ID().ToCString (pGuidStr);
+ theTarget.Element().setAttribute(::TreeIdString(), aGuidStr);
+ }
- // first child
- Handle(TDataStd_TreeNode) aF = aS->First();
+ // Find number of children.
+ int nbChildren = aS->NbChildren();
+
+ // Allocate 11 digits for each ID (an integer) of the child + a space.
+ Standard_Integer iChar = 0;
+ NCollection_LocalArray<Standard_Character> str;
+ if (nbChildren)
+ str.Allocate(11 * nbChildren + 1);
// form the string of numbers for the list of children
+ Handle(TDataStd_TreeNode) aF = aS->First();
while (!aF.IsNull())
{
- aNb = theRelocTable.FindIndex(aF);
+ Standard_Integer aNb = theRelocTable.FindIndex(aF);
if (aNb == 0)
{
aNb = theRelocTable.Add(aF);
}
- TCollection_AsciiString aNbStr (aNb);
- aChildrenStr += aNbStr + " ";
+
+ // Add number to the long string.
+ iChar += Sprintf(&(str[iChar]), "%d ", aNb);
// next child
aF = aF->Next();
}
- if (aChildrenStr.Length() > 0)
- theTarget.Element().setAttribute(::ChildrenString(),
- aChildrenStr.ToCString());
+ if (nbChildren)
+ {
+ theTarget.Element().setAttribute(::ChildrenString(), (Standard_Character*)str);
+ }
}