0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / XmlMDataStd / XmlMDataStd_IntegerListDriver.cxx
1 // File:        XmlMDataStd_IntegerListDriver.cxx
2 // Created:     May 29 11:40:00 2007
3 // Author:      Vlad Romashko
4 //              <vladislav.romashko@opencascade.com>
5 // Copyright:   Open CASCADE
6
7 #include <XmlMDataStd_IntegerListDriver.ixx>
8 #include <TDataStd_IntegerList.hxx>
9 #include <TColStd_ListIteratorOfListOfInteger.hxx>
10 #include <XmlObjMgt.hxx>
11
12 IMPLEMENT_DOMSTRING (FirstIndexString, "first")
13 IMPLEMENT_DOMSTRING (LastIndexString,  "last")
14
15 //=======================================================================
16 //function : XmlMDataStd_IntegerListDriver
17 //purpose  : Constructor
18 //=======================================================================
19 XmlMDataStd_IntegerListDriver::XmlMDataStd_IntegerListDriver(const Handle(CDM_MessageDriver)& theMsgDriver)
20      : XmlMDF_ADriver (theMsgDriver, NULL)
21 {
22
23 }
24
25 //=======================================================================
26 //function : NewEmpty
27 //purpose  : 
28 //=======================================================================
29 Handle(TDF_Attribute) XmlMDataStd_IntegerListDriver::NewEmpty() const
30 {
31   return new TDataStd_IntegerList();
32 }
33
34 //=======================================================================
35 //function : Paste
36 //purpose  : persistent -> transient (retrieve)
37 //=======================================================================
38 Standard_Boolean XmlMDataStd_IntegerListDriver::Paste(const XmlObjMgt_Persistent&  theSource,
39                                                       const Handle(TDF_Attribute)& theTarget,
40                                                       XmlObjMgt_RRelocationTable&  ) const
41 {
42   Standard_Integer aFirstInd, aLastInd, aValue, ind;
43   const XmlObjMgt_Element& anElement = theSource;
44
45   // Read the FirstIndex; if the attribute is absent initialize to 1
46   XmlObjMgt_DOMString aFirstIndex= anElement.getAttribute(::FirstIndexString());
47   if (aFirstIndex == NULL)
48     aFirstInd = 1;
49   else if (!aFirstIndex.GetInteger(aFirstInd)) 
50   {
51     TCollection_ExtendedString aMessageString =
52       TCollection_ExtendedString("Cannot retrieve the first index"
53                                  " for IntegerList attribute as \"")
54         + aFirstIndex + "\"";
55     WriteMessage (aMessageString);
56     return Standard_False;
57   }
58
59   // Read the LastIndex; the attribute should be present
60   if (!anElement.getAttribute(::LastIndexString()).GetInteger(aLastInd)) 
61   {
62     TCollection_ExtendedString aMessageString =
63       TCollection_ExtendedString("Cannot retrieve the last index"
64                                  " for IntegerList attribute as \"")
65         + aFirstIndex + "\"";
66     WriteMessage (aMessageString);
67     return Standard_False;
68   }
69
70   Handle(TDataStd_IntegerList) anIntList = Handle(TDataStd_IntegerList)::DownCast(theTarget);
71   if (aFirstInd == aLastInd) 
72   {
73     Standard_Integer anInteger;
74     if (!XmlObjMgt::GetStringValue(anElement).GetInteger(anInteger)) 
75     {
76       TCollection_ExtendedString aMessageString =
77         TCollection_ExtendedString("Cannot retrieve integer member"
78                                    " for IntegerList attribute as \"");
79       WriteMessage (aMessageString);
80       return Standard_False;
81     }
82     anIntList->Append(anInteger);
83   }
84   else 
85   {
86     Standard_CString aValueStr = Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString());
87     for (ind = aFirstInd; ind <= aLastInd; ind++)
88     {
89       if (!XmlObjMgt::GetInteger(aValueStr, aValue)) 
90       {
91         TCollection_ExtendedString aMessageString =
92           TCollection_ExtendedString("Cannot retrieve integer member"
93                                      " for IntegerList attribute as \"")
94             + aValueStr + "\"";
95         WriteMessage (aMessageString);
96         return Standard_False;
97       }
98       anIntList->Append(aValue);
99     }
100   }
101   
102   return Standard_True;
103 }
104
105 //=======================================================================
106 //function : Paste
107 //purpose  : transient -> persistent (store)
108 //=======================================================================
109 void XmlMDataStd_IntegerListDriver::Paste(const Handle(TDF_Attribute)& theSource,
110                                           XmlObjMgt_Persistent&        theTarget,
111                                           XmlObjMgt_SRelocationTable&  ) const
112 {
113   Handle(TDataStd_IntegerList) anIntList = Handle(TDataStd_IntegerList)::DownCast(theSource);
114
115   Standard_Integer anU = anIntList->Extent();
116   TCollection_AsciiString aValueStr;
117
118   theTarget.Element().setAttribute(::LastIndexString(), anU);
119   if (anU >= 1)
120   {
121     TColStd_ListIteratorOfListOfInteger itr(anIntList->List());
122     for (; itr.More(); itr.Next())
123     {
124       aValueStr += TCollection_AsciiString(itr.Value());
125       aValueStr += ' ';
126     }
127   }
128   // No occurrence of '&', '<' and other irregular XML characters
129   XmlObjMgt::SetStringValue (theTarget, aValueStr.ToCString(), Standard_True);
130 }