0022922: Clean up warnings on uninitialized / unused variables
[occt.git] / src / VrmlData / VrmlData_WorldInfo.cxx
1 // File:      VrmlData_WorldInfo.cxx
2 // Created:   01.08.07 08:21
3 // Author:    Alexander GRIGORIEV
4 // Copyright: Open Cascade 2007
5
6
7 #include <VrmlData_WorldInfo.hxx>
8 #include <VrmlData_Scene.hxx>
9 #include <VrmlData_InBuffer.hxx>
10
11 #ifdef WNT
12 #define _CRT_SECURE_NO_DEPRECATE
13 #pragma warning (disable:4996)
14 #endif
15
16 IMPLEMENT_STANDARD_HANDLE  (VrmlData_WorldInfo, VrmlData_Node)
17 IMPLEMENT_STANDARD_RTTIEXT (VrmlData_WorldInfo, VrmlData_Node)
18
19 //=======================================================================
20 //function : VrmlData_WorldInfo::VrmlData_WorldInfo
21 //purpose  : Constructor
22 //=======================================================================
23
24 VrmlData_WorldInfo::VrmlData_WorldInfo (const VrmlData_Scene&  theScene,
25                                         const char             * theName,
26                                         const char             * theTitle)
27   : VrmlData_Node (theScene, theName),
28     myInfo        (theScene.Allocator())
29 {
30   SetTitle (theTitle);
31 }
32
33 //=======================================================================
34 //function : SetTitle
35 //purpose  : Set or modify the title.
36 //=======================================================================
37
38 void VrmlData_WorldInfo::SetTitle (const char * theString)
39 {
40   if (theString == 0L)
41     myTitle = 0L;
42   else {
43     const size_t len = strlen (theString) + 1;
44     if (len == 1)
45       myTitle = 0L;
46     else {
47       myTitle = static_cast <const char *>(Scene().Allocator()->Allocate(len));
48       memcpy (const_cast<char *> (myTitle), theString, len);
49     }
50   }
51 }
52
53 //=======================================================================
54 //function : AddInfo
55 //purpose  : Add a string to the list of info strings.
56 //=======================================================================
57
58 void VrmlData_WorldInfo::AddInfo (const char * theString)
59 {
60   if (theString != 0L)
61     if (* theString != '\0') {
62       const size_t len = strlen (theString) + 1;
63       char * aStr = static_cast <char *>(Scene().Allocator()->Allocate(len));
64       memcpy (aStr, theString, len);
65       myInfo.Append (aStr);
66     }
67 }
68
69 //=======================================================================
70 //function : Clone
71 //purpose  : Create a copy of this node
72 //=======================================================================
73
74 Handle(VrmlData_Node) VrmlData_WorldInfo::Clone
75                                 (const Handle(VrmlData_Node)& theOther) const
76 {
77   Handle(VrmlData_WorldInfo) aResult =
78     Handle(VrmlData_WorldInfo)::DownCast (VrmlData_Node::Clone(theOther));
79   if (aResult.IsNull())
80     aResult =
81       new VrmlData_WorldInfo (theOther.IsNull() ? Scene() : theOther->Scene(),
82                              Name());
83
84   if (&aResult->Scene() == &Scene()) {
85     aResult->myTitle = myTitle;
86     aResult->myInfo  = myInfo;
87   } else {
88     aResult->SetTitle (myTitle);
89     NCollection_List <const char *>::Iterator anIter (myInfo);
90     for (; anIter.More(); anIter.Next())
91       aResult->AddInfo (anIter.Value());
92   }
93   return aResult;
94 }
95
96 //=======================================================================
97 //function : Read
98 //purpose  : Read the Node from input stream.
99 //=======================================================================
100
101 VrmlData_ErrorStatus VrmlData_WorldInfo::Read (VrmlData_InBuffer& theBuffer)
102 {
103   VrmlData_ErrorStatus aStatus;
104   while (OK(aStatus, VrmlData_Scene::ReadLine(theBuffer))) {
105
106     if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "title")) {
107       TCollection_AsciiString aTitleString;
108       if (OK (aStatus, ReadString (theBuffer, aTitleString)))
109         SetTitle (aTitleString.ToCString());
110
111     } else if (VRMLDATA_LCOMPARE (theBuffer.LinePtr, "info")) {
112       NCollection_List<TCollection_AsciiString> lstInfo;
113       if (OK (aStatus, ReadMultiString (theBuffer, lstInfo))) {
114         NCollection_List<TCollection_AsciiString>::Iterator anIter (lstInfo);
115         for (; anIter.More(); anIter.Next())
116           AddInfo (anIter.Value().ToCString());
117       }
118     } else
119       break;
120   }
121
122   // Read the terminating (closing) brace
123   if (OK(aStatus))
124     aStatus = readBrace (theBuffer);
125   return aStatus;
126 }
127
128 //=======================================================================
129 //function : Write
130 //purpose  : Write the Node to the Scene output.
131 //=======================================================================
132
133 VrmlData_ErrorStatus VrmlData_WorldInfo::Write (const char * thePrefix) const
134 {
135   VrmlData_ErrorStatus aStatus (VrmlData_StatusOK);
136   const VrmlData_Scene& aScene = Scene();
137   static char header[] = "WorldInfo {";
138   if (aScene.IsDummyWrite() == Standard_False &&
139       OK (aStatus, aScene.WriteLine (thePrefix, header, GlobalIndent())))
140   {
141     char buf[4096];
142     if (myTitle) {
143       sprintf (buf, "title \"%s\"", myTitle);
144       aStatus = aScene.WriteLine (buf);
145     }
146
147     if (myInfo.IsEmpty() == Standard_False && OK(aStatus)) {
148       if (OK (aStatus, aScene.WriteLine ("info [", 0L, GlobalIndent()))) {
149         NCollection_List<const char *>::Iterator anIter (myInfo);
150         while (anIter.More()) {
151           sprintf (buf, "\"%s\"", anIter.Value());
152           anIter.Next();
153           if (anIter.More())
154             aStatus = aScene.WriteLine (buf, ",");
155           else
156             aStatus = aScene.WriteLine (buf);
157         }
158       }
159       aStatus = aScene.WriteLine ("]", 0L, -GlobalIndent());
160     }
161
162     aStatus = WriteClosing();
163   }
164   return aStatus;
165 }
166
167 //=======================================================================
168 //function : IsDefault
169 //purpose  : 
170 //=======================================================================
171
172 Standard_Boolean VrmlData_WorldInfo::IsDefault() const
173 {
174   return (myTitle == 0L && myInfo.IsEmpty());
175 }