]> git.lizzy.rs Git - dragonfireclient.git/blob - src/nodemetadata.h
C++11 patchset 2: remove util/cpp11.h and util/cpp11_container.h (#5821)
[dragonfireclient.git] / src / nodemetadata.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef NODEMETADATA_HEADER
21 #define NODEMETADATA_HEADER
22
23 #include <unordered_set>
24 #include "metadata.h"
25
26 /*
27         NodeMetadata stores arbitary amounts of data for special blocks.
28         Used for furnaces, chests and signs.
29
30         There are two interaction methods: inventory menu and text input.
31         Only one can be used for a single metadata, thus only inventory OR
32         text input should exist in a metadata.
33 */
34
35 class Inventory;
36 class IItemDefManager;
37
38 class NodeMetadata : public Metadata
39 {
40 public:
41         NodeMetadata(IItemDefManager *item_def_mgr);
42         ~NodeMetadata();
43
44         void serialize(std::ostream &os, u8 version, bool disk=true) const;
45         void deSerialize(std::istream &is, u8 version);
46
47         void clear();
48         bool empty() const;
49
50         // The inventory
51         Inventory *getInventory()
52         {
53                 return m_inventory;
54         }
55
56         inline bool isPrivate(const std::string &name) const
57         {
58                 return m_privatevars.count(name) != 0;
59         }
60         void markPrivate(const std::string &name, bool set);
61
62 private:
63         int countNonPrivate() const;
64
65         Inventory *m_inventory;
66         std::unordered_set<std::string> m_privatevars;
67 };
68
69
70 /*
71         List of metadata of all the nodes of a block
72 */
73
74 class NodeMetadataList
75 {
76 public:
77         ~NodeMetadataList();
78
79         void serialize(std::ostream &os, u8 blockver, bool disk=true) const;
80         void deSerialize(std::istream &is, IItemDefManager *item_def_mgr);
81
82         // Add all keys in this list to the vector keys
83         std::vector<v3s16> getAllKeys();
84         // Get pointer to data
85         NodeMetadata *get(v3s16 p);
86         // Deletes data
87         void remove(v3s16 p);
88         // Deletes old data and sets a new one
89         void set(v3s16 p, NodeMetadata *d);
90         // Deletes all
91         void clear();
92
93 private:
94         int countNonEmpty() const;
95
96         std::map<v3s16, NodeMetadata *> m_data;
97 };
98
99 #endif