CoeffFactory.cpp
Go to the documentation of this file.
00001 #include "robot_instance/CoeffFactory.h"
00002 
00003 using namespace std;
00004 using namespace log4cpp;
00005 
00006 /***************************************************************************/
00015 CoeffMap::value_type CoeffFactory::fromXml(const std::string& xml, const std::string& namePrefix)
00016 {
00017     TiXmlDocument file;
00018     file.Parse(xml.c_str());
00019     TiXmlHandle doc(&file);
00020     TiXmlHandle elementHandle(doc.FirstChild("Coeff"));
00021 
00022     if (elementHandle.ToElement())
00023     {
00024         string name = "";
00025 
00026         if (elementHandle.ToElement()->Attribute("id"))
00027         {
00028             if (namePrefix.size() > 0)
00029             {
00030                 name = StringUtilities::makeFullyQualifiedRoboDynElement(namePrefix, elementHandle.ToElement()->Attribute("id"));
00031             }
00032             else
00033             {
00034                 name = elementHandle.ToElement()->Attribute("id");
00035             }
00036         }
00037         else
00038         {
00039             NasaCommonLogging::Logger::getCategory("gov.nasa.robonet.CoeffFactory") << Priority::ERROR << "The attribute [id] was not found for element [" << elementHandle.ToElement()->ValueStr() << "]";
00040             MissingXMLElementException missingXMLElementException;
00041             throw missingXMLElementException;
00042         }
00043 
00044         float  value    = 0;
00045         string valueStr = "";
00046 
00047         if (elementHandle.ToElement()->Attribute("value"))
00048         {
00049             valueStr = elementHandle.ToElement()->Attribute("value");
00050             value = boost::lexical_cast<float>(valueStr);
00051         }
00052         else
00053         {
00054             NasaCommonLogging::Logger::getCategory("gov.nasa.robonet.CoeffFactory") << Priority::ERROR << "The attribute [value] was not found for element [" << elementHandle.ToElement()->ValueStr() << "]";
00055             MissingXMLElementException missingXMLElementException;
00056             throw missingXMLElementException;
00057         }
00058 
00059         //    // Create and return the new token
00060         return CoeffMap::value_type(name, value);
00061     }
00062     else
00063     {
00064         NasaCommonLogging::Logger::getCategory("gov.nasa.robonet.CoeffFactory") << Priority::ERROR << "The element [Coeff] was not found.";
00065         MissingXMLElementException missingXMLElementException;
00066         throw missingXMLElementException;
00067     }
00068 }
00069 
00070 


robot_instance
Author(s):
autogenerated on Sat Jun 8 2019 20:43:12