00001 //$Header: /home/ben/Mapper/c++/RCS/MapDataDocument.cpp,v 6.4 2002/07/07 20:00:46 ben Exp $
00002 // Copyright Benedict Adamson 2002.
00003 // This file is part of Mapper.
00004
00005 // Mapper is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 2 of the License, or
00008 // (at your option) any later version.
00009
00010 // Mapper is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013 // GNU General Public License for more details.
00014
00015 // You should have received a copy of the GNU General Public License
00016 // along with Mapper; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00018
00028 #include <parsers/DOMParser.hpp>
00029
00030 #include "DOM_output.h"
00031 #include "MapDataDocument.h"
00032 #include "MapperErrorHandler.h"
00033 #include "constraint.h"
00034 #include "curve.h"
00035
00036
00037
00038 MapDataDocument::MapDataDocument(void)
00039 :
00040 precision( 6 ),
00041 origin_( 0, 0 ),
00042 height_( 0 ),
00043 width_( 0 )
00044 {
00045 {//Create the DOM
00046 //FIXME
00047 };
00048 {//Postconditions:
00049 assert( this->origin() == vector2(0,0) );
00050 assert( this->height() == 0.0 );
00051 assert( this->width() == 0.0 );
00052 assert( this->named_points().empty() );
00053 assert( this->anon_points().empty() );
00054 assert( this->curves().empty() );
00055 assert( this->fixed_points().empty() );
00056 assert( this->constraints().empty() );
00057 assert( this->precision = 6 );
00058 };
00059 }
00060
00061
00062
00063 MapDataDocument::~MapDataDocument(void)
00064 {
00065 for( vector< constraint * >::iterator i = constraints_.begin();
00066 i != constraints_.end();
00067 i++
00068 )
00069 delete (*i);
00070 ;
00071 for( map< string, curve * >::iterator i = curves_.begin();
00072 i != curves_.end();
00073 i++
00074 )
00075 delete (*i).second;
00076 ;
00077 for( map< string, vector2 * >::iterator i = named_points_.begin();
00078 i != named_points_.end();
00079 i++
00080 )
00081 delete (*i).second;
00082 ;
00083 for( vector< vector2 * >::iterator i = anon_points_.begin();
00084 i != anon_points_.end();
00085 i++
00086 )
00087 delete (*i);
00088 ;
00089 }
00090
00091
00092
00093 void MapDataDocument::read(
00094 InputSource &source,
00095 MapperErrorHandler &err_handler
00096 )
00097 {
00098 try{
00099 DOMParser parser;
00100 {//set up the parser
00101 parser.setDoNamespaces( false );
00102 parser.setErrorHandler( &err_handler );
00103 parser.setIncludeIgnorableWhitespace( true );
00104 };
00105 parser.parse( source );
00106 if( !err_handler.errors ){
00107 this->doc = parser.getDocument();
00108 this->convert( err_handler );
00109 };
00110 }catch( const DOM_DOMException &ex ){
00111 err_handler.fatalError( ex );
00112 }catch( const XMLException &ex ){
00113 err_handler.fatalError( ex );
00114 }catch( ... ){
00115 err_handler.unexpectedError();
00116 };
00117 }
00118
00119
00120
00121 void MapDataDocument::write(
00122 ostream &out,
00123 const double tol
00124 )
00125 {
00126 this->update( tol );
00127 DOM_output::write( out, this->doc );
00128 }
00129
00130
00131
00132 set< vector2 * > MapDataDocument::all_points(void) const
00133 {
00134 set< vector2 * > ps; //return value
00135 for( map< string, vector2 * >::const_iterator j =
00136 this->named_points_.begin();
00137 j != this->named_points_.end();
00138 j++ ){
00139 vector2 *p = (*j).second;
00140 assert( p );
00141 ps.insert( p );
00142 };
00143 for( vector< vector2 * >::const_iterator j = this->anon_points_.begin();
00144 j != this->anon_points_.end();
00145 j++ ){
00146 vector2 *p = (*j);
00147 assert( p );
00148 assert( ps.count( p ) == 0 );
00149 ps.insert( p );
00150 };
00151 for( map< string, curve * >::const_iterator j = this->curves_.begin();
00152 j != this->curves_.end();
00153 j++ ){
00154 const curve *c = (*j).second;
00155 assert( c );
00156 const unsigned np = c->param.size();
00157 for( unsigned k = 0; k < np; k++ ){
00158 vector2 *p = c->param[k];
00159 assert( p );
00160 ps.insert( p );
00161 };
00162 };
00163 return ps;
00164 }