Main Page   Namespace List   Class Hierarchy   Compound List   File List   Header Files   Sources   Namespace Members   Compound Members   File Members  

MapDataDocument_convert_attributes.cpp

00001 //$Header: /home/ben/Mapper/c++/RCS/MapDataDocument_convert_attributes.cpp,v 6.3 2002/07/09 22:50:52 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 
00030 #include <climits>
00031 #include <cstdio>
00032 #include <cstdlib>
00033 #include <cstring>
00034 #include <memory>
00035 
00036 #include <dom/DOM_Attr.hpp>
00037 #include <dom/DOM_Element.hpp>
00038 #include <dom/DOM_Node.hpp>
00039 
00040 #include <string>
00041 
00042 #include "MapDataDocument.h"
00043 
00044 
00045 
00046 void MapDataDocument::get_attribute(
00047    string &x, //output
00048    const DOM_Element &elem,
00049    const char *attr
00050    )
00051    throw(
00052       error::attribute_error
00053       )
00054 {
00055    {//preconditions:
00056       assert( attr );
00057    };
00058    const DOMString a( attr );
00059    if( elem.getAttributeNode( a ).isNull() )
00060       throw error::attribute_error( elem, "absent", attr );
00061    ;
00062    const DOMString s( elem.getAttribute( a ) );
00063    auto_ptr< char > trans( s.transcode() );
00064    assert( trans.get() );
00065    x = trans.get();
00066    //implicit delete trans
00067 }
00068       
00069 
00070       
00071 void MapDataDocument::get_attribute(
00072    double &x, //output
00073    const DOM_Element &elem,
00074    const char *attr
00075    )
00076    throw(
00077       error::attribute_error
00078       )
00079 {
00080    {//preconditions:
00081       assert( attr );
00082    };
00083    const DOMString a( attr );
00084    if( elem.getAttributeNode( a ).isNull() )
00085       throw error::attribute_error( elem, "absent", attr );
00086    ;
00087    const DOMString s( elem.getAttribute( a ) );
00088    if( 0 == s.length() )
00089       throw error::attribute_error( elem, "empty", attr );
00090    ;
00091    auto_ptr< char > trans( s.transcode() );
00092    assert( trans.get() );
00093    char *endptr;
00094    x = strtod( trans.get(), &endptr );
00095    while( *endptr && isspace( *endptr ) ) endptr++; //skip whitespace
00096    if( *endptr )
00097       throw error::attribute_error( elem, "unexpected characters", attr );
00098    ;
00099    //implicit delete trans
00100 }
00101       
00102 
00103 
00104 void MapDataDocument::get_attribute(
00105    unsigned &x, //output
00106    const DOM_Element &elem,
00107    const char *attr
00108    )
00109    throw(
00110       error::attribute_error
00111       )
00112 {
00113    {//preconditions:
00114       assert( attr );
00115    };
00116    const DOMString a( attr );
00117    if( elem.getAttributeNode( a ).isNull() )
00118       throw error::attribute_error( elem, "absent", attr );
00119    ;
00120    const DOMString s( elem.getAttribute( a ) );
00121    if( 0 == s.length() )
00122       throw error::attribute_error( elem, "empty", attr );
00123    ;
00124    auto_ptr< char > trans( s.transcode() );
00125    assert( trans.get() );
00126    char *endptr;
00127    unsigned long xl = strtoul( trans.get(), &endptr, 10 );
00128    while( *endptr && isspace( *endptr ) ) endptr++; //skip whitespace
00129    if( *endptr )  //found non whitespace
00130       throw error::attribute_error( elem, "unexpected characters", attr );
00131    ;
00132    if( UINT_MAX < xl )
00133       throw error::attribute_error( elem, "out of range", attr );
00134    ;
00135    x = (unsigned)xl;
00136    //implicit delete trans
00137 }
00138       
00139 
00140 
00141 void MapDataDocument::get_attribute(
00142    vector2 *&p, //output
00143    const DOM_Element &elem,
00144    const char *attr
00145    ) const
00146    throw(
00147       error::attribute_error
00148       )
00149 {
00150    {//preconditions:
00151       assert( attr );
00152    };
00153    string name;
00154    get_attribute( name, elem, attr );
00155    map< string, vector2 * >::const_iterator i =
00156       this->named_points_.find( name );
00157    if( i == this->named_points_.end() )
00158       throw error::attribute_error( elem, "point not found", attr );
00159    ;
00160    p = (*i).second;
00161 }
00162       
00163       
00164 
00165 void MapDataDocument::get_attribute(
00166    curve *&c, //output
00167    const DOM_Element &elem,
00168    const char *attr
00169    ) const
00170    throw(
00171       error::attribute_error
00172       )
00173 {
00174    {//preconditions:
00175       assert( attr );
00176    };
00177    string name;
00178    get_attribute( name, elem, attr );
00179    map< string, curve * >::const_iterator i = this->curves_.find( name );
00180    if( i == this->curves_.end() )
00181       throw error::attribute_error( elem, "curve not found", attr );
00182    ;
00183    c = (*i).second;
00184 }
00185 
00186 
00187 
00188 bool MapDataDocument::has_attribute(
00189    const DOM_Element &node,
00190    const char *attr
00191    )
00192 {
00193    return !node.getAttributeNode( DOMString(attr) ).isNull();
00194 }

Generated at Sun Jul 14 20:38:09 2002 for Mapper by doxygen 1.0.0 written by Dimitri van Heesch, © 1997-1999