- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Estimation/Discrete/Io/Xml/Sax/TrajCH.cpp

    00001
    00002 //
    00003 // Copyright (c) 2005           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00010
    00011 #include "TrajCH.h"
    00012 #include "EstCH.h"
    00013 #include <Mers/Estimation/Discrete/Trajectories.h>
    00014 #include <Mers/Estimation/Discrete/Estimate.h>
    00015 #include <Mers/Utils/Lang/String.h>
    00016 #include <Mers/Utils/Exceptions/RuntimeException.h>
    00017 #include <xercesc/util/XMLString.hpp>
    00018 #include <xercesc/sax2/SAX2XMLReader.hpp>
    00019
    00021
    00022 using namespace Mers::Estimation::Discrete::Io::Xml::Sax;
    00023 using Mers::Utils::Io::Xml::Sax::TypedCH;
    00024 using Mers::Utils::Io::Xml::Sax::ContentHandler;
    00025 using Mers::Utils::Io::Xml::Sax::ContentCallback;
    00026 using Mers::Estimation::Discrete::Estimate;
    00027 using Mers::Estimation::Discrete::Trajectories;
    00028 using Mers::Models::Base::BaseModel;
    00029 using Mers::Utils::Lang::String;
    00030 using Mers::Utils::Exceptions::RuntimeException;
    00031 using XERCES_CPP_NAMESPACE::SAX2XMLReader;
    00032 using XERCES_CPP_NAMESPACE::Attributes;
    00033 using XERCES_CPP_NAMESPACE::XMLString;
    00034
    00036
    00037 TrajCH::TrajCH( SAX2XMLReader * reader, const BaseModel * model,
    00038         ContentHandler * parent, ContentCallback< Trajectories * > * callback )
    00039         : TypedCH< const BaseModel * >( reader, model, parent ),
    00040                 m_Trajectories( NULL ), m_Callback( callback )
    00041 {
    00042         m_Trajectories = new Trajectories( 0.0 );
    00043 }
    00044
    00046
    00047 void TrajCH::startElement( const XMLCh * const uri,
    00048         const XMLCh * const localname, const XMLCh * const qname,
    00049         const Attributes& attrs)
    00050 {
    00051         // Get the string version of the word we're looking for.
    00052         XMLCh * kEstimate = XMLString::transcode( "estimate" );
    00053
    00054         if( XMLString::equals( localname, kEstimate ) ) {
    00055                 // Setup a new estimate object.
    00056                 EstCH * ch = new EstCH( m_Reader, m_Data, this, this );
    00057                 m_Reader->setContentHandler( ch );
    00058         } else {
    00059                 ContentHandler::startElement( uri, localname, qname, attrs );
    00060         }
    00061
    00062         // Free our string.
    00063         XMLString::release( &kEstimate );
    00064 }
    00065
    00067
    00068 void TrajCH::endElement(const XMLCh * const uri,
    00069         const XMLCh * const localname, const XMLCh * const qname)
    00070 {
    00071         // Call our callback function.
    00072         m_Callback->handleContent( m_Trajectories, localname );
    00073
    00074         // Clean up the memory pointer we just handed off.
    00075         m_Trajectories = NULL;
    00076
    00077         // Do the default stuff.  This may delete us.
    00078         ContentHandler::endElement( uri, localname, qname );
    00079 }
    00080
    00082
    00083 void TrajCH::handleContent( Estimate * est, const XMLCh * element )
    00084 {
    00085         if( !m_Trajectories->addEstimate(est) ) {
    00086                 String str( "Estimate could not be added to the trajectories: " );
    00087                 throw RuntimeException( str.c_str(), __FILE__, __LINE__);
    00088         }
    00089 }
    00090
    00092