AnimatLab  2
Test
StdSerialize.cpp
Go to the documentation of this file.
1 
7 #include "StdAfx.h"
8 
9 #ifdef _DEBUG
10 #undef THIS_FILE
11 static char THIS_FILE[]=__FILE__;
12 #define new DEBUG_NEW
13 #endif
14 
15 namespace StdUtils
16 {
24 {
25 
26 }
27 
35 {
36 
37 }
38 
48 {}
49 
59 {return NULL;}
60 
69 void CStdSerialize::Trace(std::ostream &oOs)
70 {}
71 
81 {}
82 
92 {}
93 
99 std::ostream STD_UTILS_PORT &operator<<(std::ostream& oOs, CStdSerialize *lpObj)
100 {
101  lpObj->Trace(oOs);
102  return oOs;
103 }
104 
110 std::ostream STD_UTILS_PORT &operator<<(std::ostream& oOs, CStdIPoint oPoint)
111 {
112  oOs << "(" << oPoint.x << ", " << oPoint.y << ", " << oPoint.z << ")";
113  return oOs;
114 }
115 
121 std::ostream STD_UTILS_PORT &operator<<(std::ostream& oOs, CStdLPoint oPoint)
122 {
123  oOs << "(" << oPoint.x << ", " << oPoint.y << ", " << oPoint.z << ")";
124  return oOs;
125 }
126 
132 std::ostream STD_UTILS_PORT &operator<<(std::ostream& oOs, CStdFPoint oPoint)
133 {
134  oOs << "(" << oPoint.x << ", " << oPoint.y << ", " << oPoint.z << ")";
135  return oOs;
136 }
137 
143 std::ostream STD_UTILS_PORT &operator<<(std::ostream& oOs, CStdDPoint oPoint)
144 {
145  oOs << "(" << oPoint.x << ", " << oPoint.y << ", " << oPoint.z << ")";
146  return oOs;
147 }
148 
149 
150 //Save To Xml
151 
164 void STD_UTILS_PORT Std_SavePoint(CStdXml &oXml, std::string strName, CStdIPoint &oPoint)
165 {
166  oXml.AddChildElement(strName);
167  oXml.IntoChildElement(strName);
168  oXml.SetAttrib("x", oPoint.x);
169  oXml.SetAttrib("y", oPoint.y);
170  oXml.SetAttrib("z", oPoint.z);
171  oXml.OutOfElem();
172 }
173 
186 void STD_UTILS_PORT Std_SavePoint(CStdXml &oXml, std::string strName, CStdLPoint &oPoint)
187 {
188  oXml.AddChildElement(strName);
189  oXml.IntoChildElement(strName);
190  oXml.SetAttrib("x", oPoint.x);
191  oXml.SetAttrib("y", oPoint.y);
192  oXml.SetAttrib("z", oPoint.z);
193  oXml.OutOfElem();
194 }
195 
208 void STD_UTILS_PORT Std_SavePoint(CStdXml &oXml, std::string strName, CStdFPoint &oPoint)
209 {
210  oXml.AddChildElement(strName);
211  oXml.IntoChildElement(strName);
212  oXml.SetAttrib("x", oPoint.x);
213  oXml.SetAttrib("y", oPoint.y);
214  oXml.SetAttrib("z", oPoint.z);
215  oXml.OutOfElem();
216 }
217 
230 void STD_UTILS_PORT Std_SavePoint(CStdXml &oXml, std::string strName, CStdDPoint &oPoint)
231 {
232  oXml.AddChildElement(strName);
233  oXml.IntoChildElement(strName);
234  oXml.SetAttrib("x", oPoint.x);
235  oXml.SetAttrib("y", oPoint.y);
236  oXml.SetAttrib("z", oPoint.z);
237  oXml.OutOfElem();
238 }
239 
240 
241 //Load From Xml
242 
256 bool STD_UTILS_PORT Std_LoadPoint(CStdXml &oXml, std::string strName, CStdIPoint &oPoint, bool bThrowError)
257 {
258  if(oXml.FindChildElement(strName, bThrowError))
259  {
260  oXml.IntoElem();
261  oPoint.x = oXml.GetAttribInt("x");
262  oPoint.y = oXml.GetAttribInt("y");
263  oPoint.z = oXml.GetAttribInt("z", 0);
264  oXml.OutOfElem();
265  return true;
266  }
267 
268  return false;
269 }
270 
271 //Load From Xml
272 
286 bool STD_UTILS_PORT Std_LoadPoint(CStdXml &oXml, std::string strName, CStdLPoint &oPoint, bool bThrowError)
287 {
288  if(oXml.FindChildElement(strName, bThrowError))
289  {
290  oXml.IntoElem();
291  oPoint.x = oXml.GetAttribLong("x");
292  oPoint.y = oXml.GetAttribLong("y");
293  oPoint.z = oXml.GetAttribLong("z", 0);
294  oXml.OutOfElem();
295  return true;
296  }
297 
298  return false;
299 }
300 
301 //Load From Xml
302 
316 bool STD_UTILS_PORT Std_LoadPoint(CStdXml &oXml, std::string strName, CStdFPoint &oPoint, bool bThrowError)
317 {
318  if(oXml.FindChildElement(strName, bThrowError))
319  {
320  oXml.IntoElem();
321  oPoint.x = oXml.GetAttribFloat("x");
322  oPoint.y = oXml.GetAttribFloat("y");
323  oPoint.z = oXml.GetAttribFloat("z", 0);
324  oXml.OutOfElem();
325  return true;
326  }
327 
328  return false;
329 }
330 
331 //Load From Xml
332 
346 bool STD_UTILS_PORT Std_LoadPoint(CStdXml &oXml, std::string strName, CStdDPoint &oPoint, bool bThrowError)
347 {
348  if(oXml.FindChildElement(strName, bThrowError))
349  {
350  oXml.IntoElem();
351  oPoint.x = oXml.GetAttribDouble("x");
352  oPoint.y = oXml.GetAttribDouble("y");
353  oPoint.z = oXml.GetAttribDouble("z", 0);
354  oXml.OutOfElem();
355  return true;
356  }
357 
358  return false;
359 }
360 
372 void STD_UTILS_PORT Std_LoadPoint(CStdXml &oXml, int iIndex, CStdIPoint &oPoint)
373 {
374  oXml.FindChildByIndex(iIndex);
375  oXml.IntoElem();
376  oPoint.x = oXml.GetAttribInt("x");
377  oPoint.y = oXml.GetAttribInt("y");
378  oPoint.z = oXml.GetAttribInt("z", 0);
379  oXml.OutOfElem();
380 }
381 
393 void STD_UTILS_PORT Std_LoadPoint(CStdXml &oXml, int iIndex, CStdLPoint &oPoint)
394 {
395  oXml.FindChildByIndex(iIndex);
396  oXml.IntoElem();
397  oPoint.x = oXml.GetAttribLong("x");
398  oPoint.y = oXml.GetAttribLong("y");
399  oPoint.z = oXml.GetAttribLong("z", 0);
400  oXml.OutOfElem();
401 }
402 
414 void STD_UTILS_PORT Std_LoadPoint(CStdXml &oXml, int iIndex, CStdFPoint &oPoint)
415 {
416  oXml.FindChildByIndex(iIndex);
417  oXml.IntoElem();
418  oPoint.x = oXml.GetAttribFloat("x");
419  oPoint.y = oXml.GetAttribFloat("y");
420  oPoint.z = oXml.GetAttribFloat("z", 0);
421  oXml.OutOfElem();
422 }
423 
434 void STD_UTILS_PORT Std_LoadPoint(CStdXml &oXml, int iIndex, CStdDPoint &oPoint)
435 {
436  oXml.FindChildByIndex(iIndex);
437  oXml.IntoElem();
438  oPoint.x = oXml.GetAttribDouble("x");
439  oPoint.y = oXml.GetAttribDouble("y");
440  oPoint.z = oXml.GetAttribDouble("z", 0);
441  oXml.OutOfElem();
442 }
443 
455 double STD_UTILS_PORT Std_CalculateDistance(CStdIPoint &ptA, CStdIPoint &ptB)
456 {
457  return (double) sqrt( (double) (pow((double)(ptA.x-ptB.x), 2) + pow((double)(ptA.y-ptB.y), 2) + pow((double)(ptA.z-ptB.z), 2)) );
458 }
459 
471 double STD_UTILS_PORT Std_CalculateDistance(CStdLPoint &ptA, CStdLPoint &ptB)
472 {
473  return (double) sqrt( (double) (pow((double)(ptA.x-ptB.x), 2) + pow((double)(ptA.y-ptB.y), 2) + pow((double)(ptA.z-ptB.z), 2)) );
474 }
475 
487 double STD_UTILS_PORT Std_CalculateDistance(CStdFPoint &ptA, CStdFPoint &ptB)
488 {
489  return sqrt( pow((ptA.x-ptB.x), 2) + pow((ptA.y-ptB.y), 2) + pow((ptA.z-ptB.z), 2) );
490 }
491 
503 double STD_UTILS_PORT Std_CalculateDistance(CStdDPoint &ptA, CStdDPoint &ptB)
504 {
505  return sqrt( pow((ptA.x-ptB.x), 2) + pow((ptA.y-ptB.y), 2) + pow((ptA.z-ptB.z), 2) );
506 }
507 
508 
509 double STD_UTILS_PORT Std_CalculateDistance(float fltX1, float fltY1, float fltZ1, float fltX2, float fltY2, float fltZ2)
510 {
511  return (double) sqrt( (double) (pow((double)(fltX1-fltX2), 2) + pow((double)(fltY1-fltY2), 2) + pow((double)(fltZ1-fltZ2), 2)) );
512 }
513 
514 } //StdUtils
virtual int GetAttribInt(std::string strAttribName, bool bThrowError=true, int iDefault=0)
Gets an attribute int.
Definition: StdXml.cpp:1024
virtual ~CStdSerialize()
Destructor.
virtual bool FindChildElement(std::string strElementName, bool fThrowError=true)
Finds a child element by name.
Definition: StdXml.cpp:256
virtual void AddChildElement(std::string strElementName)
Adds a child element to current element.
Definition: StdXml.cpp:799
virtual bool IntoElem()
Goes into the next element where the cursor is located.
Definition: StdXml.cpp:42
virtual void Load(CStdXml &oXml)
Loads this object from an xml packet.
std::ostream & operator<<(std::ostream &oOs, CStdSerialize *lpObj)
writes to an output stream
A standard xml manipulation class.
Definition: StdXml.h:19
virtual CStdSerialize * Clone()
Makes a deep copy of this object.
virtual float GetAttribFloat(std::string strAttribName, bool bThrowError=true, float fltDefault=0)
Gets an attribute float.
Definition: StdXml.cpp:1095
virtual double GetAttribDouble(std::string strAttribName, bool bThrowError=true, double dblDefault=0)
Gets an attribute double.
Definition: StdXml.cpp:1061
Namespace for the standard utility objects.
Definition: MarkupSTL.cpp:19
virtual void Save(CStdXml &oXml)
Saves this object to an xml packet..
virtual void Trace(std::ostream &oOs)
Traces this object to an output stream.
virtual bool OutOfElem()
Goes out of the element where the cursor is located.
Definition: StdXml.cpp:56
virtual void Copy(CStdSerialize *lpSource)
Makes a deep copy of this object.
virtual long GetAttribLong(std::string strAttribName, bool bThrowError=true, long lDefault=0)
Gets an attribute long.
Definition: StdXml.cpp:987
virtual bool IntoChildElement(std::string strElementName, bool bThrowError=true)
Goes into the child element with the specified name.
Definition: StdXml.cpp:278
bool Std_LoadPoint(CStdXml &oXml, std::string strName, CStdIPoint &oPoint, bool bThrowError)
Standard load point.
void Std_SavePoint(CStdXml &oXml, std::string strName, CStdIPoint &oPoint)
Standard save point.
Standard serialize class.
Definition: StdSerialize.h:20
virtual void SetAttrib(std::string strAttribName, std::string strVal)
Sets an attribute.
Definition: StdXml.cpp:1163
CStdSerialize()
Default constructor.
virtual bool FindChildByIndex(int iIndex, bool bThrowError=true)
Finds a child element by index.
Definition: StdXml.cpp:225
double Std_CalculateDistance(CStdIPoint &ptA, CStdIPoint &ptB)
Calculates the distance between two points.