source: subversion/applications/lib/libosm/Way.cpp @ 34393

Last change on this file since 34393 was 11684, checked in by nienhueser, 11 years ago

Less inline definitions. Start to document things (doxygen style)

File size: 1.9 KB
Line 
1#include "Way.h"
2#include "Components.h"
3#include <cfloat>
4#include <iostream>
5
6/*
7Copyright (C) 2006 Nick Whitelegg, Hogweed Software, nick@hogweed.org
8
9This program is free software; you can redistribute it and/or modify
10it under the terms of the GNU General Public License as published by
11the Free Software Foundation; either version 2 of the License, or
12(at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
22
23 */
24
25using std::endl;
26using std::vector;
27
28namespace OSM
29{
30
31Way::Way(int id ) : Object(id)
32{
33}
34
35void Way::addNode(int n)
36{
37        nodes.push_back(n);
38}
39
40// remove a node - returns its position
41int Way::removeNode(int n)
42{
43        for(vector<int>::iterator i=nodes.begin(); i!=nodes.end(); i++)
44        {
45                if(*i==n)
46                {
47                        int index = i-nodes.begin();
48                        nodes.erase(i);
49                        return index;
50                }
51        }
52        return -1;
53}
54
55// Insert a node at position 'index'
56bool Way::addNodeAt(unsigned int index, int n)
57{
58        vector<int>::iterator i = nodes.begin() + index;
59        if(n>0)
60        {
61                nodes.insert(i,n);
62                return true;
63        }
64        return false;
65}
66
67int Way::getNode(unsigned int i) const
68{
69        return (i>=0 && i<nodes.size()) ?  (nodes[i]) : -1;
70}
71
72void Way::toXML(std::ostream &strm)
73{
74        if (hasTags() || nodes.size()) {
75                strm << "  <way id='" << id() << "'>" << endl;
76                for(unsigned int count=0; count<nodes.size(); count++)
77                        strm  << "    <node id='" << nodes[count] << "'/>" << endl;
78                tagsToXML(strm);
79                strm << "  </way>" << endl;
80        } else {
81                strm << "  <way id='" << id() << "'/>" << endl;
82        }
83}
84
85int Way::nNodes() const
86{
87        return nodes.size();
88}
89
90}
Note: See TracBrowser for help on using the repository browser.