File: property.hpp

package info (click to toggle)
tilemaker 3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 78,284 kB
  • sloc: cpp: 28,715; ansic: 4,052; makefile: 180; ruby: 77; sh: 6
file content (89 lines) | stat: -rw-r--r-- 2,441 bytes parent folder | download
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
#ifndef VTZERO_PROPERTY_HPP
#define VTZERO_PROPERTY_HPP

/*****************************************************************************

vtzero - Tiny and fast vector tile decoder and encoder in C++.

This file is from https://github.com/mapbox/vtzero where you can find more
documentation.

*****************************************************************************/

/**
 * @file property.hpp
 *
 * @brief Contains the property class.
 */

#include "property_value.hpp"
#include "types.hpp"

namespace vtzero {

    /**
     * A view of a vector tile property (key and value).
     *
     * Doesn't hold any data itself, just views of the key and value.
     */
    class property {

        data_view m_key{};
        property_value m_value{};

    public:

        /**
         * The default constructor creates an invalid (empty) property.
         */
        constexpr property() noexcept = default;

        /**
         * Create a (valid) property from a key and value.
         */
        constexpr property(const data_view key, const property_value value) noexcept :
            m_key(key),
            m_value(value) {
        }

        /**
         * Is this a valid property? Properties are valid if they were
         * constructed using the non-default constructor.
         */
        constexpr bool valid() const noexcept {
            return m_key.data() != nullptr;
        }

        /**
         * Is this a valid property? Properties are valid if they were
         * constructed using the non-default constructor.
         */
        explicit constexpr operator bool() const noexcept {
            return valid();
        }

        /// Return the property key.
        constexpr data_view key() const noexcept {
            return m_key;
        }

        /// Return the property value.
        constexpr property_value value() const noexcept {
            return m_value;
        }

    }; // class property

    /// properties are equal if they contain the same key & value data.
    inline constexpr bool operator==(const property& lhs, const property& rhs) noexcept {
        return lhs.key() == rhs.key() && lhs.value() == rhs.value();
    }

    /// properties are unequal if they do not contain them same key and value data.
    inline constexpr bool operator!=(const property& lhs, const property& rhs) noexcept {
        return !(lhs == rhs);
    }

} // namespace vtzero

#endif // VTZERO_PROPERTY_HPP