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

# /Users/fpy/titan-1-5-MBARI/Mers/Estimation/Discrete/Io/Xml/Sax/TrajXMLReader.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 <Mers/Utils/Io/Xml/Sax/ContentLauncher.h>
    00013 #include <Mers/Utils/Io/Xml/Sax/CallbackStore.h>
    00014 #include <Mers/Estimation/Discrete/Trajectories.h>
    00015 #include <Mers/Models/Base/Io/Mof/BaseModelReader.h>
    00016 #include <Mers/Utils/Io/Xml/Sax/XMLLoader.h>
    00017
    00019
    00020 using Mers::Estimation::Discrete::Io::Xml::Sax::TrajCH;
    00021 using Mers::Utils::Io::Xml::Sax::CallbackStore;
    00022 using Mers::Utils::Io::Xml::Sax::ContentLauncher;
    00023 using Mers::Estimation::Discrete::Trajectories;
    00024 using Mers::Models::Base::Io::Mof::BaseModelReader;
    00025 using Mers::Models::Base::BaseModel;
    00026 using Mers::Utils::Exceptions::Exception;
    00027 using Mers::Utils::Io::Xml::Sax::XMLLoader;
    00028 using XERCES_CPP_NAMESPACE::XMLException;
    00029 using XERCES_CPP_NAMESPACE::XMLString;
    00030 using std::cout;
    00031 using std::endl;
    00032
    00034
    00035 void printUse( const char * progName )
    00036 {
    00037         cout << "Use: " << progName <<
    00038                 " <BM file> <Trajectory XML file> [<log4cplus file>]" << endl;
    00039 }
    00040
    00042
    00043 int main( int argc, const char * argv[] )
    00044 {
    00045         // We require a BM file (for a model) and an XML file.
    00046         if( argc != 3 && argc != 4 ) {
    00047                 printUse( argv[0] );
    00048                 return 1;
    00049         }
    00050
    00051         if( argc == 4 ) {
    00052                 log4cplus::PropertyConfigurator::doConfigure( argv[ 3 ] );
    00053         } else {
    00054                 log4cplus::BasicConfigurator::doConfigure();
    00055         }
    00056
    00057         BaseModel model( argv[ 1 ] );
    00058         if( FAILED( BaseModelReader::loadBaseModel( argv[ 1 ], model ) ) ) {
    00059                 cout << "Unable to load base model: " << argv[1] << endl;
    00060                 return 1;
    00061         }
    00062
    00063         try {
    00064                 XMLLoader::initialize();
    00065         } catch( const XMLException & toCatch ) {
    00066                 char* message = XMLString::transcode(toCatch.getMessage());
    00067                 cout << "Error during initialization! :\n";
    00068                 cout << "Exception message is: \n"
    00069                                  << message << "\n";
    00070                 XMLString::release(&message);
    00071                 return 1;
    00072         }
    00073
    00074         // Our Variables
    00075         Trajectories * traj = NULL;
    00076         if( FAILED( XMLLoader::load< Trajectories *, const BaseModel *, TrajCH >
    00077                 ( argv[2], traj, &model ) ) ) {
    00078                 cout << "Failed to load " << argv[2] << endl;
    00079                 return 2;
    00080         }
    00081
    00082         if( traj != NULL ) {
    00083                 cout << "Loaded:" << endl << *traj << endl;
    00084                 delete traj;
    00085         } else {
    00086                 cout << "Loaded nothing." << endl;
    00087         }
    00088
    00089         return 0;
    00090 }
    00091
    00093