forked from CleverRaven/Cataclysm-DDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontents_change_handler.h
49 lines (45 loc) · 1.73 KB
/
contents_change_handler.h
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
#pragma once
#ifndef CATA_SRC_CONTENTS_CHANGE_HANDLER_H
#define CATA_SRC_CONTENTS_CHANGE_HANDLER_H
#include <functional>
#include <vector>
#include "item_location.h"
/**
* Records a batch of unsealed containers and handles spilling at once. This
* is preferred over handling containers right after unsealing because the latter
* can cause items to be invalidated when later code still needs to access them.
* See @ref `Character::handle_contents_changed` for more detail.
*/
class contents_change_handler
{
public:
contents_change_handler() = default;
/**
* Add an already unsealed container to the list. This item location
* should remain valid when `handle_by` is called.
*/
void add_unsealed( const item_location &loc );
/**
* Unseal the pocket containing `loc` and add `loc`'s parent to the list.
* Does nothing if `loc` does not have a parent container. The parent of
* `loc` should remain valid when `handle_by` is called, but `loc` only
* needs to be valid here (for example, the item may be consumed afterwards).
*/
void unseal_pocket_containing( const item_location &loc );
/**
* Let the guy handle any container that needs spilling. This may invalidate
* items in and out of the list of containers. The list is cleared after handling.
*/
void handle_by( Character &guy );
/**
* Serialization for activities
*/
void serialize( JsonOut &jsout ) const;
/**
* Deserialization for activities
*/
void deserialize( JsonIn &jsin );
private:
std::vector<item_location> unsealed;
};
#endif // CATA_SRC_CONTENTS_CHANGE_HANDLER_H