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

# /Users/fpy/titan-1-5-MBARI/Mers/Estimation/Discrete/Io/Xml/Sax/EstCH.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 "EstCH.h"
    00012 #include <Mers/Models/Base/Io/Xml/Sax/BMAssignmentCH.h>
    00013 #include <Mers/Utils/Io/Xml/Sax/DoubleCH.h>
    00014 #include <Mers/Estimation/Discrete/Estimate.h>
    00015 #include <Mers/Models/Base/BaseModelAssignmentArray.h>
    00016 #include <xercesc/util/XMLString.hpp>
    00017 #include <xercesc/sax2/SAX2XMLReader.hpp>
    00018
    00020
    00021 using namespace Mers::Estimation::Discrete::Io::Xml::Sax;
    00022 using Mers::Utils::Io::Xml::Sax::ContentHandler;
    00023 using Mers::Utils::Io::Xml::Sax::ContentCallback;
    00024 using Mers::Utils::Io::Xml::Sax::CallbackStore;
    00025 using Mers::Utils::Io::Xml::Sax::TypedCH;
    00026 using Mers::Utils::Io::Xml::Sax::DoubleCH;
    00027 using Mers::Models::Base::Io::Xml::Sax::BMAssignmentCH;
    00028 using Mers::Estimation::Discrete::Estimate;
    00029 using Mers::Models::Base::BaseModel;
    00030 using Mers::Models::Base::BaseModelAssignmentArray;
    00031 using Mers::Models::Base::BaseModelAssignment;
    00032 using XERCES_CPP_NAMESPACE::SAX2XMLReader;
    00033 using XERCES_CPP_NAMESPACE::Attributes;
    00034 using XERCES_CPP_NAMESPACE::XMLString;
    00035
    00037
    00038 EstCH::EstCH( SAX2XMLReader * reader, const BaseModel * model,
    00039         ContentHandler * parent, ContentCallback< Estimate * > * callback )
    00040         : TypedCH< const BaseModel * >( reader, model, parent ),
    00041                 CallbackStore<double>(), m_Callback( callback )
    00042 {
    00043         m_Assigns = new BaseModelAssignmentArray( true );
    00044 }
    00045
    00047
    00048 EstCH::~EstCH()
    00049 {
    00050         if( m_Assigns != NULL )
    00051                 delete m_Assigns;
    00052 }
    00053
    00055
    00056 void EstCH::startElement( const XMLCh * const uri,
    00057         const XMLCh * const localname, const XMLCh * const qname,
    00058         const Attributes& attrs)
    00059 {
    00060         // Get the string version of the word we're looking for.
    00061         XMLCh * kProbability = XMLString::transcode( "probability" );
    00062         XMLCh * kAssignment = XMLString::transcode( "assignment" );
    00063
    00064         if( XMLString::equals( localname, kProbability ) ) {
    00065                 DoubleCH * ch = new DoubleCH( m_Reader, this, this );
    00066                 m_Reader->setContentHandler( ch );
    00067         } else if( XMLString::equals( localname, kAssignment ) ) {
    00068                 BMAssignmentCH * ch = new BMAssignmentCH( m_Reader,
    00069                         TypedCH< const BaseModel * >::m_Data, this, this );
    00070                 m_Reader->setContentHandler( ch );
    00071         } else {
    00072                 ContentHandler::startElement( uri, localname, qname, attrs );
    00073         }
    00074
    00075         // Free our strings.
    00076         XMLString::release( &kProbability );
    00077         XMLString::release( &kAssignment );
    00078 }
    00079
    00081
    00082 void EstCH::endElement(const XMLCh * const uri,
    00083         const XMLCh * const localname, const XMLCh * const qname)
    00084 {
    00085         // Get our probability.
    00086         double probability = CallbackStore< double >::m_Data;
    00087
    00088         // Construct our Estimate.
    00089         Estimate * est = new Estimate( m_Assigns, probability );
    00090         m_Assigns = NULL;
    00091
    00092         // Call our callback function.
    00093         m_Callback->handleContent( est, localname );
    00094
    00095         // Do the default stuff.  This may delete us.
    00096         ContentHandler::endElement( uri, localname, qname );
    00097 }
    00098
    00100
    00101 void EstCH::handleContent( BaseModelAssignment * asg, const XMLCh * element )
    00102 {
    00103         if( m_Assigns != NULL )
    00104                 m_Assigns->pushBack( asg );
    00105 }
    00106
    00108