This file is indexed.

/usr/include/osmium/osm/object.hpp is in libosmium-dev 0.0~20111213-g7f3500a-1build2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
#ifndef OSMIUM_OSM_OBJECT_HPP
#define OSMIUM_OSM_OBJECT_HPP

/*

Copyright 2011 Jochen Topf <jochen@topf.org> and others (see README).

This file is part of Osmium (https://github.com/joto/osmium).

Osmium is free software: you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License or (at your option) the GNU
General Public License as published by the Free Software Foundation, either
version 3 of the Licenses, or (at your option) any later version.

Osmium is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU Lesser General Public License and the GNU
General Public License for more details.

You should have received a copy of the Licenses along with Osmium. If not, see
<http://www.gnu.org/licenses/>.

*/

/** @file
*   @brief Contains the Osmium::OSM::Object class.
*/

#include <cstdlib>
#include <stdexcept>
#include <assert.h>
#include <time.h>
#include <boost/tr1/memory.hpp>
using std::tr1::shared_ptr;

#ifdef OSMIUM_WITH_SHPLIB
# include <shapefil.h>
#endif // OSMIUM_WITH_SHPLIB

#include <osmium/osm/types.hpp>
#include <osmium/osm/tag_list.hpp>
#include <osmium/utils/timestamp.hpp>

namespace Osmium {

    namespace OSM {

        /**
        * Parent class for nodes, ways, and relations.
        */
        class Object {

        public:

            static const int max_characters_username = 255;
            static const int max_utf16_length_username = 2 * (max_characters_username + 1); ///< maximum number of UTF-16 units

            static const int max_length_username = 255 * 4 + 1; ///< maximum length of OSM user name (255 UTF-8 characters + null byte)

            osm_object_id_t id() const {
                return m_id;
            }

            Object& id(osm_object_id_t id) {
                m_id = id;
                return *this;
            }

            Object& id(const char* id) {
                m_id = atol(id);
                return *this;
            }

            osm_version_t version() const {
                return m_version;
            }

            Object& version(osm_version_t version) {
                m_version = version;
                return *this;
            }

            Object& version(const char* version) {
                m_version = atoi(version);
                return *this;
            }

            osm_changeset_id_t changeset() const {
                return m_changeset;
            }

            Object& changeset(osm_changeset_id_t changeset) {
                m_changeset = changeset;
                return *this;
            }

            Object& changeset(const char* changeset) {
                m_changeset = atol(changeset);
                return *this;
            }

            osm_user_id_t uid() const {
                return m_uid;
            }

            Object& uid(osm_user_id_t uid) {
                m_uid = uid;
                return *this;
            }

            Object& uid(const char* uid) {
                m_uid = atol(uid);
                return *this;
            }

            time_t timestamp() const {
                return m_timestamp;
            }

            time_t endtime() const {
                return m_endtime;
            }

            /**
             * Get the timestamp when this object last changed.
             * @return Timestamp as a string in ISO format (yyyy-mm-ddThh:mm:ssZ). Empty string if unset.
             */
            std::string timestamp_as_string() const {
                return Osmium::Utils::Timestamp::to_iso(m_timestamp);
            }

            /**
             * Get the timestamp until which this object is valid.
             * @return Timestamp as a string in ISO format (yyyy-mm-ddThh:mm:ssZ). Empty string if unset.
             */
            std::string endtime_as_string() const {
                return Osmium::Utils::Timestamp::to_iso(m_endtime);
            }

            /**
             * Set the timestamp when this object last changed.
             * @param timestamp Time in seconds since epoch.
             * @return Reference to object to make calls chainable.
             */
            Object& timestamp(time_t timestamp) {
                m_timestamp = timestamp;
                return *this;
            }

            /**
             * Set the endtime after which this object is no longer valid.
             * (This is only used when working with history data.)
             * @param timestamp Time in seconds since epoch.
             * @return Reference to object to make calls chainable.
             */
            Object& endtime(time_t timestamp) {
                m_endtime = timestamp;
                return *this;
            }

            /**
             * Set the timestamp when this object last changed.
             * @param timestamp Timestamp in the format "yyyy-mm-ddThh:mm:ssZ".
             * @return Reference to object to make calls chainable.
             * @exception std::invalid_argument Thrown when the given string
             *   can't be parsed as a timestamp. The object timestamp will remain
             *   unchanged in this case.
             */
            Object& timestamp(const char* timestamp) {
                m_timestamp = Osmium::Utils::Timestamp::parse_iso(timestamp);
                return *this;
            }

            /**
             * Get the name of the user who last changed this object.
             * @return Pointer to internal buffer with user name.
             */
            const char* user() const {
                return m_user;
            }

            /**
             * Set the name of the user who last changed this object.
             * @return Reference to object to make calls chainable.
             * @exception std::length_error Thrown when the username contains more than max_characters_username (255 UTF-8 characters). When the exception is thrown the username is set to "".
             */
            Object& user(const char* user) {
                if (! memccpy(m_user, user, 0, max_length_username)) {
                    m_user[0] = '\0';
                    throw std::length_error("user name too long");
                }
                return *this;
            }

            /**
             * Get the visible flag of this object.
             * (This is only used in OSM files with history.)
             * @return Visible flag.
             */
            bool visible() const {
                return m_visible;
            }

            /**
             * Set the visible flag of this object.
             * (This is only used in OSM files with history.)
             * @return Reference to object to make calls chainable.
             */
            Object& visible(bool visible) {
                m_visible = visible;
                return *this;
            }

            /**
             * Set the visible flag of this object.
             * (This is only used in OSM files with history.)
             * @return Reference to object to make calls chainable.
             */
            Object& visible(const char* visible) {
                if (!strcmp(visible, "false")) {
                    m_visible = false;
                }
                return *this;
            }

            virtual osm_object_type_t get_type() const = 0;

            /**
             * Set named attribute.
             * @param attr Name of the attribute (must be one of "id", "version", "changeset", "timestamp", "uid", "user", "visible")
             * @param value Value of the attribute
             */
            void set_attribute(const char* attr, const char* value) {
                if (!strcmp(attr, "id")) {
                    id(value);
                } else if (!strcmp(attr, "version")) {
                    version(value);
                } else if (!strcmp(attr, "changeset")) {
                    changeset(value);
                } else if (!strcmp(attr, "timestamp")) {
                    timestamp(value);
                } else if (!strcmp(attr, "uid")) {
                    uid(value);
                } else if (!strcmp(attr, "user")) {
                    user(value);
                } else if (!strcmp(attr, "visible")) {
                    visible(value);
                }
            }

            const TagList& tags() const {
                return m_tags;
            }

            TagList& tags() {
                return m_tags;
            }

            void tags(TagList& tags) {
                m_tags = tags;
            }

#ifdef OSMIUM_WITH_JAVASCRIPT
            v8::Persistent<v8::Object> js_object_instance;

            v8::Persistent<v8::Object> get_instance() const {
                return js_object_instance;
            }

            v8::Handle<v8::Value> js_id() const {
                return v8::Number::New(id());
            }

            v8::Handle<v8::Value> js_version() const {
                return v8::Integer::New(version());
            }

            v8::Handle<v8::Value> js_timestamp_as_string() const {
                return v8::String::New(timestamp_as_string().c_str());
            }

            v8::Handle<v8::Value> js_uid() const {
                return v8::Integer::New(uid());
            }

            v8::Handle<v8::Value> js_user() const {
                return Osmium::utf8_to_v8_String<max_utf16_length_username>(user());
            }

            v8::Handle<v8::Value> js_changeset() const {
                return v8::Number::New(changeset());
            }

            v8::Handle<v8::Value> js_visible() const {
                return v8::Boolean::New(visible());
            }

            v8::Handle<v8::Value> js_tags() const {
                return tags().js_instance();
            }

            struct JavascriptTemplate : public Osmium::Javascript::Template {

                JavascriptTemplate() : Osmium::Javascript::Template() {
                    js_template->SetAccessor(v8::String::NewSymbol("id"),        accessor_getter<Object, &Object::js_id>);
                    js_template->SetAccessor(v8::String::NewSymbol("version"),   accessor_getter<Object, &Object::js_version>);
                    js_template->SetAccessor(v8::String::NewSymbol("timestamp"), accessor_getter<Object, &Object::js_timestamp_as_string>);
                    js_template->SetAccessor(v8::String::NewSymbol("uid"),       accessor_getter<Object, &Object::js_uid>);
                    js_template->SetAccessor(v8::String::NewSymbol("user"),      accessor_getter<Object, &Object::js_user>);
                    js_template->SetAccessor(v8::String::NewSymbol("changeset"), accessor_getter<Object, &Object::js_changeset>);
                    js_template->SetAccessor(v8::String::NewSymbol("tags"),      accessor_getter<Object, &Object::js_tags>);
                    js_template->SetAccessor(v8::String::NewSymbol("visible"),   accessor_getter<Object, &Object::js_visible>);
                }

            };
#endif // OSMIUM_WITH_JAVASCRIPT

        protected:

            Object() :
                m_id(0),
                m_version(0),
                m_changeset(0),
                m_timestamp(0),
                m_endtime(0),
                m_uid(-1), // to be compatible with Osmosis we use -1 for unknown user id
                m_visible(true),
                m_tags() {
                m_user[0] = '\0';
            }

            Object(const Object &o) {
                m_id        = o.m_id;
                m_version   = o.m_version;
                m_uid       = o.m_uid;
                m_changeset = o.m_changeset;
                m_timestamp = o.m_timestamp;
                m_endtime   = o.m_endtime;
                m_tags      = o.m_tags;
                m_visible   = o.m_visible;
                strncpy(m_user, o.m_user, max_length_username);
            }

            virtual ~Object() {
#ifdef OSMIUM_WITH_JAVASCRIPT
                js_object_instance.Dispose();
#endif // OSMIUM_WITH_JAVASCRIPT
            }

        private:

            osm_object_id_t    m_id;          ///< object id
            osm_version_t      m_version;     ///< object version
            osm_changeset_id_t m_changeset;   ///< id of last changeset that changed this object
            time_t             m_timestamp;   ///< when this object changed last
            time_t             m_endtime;     ///< when this object version was replaced by a new one
            osm_user_id_t      m_uid;         ///< user id of user who last changed this object
            char m_user[max_length_username]; ///< name of user who last changed this object
            bool               m_visible;     ///< object visible (only when working with history data)

            TagList m_tags;

        }; // class Object

    } // namespace OSM

} // namespace Osmium

#endif // OSMIUM_OSM_OBJECT_HPP