fixed memory leak
[platform/core/location/maps-plugin-mapzen.git] / src / mapzen / tangram / data / properties.h
1 #pragma once
2
3 #include <string>
4 #include <vector>
5
6 namespace Tangram {
7
8 class Value;
9 struct PropertyItem;
10
11 struct Properties {
12     using Item = PropertyItem;
13
14     Properties();
15     ~Properties();
16
17     Properties(const Properties& _other) = default;
18     Properties(Properties&& _other) = default;
19     Properties(std::vector<Item>&& _items);
20     Properties& operator=(const Properties& _other) = default;
21     Properties& operator=(Properties&& _other);
22
23     const Value& get(const std::string& key) const;
24
25     void sort();
26
27     void clear();
28
29     bool contains(const std::string& key) const;
30
31     bool getNumber(const std::string& key, double& value) const;
32
33     double getNumber(const std::string& key) const;
34
35     bool getString(const std::string& key, std::string& value) const;
36
37     const std::string& getString(const std::string& key) const;
38
39     std::string asString(const Value& value) const;
40
41     std::string getAsString(const std::string& key) const;
42
43     bool getAsString(const std::string& key, std::string& value) const;
44
45     std::string toJson() const;
46
47     void set(std::string key, std::string value);
48     void set(std::string key, double value);
49
50     void setSorted(std::vector<Item>&& _items);
51
52     // template <typename... Args> void set(std::string key, Args&&... args) {
53     //     props.emplace_back(std::move(key), Value{std::forward<Args>(args)...});
54     //     sort();
55     // }
56
57     const std::vector<Item>& items() const { return props; }
58
59     int32_t sourceId;
60
61     static bool keyComparator(const std::string& a, const std::string& b) {
62         if (a.size() == b.size()) {
63             return a < b;
64         } else {
65             return a.size() < b.size();
66         }
67     }
68 private:
69     std::vector<Item> props;
70 };
71
72 }