root/tools/osm2pgrouting/trunk/src/ConfigurationParserCallback.cpp

Revision 198, 3.2 KB (checked in by anton, 2 years ago)

Road classes support added to osm2pgrouting

Line 
1/***************************************************************************
2 *   Copyright (C) 2008 by Daniel Wendt                                                                    *
3 *   gentoo.murray@gmail.com                                                                                       *
4 *                                                                         *
5 *   This program is free software; you can redistribute it and/or modify  *
6 *   it under the terms of the GNU General Public License as published by  *
7 *   the Free Software Foundation; either version 2 of the License, or     *
8 *   (at your option) any later version.                                   *
9 *                                                                         *
10 *   This program is distributed in the hope that it will be useful,       *
11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13 *   GNU General Public License for more details.                          *
14 *                                                                         *
15 *   You should have received a copy of the GNU General Public License     *
16 *   along with this program; if not, write to the                         *
17 *   Free Software Foundation, Inc.,                                       *
18 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19 ***************************************************************************/
20
21#include "stdafx.h"
22#include "ConfigurationParserCallback.h"
23#include "OSMDocument.h"
24#include "Configuration.h"
25#include "Type.h"
26#include "Class.h"
27
28namespace osm
29{
30       
31       
32/**
33        Parser callback for configuration files
34*/
35void ConfigurationParserCallback::StartElement( const char *name, const char** atts )
36{
37        std::cout << "SE for <" << name << ">" << std::endl;
38        if( strcmp(name,"class") == 0 )
39        {
40                if (atts != NULL)
41                {
42                        long long id=-1;
43                        std::string name;
44                        const char** attribut = (const char**)atts;
45                        while( *attribut != NULL )
46                        {
47                                const char* key = *attribut++;
48                                const char* value = *attribut++;
49                                if( strcmp( key, "id" ) == 0 )
50                                {
51                                        id = atol( value );
52                                        std::cout << "class id = " << id << std::endl;
53
54                                }
55                                else if( strcmp( key, "name" ) == 0 )
56                                {
57                                        name = value;
58                                        std::cout << "class name = " << name << std::endl;
59                                }
60                        }
61                        if( id>0 && !name.empty() )
62                        {
63                                m_pActType->AddClass( new Class( id, name ) );
64                                std::cout << "class id = "<<id<<" name = " << name << " added to type name=" << m_pActType->name << std::endl;
65                        }
66                }
67        }
68        else if( strcmp(name,"type") == 0 )
69        {
70                if (atts != NULL)
71                {
72                        long long id;
73                        std::string name;
74                        const char** attribut = (const char**)atts;
75                        while( *attribut != NULL )
76                        {
77                                const char* key = *attribut++;
78                                const char* value = *attribut++;
79                                if( strcmp( key, "id" ) == 0 )
80                                {
81                                        id = atol( value );
82
83                                }
84                                else if( strcmp( key, "name" ) == 0 )
85                                {
86                                        name = value;
87                                }
88                        }
89                        if( !name.empty() )
90                        {
91                            m_pActType = new Type( id, name );
92                        }
93                }
94        }
95        else if( strcmp(name,"configuration") == 0 )
96        {
97        }
98}
99
100
101void ConfigurationParserCallback::EndElement( const char* name )
102{
103        if( strcmp(name,"type") == 0 )
104        {
105            m_rDocument.AddType( m_pActType );
106            m_pActType = 0;
107        }
108}
109
110}; // end namespace osm
Note: See TracBrowser for help on using the browser.