ServiceLocatedObject.h
Go to the documentation of this file.
00001 /**********************************************************************************************/
00023 #ifndef SERVICELOCATEDOBJECT_H
00024 #define SERVICELOCATEDOBJECT_H
00025 
00026 #include "lo/LocatedObject.h"
00027 
00028 
00029 #include <string>
00030 #include <vector>
00031 #include <map>
00032 
00033 #define LO_TYPE_PHYSICAL 1
00034 
00035 
00036 #define XML_NODE_SaveableLo "SaveableLo"
00037 #define XML_ATTRIBUTE_LOID "loid"
00038 #define XML_ATTRIBUTE_LOIDFATHER "loidfather"
00039 #define XML_NODE_MATPOSE "Pose"
00040 #define XML_NODE_COVARIANCE "Cov"
00041 #ifndef ID_WORLD
00042 #define ID_WORLD 1
00043 #endif
00044 
00045 /************************************************************************
00046                         XMLTag.h - Copyright klank
00047 
00048 
00049 **************************************************************************/
00050 typedef struct _xmlTextWriter xmlTextWriter;
00051 typedef struct _xmlTextReader xmlTextReader;
00052 #define XML_NODE_STD_VECTOR "std_vector"
00053 #define XML_NODE_STD_PAIR "std_pair"
00054 #define XML_NODE_INT "int"
00055 #define XML_NODE_DOUBLE "double"
00056 #define XML_NODE_STRING "std_string"
00057 #define XML_NODE_MATRIX "newmat_Matrix"
00058 #define XML_ATTRIBUTE_ROWS "rows"
00059 #define XML_ATTRIBUTE_COLS "cols"
00060 
00061 /**********************************************************************************************/
00070 namespace jlo
00071 {
00072 class ServiceInterface;
00073 
00074 class XMLTag
00075 {
00076 public:
00077 
00078   // Constructors/Destructors
00079   //
00080 
00081 
00085   XMLTag ( std::string Name);
00086 
00090   virtual ~XMLTag ( );
00094 /****************************************************************************/
00115   void WriteToFile(const std::string& stFile, XMLTag** fileReference = NULL) const;
00116 /****************************************************************************/
00129     char* WriteToString() const;
00130 /****************************************************************************/
00147   static XMLTag* ReadFromFile(const std::string &stFile);
00148 /****************************************************************************/
00158   XMLTag* Clone() const;
00159 
00160 /****************************************************************************/
00175   virtual void Write(xmlTextWriter* pWriter) const;
00176 /****************************************************************************/
00190   static XMLTag* Read(xmlTextReader* pReader);
00191 /****************************************************************************/
00202   template<typename T> static XMLTag* Tag(std::vector<T> vector, std::string name = "")
00203   {
00204     XMLTag* tag = new XMLTag(name.compare("") == 0 ? XML_NODE_STD_VECTOR : name);
00205 #ifdef WIN32
00206     std::vector<T>::const_iterator iter;
00207     for(iter = vector.begin(); iter != vector.end(); iter++)
00208     {
00209       tag->AddChild(XMLTag::Tag((*iter)));
00210     }
00211 #else
00212     for(unsigned int i = 0; i < vector.size(); i++)
00213     {
00214       tag->AddChild(XMLTag::Tag(vector[i]));
00215     }
00216 #endif
00217     return tag;
00218   }
00219   template<typename T1, typename T2> static XMLTag* Tag(std::pair<T1, T2> p, std::string name = "")
00220   {
00221     XMLTag* tag = new XMLTag(name.compare("") == 0 ? XML_NODE_STD_PAIR : name);
00222     tag->AddChild(XMLTag::Tag(p.first));
00223     tag->AddChild(XMLTag::Tag(p.second));
00224     return tag;
00225   }
00226 
00227 
00228   static XMLTag* Tag(int n, std::string name = "");
00229   static XMLTag* Tag(double d, std::string name = "");
00230   static XMLTag* Tag(std::string value, std::string name = "");
00231   static XMLTag* Tag(const Matrix& alg, std::string name = "");
00232 
00233 
00234 /****************************************************************************/
00248   template<typename T>
00249   static T Load(XMLTag* tag, T* t )
00250   {
00251     throw "Load Failed: Expected type has no loading function implemented";
00252   };
00253 
00254   template<typename T>
00255    static std::vector<T> Load(XMLTag* tag, std::vector<T>*  )
00256   {
00257     std::vector<T> vectorTemp;
00258     for(unsigned int i = 0; i < tag->CountChildren(); i++)
00259     {
00260       try
00261       {
00262         vectorTemp.push_back(Load(tag->GetChild(i), (T*)NULL));
00263       }
00264       catch(...)
00265       {
00266         printf("!!!!!!!!! Error reading a vector!!!!!!!!!! \n\n\n");
00267         /* Do nothing, try to get the others*/
00268       }
00269     }
00270     return vectorTemp;
00271   };
00272 
00273   template<typename T1, typename T2>
00274   static std::pair<T1, T2> Load(XMLTag* tag, std::pair<T1, T2>*  )
00275   {
00276     std::pair<T1, T2> p;
00277     int childCount = tag->CountChildren();
00278     if(childCount > 0)
00279       p.first = Load(tag->GetChild(0), (T1*)NULL);
00280     if(childCount > 1)
00281       p.second = Load(tag->GetChild(1), (T2*)NULL);
00282 
00283     return p;
00284   };
00285 
00286   static int Load(XMLTag* tag, int* )
00287   {
00288     if(tag == NULL)
00289       return 0;
00290     return  tag->GetCDataInt();
00291   };
00292 
00293   static double Load(XMLTag* tag,double *)
00294   {
00295     if(tag == NULL)
00296       return 0.0;
00297     return tag->GetCDataDouble();
00298   };
00299 
00300   static std::string Load(XMLTag* tag, std::string *)
00301   {
00302     if(tag == NULL)
00303       return "";
00304     return tag->GetCDataST();
00305   };
00306 
00307   static Matrix Load(XMLTag* tag, Matrix* );
00308 
00309 /****************************************************************************/
00324   void AddProperty(const std::string& name, const std::string& value);
00325   void AddProperty(const std::string &name, const unsigned long &value);
00326   void AddProperty(const std::string& name, const int &value);
00327   void AddProperty(const std::string& name, const double &value);
00328 
00329 /****************************************************************************/
00342   void SetCData(const int &value);
00343   void SetCData(const double &value);
00344   void SetCData(const std::string &value);
00345 
00346 /****************************************************************************/
00360   int                   GetCDataInt() const;
00361   double                GetCDataDouble() const;
00362   std::string GetCDataST() const;
00363 
00364 
00365 /****************************************************************************/
00381   std::string GetProperty(const std::string& name);
00382   double GetPropertyDouble(const std::string& name);
00383   int GetPropertyInt(const std::string& name);
00384 
00385 
00386 /****************************************************************************/
00407   int AddChild(XMLTag* child, int position = -1);
00408   void ReplaceChild(XMLTag* child, int position);
00409 /****************************************************************************/
00423   unsigned int CountChildren() const;
00424 /****************************************************************************/
00442   void RemoveChild(const unsigned int &position);
00443   void RemoveChild(const std::string &name);
00444 
00445 /****************************************************************************/
00460   XMLTag* GetChild(const unsigned int &position);
00461   XMLTag* GetChild(const std::string &name);
00462   XMLTag* GetChild(const std::string& name, int innerindex);
00463 
00464 /****************************************************************************/
00476   std::string& GetName(){return m_name;}
00477 
00478   //static public Methods
00479   static unsigned int OldTag()
00480   {
00481     return 0;
00482   }
00483 
00484   unsigned long date();
00485 
00486 
00487   private:
00491     void Touch();
00492 
00493   // Private attributes
00494   //
00495   unsigned long                                                 m_lastChanged;
00496   std::vector<XMLTag*>                                  m_children;
00497   std::string                                                           m_cData;
00498   std::string                                                           m_name;
00499   std::map<std::string, std::string>            m_properties;
00500 };
00501 
00507 class ServiceLocatedObject :  public LocatedObject
00508 {
00509 public:
00510   //
00511   // Constructors/Destructors
00512   //
00513 
00514 
00515 /********************************************************************/
00522   ServiceLocatedObject ( );
00523 
00524   ServiceLocatedObject(ServiceLocatedObject* locobj, const Matrix &matrix , const Matrix &covariance);
00525 
00526 
00527   ServiceLocatedObject(ServiceLocatedObject* locobj, double x = 0.0, double y = 0.0, double z = 0.0,
00528           double roll = 0.0, double pitch = 0.0, double yaw = 0.0,
00529           double sigmaX = 0.0, double sigmaY = 0.0, double sigmaZ = 0.0,
00530           double sigmaRoll = 0.0, double sigmaPitch = 0.0, double sigmaYaw = 0.0);
00531 
00532 #ifdef _DEBUG
00533   void Print();
00534 #endif
00535 public:
00536   XMLTag* SaveComplete() ;
00537 /*      void TransformPointLocally(const double& x_in, const double& y_in, const double& z_in, double& x_out, double& y_out, double& z_out, const double& scale);*/
00538   XMLTag* Save() ;
00539 
00546   void UpdateParent(ServiceLocatedObject* new_parent);
00558   void Update(Matrix m, Matrix cov,  ServiceLocatedObject*(* copy)(ServiceLocatedObject*, ServiceLocatedObject*), unsigned long(*del)(ServiceLocatedObject*), void (*updated)(unsigned long));
00562   void DecreaseReferenceCounter(){if(referenceCounter>0)referenceCounter--;}
00563   void IncreaseReferenceCounter(){referenceCounter++;}
00564   unsigned long GetReferenceCounter(){return referenceCounter;}
00565   /********************************************************************/
00570   virtual ~ServiceLocatedObject ( );
00571 
00572   /********************************************************************/
00584   ServiceLocatedObject operator- (ServiceLocatedObject &smallObject ) ;
00585 
00586   /********************************************************************/
00595   virtual void AddAttachedObject(ServiceLocatedObject* lo){IncreaseReferenceCounter();}
00596 
00597   /********************************************************************/
00602   virtual void RemoveAttachedObject(ServiceLocatedObject* lo){DecreaseReferenceCounter();}
00603   /********************************************************************/
00612   virtual void PropagateMovement(ServiceLocatedObject*(* copy)(ServiceLocatedObject*, ServiceLocatedObject*),
00613                                 unsigned long (*del)(ServiceLocatedObject*), void (*updated)(unsigned long), ServiceLocatedObject*)
00614   {
00615     updated(m_uniqueID);
00616   }
00617 
00618   virtual bool NeedCopy (){return false;}
00619   virtual void TellParentNeedCopy(){return;}
00620   virtual void TellParentNeedNoCopy(){return;}
00621 
00622   /********************************************************************/
00627   virtual unsigned long GetLOType(){return LO_TYPE_PERCEIVED;}
00628 
00629 
00630   /********************************************************************/
00637   ServiceLocatedObject* m_relation;
00638   /********************************************************************/
00644   static void SetLastID(unsigned long lastID){if(lastID >= s_lastID) s_lastID = lastID + 1;}
00648   std::string m_mapstring;
00649 protected:
00650   unsigned long referenceCounter;
00651   long m_needCopy;
00652 private:
00653   friend class ServiceInterface;
00654   static unsigned long s_lastID;
00655 };
00661   class LocatedObjectLoader : public LazyLocatedObjectLoader
00662   {
00663   public:
00664     LocatedObjectLoader(){}
00665     LocatedObject* GetParent(const LocatedObject& child){return ((ServiceLocatedObject*)&child)->m_relation;}
00666   };
00667 
00668 
00669 }
00670 
00671 #endif /*SERVICELOCATEDOBJECT*/
00672 


lo
Author(s): U. Klank
autogenerated on Mon Oct 6 2014 10:44:15